·

SMSsing Around

Curious experiments about sending uncommon types of SMS.
Raffy Efrényi

Raffy Efrényi

@Raffy27

Read in Hungarian

I remember when smartphones first started showing up around me. By elementary school, almost everyone used an Android phone, they were the most common around here. Admittedly, the ecosystem was pretty primitive back then; you could do pretty much anything on those phones. In-app purchases often weren't properly verified, so you could even cheat in online games with apps like Freedom or the infamous LuckyPatcher. Better yet, rooting was easy, and we definitely took advantage of it.

Some were reluctant to switch to smartphones and decided to stick with older variants, such as Nokias with keypads and their classic games (Snake Xenzia anyone?). That was some charming tech in its own right. One day during recess, the following conversation took place between one of my retro friends and me:

  • And then you can access all the files with it.
  • ...Mhm, that's pretty cool. But can your phone do this?

They fiddled around a bit with their phone, and sure enough, after a while, a message popped up on my phone automatically, taking over the whole screen. Needless to say, that was awesome. A self-opening SMS message? To answer their original question, no, my phone couldn't do that. Yet.

When I got home, I looked up what Flash SMSs were and how they worked. Turns out SMS actually comes in a bunch of different flavors, and you can spice up plain messages with all sorts of features. This, among other things, is what made it possible to send bitmaps and ringtones on old phones. A Flash SMS, also known as Class 0, is supposed to open immediately on top of everything else according to the spec, and it leaves it up to the user whether to save it or not.

A Haunted App

While digging around, I stumbled upon an app called HushSMS, which let rooted Android phones send these kinds of special SMS messages. Since I had a rooted Samsung Galaxy S4 at the time, I got my hands on an APK to try it out. Fun fact, this was officially distributed by a German company called Silent Services UG (the original site has been down for a while), and they tried to license it with varying degrees of success.

Crooked Games

There it was, Class 0. And now I could send them too! But I was curious to see what else the app had to offer.

  1. PING - invisible messages that the device accepts without showing anything to the user. If accepted, the network sends back a delivery report (letting you know, for instance, whether the recipient's phone is turned on). Variations of this are used by law enforcement during investigations, except they also have access to cell tower data, so they can actually pinpoint the phone's location.
  2. WAP Push SL (Service Load) - tries to convince the device on behalf of the carrier to download and run something from a link, sometimes invisibly. This was used to push configurations, though it's obviously super dangerous.
  3. WAP Push SI (Service Indication) - a message sent on behalf of the carrier containing a link, which usually asks the user if they want to open it.
  4. MMS Notification - displays a fake multimedia message notification that the user can't properly download. The interesting part is that the "sender" field can be spoofed, and on some devices, the message merges into an existing conversation if you send it under the name of a saved contact.
  5. Replace Message - tags the message with a specific type. If you later send another message of the same type, it overwrites the previous one on the recipient's device.
  6. MWI Message - now this... This is psychological warfare. It convinces the recipient's device that they have a new voicemail in their inbox. On many devices, this shows up as a permanent notification (meaning it cannot be dismissed), which gets really annoying, really fast. Rebooting, killing the telephony process - not even clearing app data helps. The notification just keeps coming back. Calling voicemail (which nowadays often isn't even set up) doesn't clear it either. The only way out is either a deactivation message (which can also be sent from this app) or removing the SIM card.

Personal note on that last one: that voicemail trick has the power to turn friends into legitimate enemies, so go easy on it. :'D

Curiously, even though the app hasn't been maintained for years, people still find a use for it today. Namely, it's used for FRP bypasses, because it can send self-opening messages with links that pop up during the OOBE setup wizard.

So why does this need root?

All this does is send some tricky SMS messages. If the phone is physically capable of doing this out of the box, why is the functionality locked behind root?

The answer is that back in the day, the Telephony service could assemble the PDU (a binary format containing the SMS along with different types of headers and flags) manually and hand it off to the SIM for transmission. Later on, however, someone decided such incomprehensible power didn't belong in the hands of mere mortals, so they made the method private in the new API:

/**
- Send a raw SMS PDU.
- A PDU is a protocol data unit. It contains the message and the
- associated meta information.
 */
private void sendRawPdu(byte[] smsc, byte[] pdu, PendingIntent sentIntent, PendingIntent deliveryIntent) {
    try {
        ISms iccISms = ISms.Stub.asInterface(ServiceManager.getService("isms"));
        if (iccISms != null) {
            iccISms.sendRawPdu(smsc, pdu, sentIntent, deliveryIntent);
        }
    } catch (RemoteException ex) {
        // ignore it
    }
}

Java is notoriously malleable, and as such, it lets us excavate the method and force-invoke it anyway. And for a while, that's exactly what developers did:

import android.telephony.SmsManager;
import android.app.PendingIntent;
import java.lang.reflect.Method;

public static void sendRawPdu(byte[] smsc, byte[] pdu) throws Exception {
    SmsManager sm = SmsManager.getDefault();
    Method sendRawPdu = SmsManager.class.getDeclaredMethod(
		"sendRawPdu",
		byte[].class, byte[].class,
		PendingIntent.class, PendingIntent.class
    );
    
    // Well, no, but actually yes!
    sendRawPdu.setAccessible(true);
    sendRawPdu.invoke(sm, smsc, pdu, null, null);
}

So they just removed the method from the visible API surface completely. Hence why you now need an Xposed module (which requires root) to hook into SMS sending so that apps like HushSMS can regain access to this functionality and tamper with the bytes of the PDU directly.

Back to the Present

Can we still send these kinds of messages today? I tested a couple of them on my old rooted phone. The app still ran on it (kind of? the OS is pretty unstable to begin with), so I sent messages from a second SIM.

I got a varied assortment of results. The docs for HushSMS already mentioned that these messages behave differently depending on the receiving device and network (for instance, it was already known that Deutsche Telekom blocks Replace messages). I couldn't send Flash messages, WAP Pushes, or MMS notifications, but the rest worked. Was the carrier blocking them, or was the receiving phone refusing to interpret them?

After swapping SIMs, I managed to send a Flash SMS, so that part was definitely on the carrier. Interestingly though, depending on the phone, it sometimes still showed up as a regular text. Come on, is there no specification they're supposed to follow...? Well, there is. Quite a few, actually:

  • 3GPP TS 23.040 – SMS PDU structure, special types (Type 0, Replace), UDH, and EMS
  • 3GPP TS 23.038 – character encodings (GSM 7-bit, UCS-2) and DCS field quirks (Class 0/Flash, MWI)
  • WAP-259 – transmitting port-addressed binary data packets (WAP Push, MMS notifications)
  • WAP-167 – WAP Push notifications with links and short text

It took me a while to read through all of those. At this point, it still wasn't clear where the process was breaking (on the sending side, at the carrier, on the receiving end...?), but at least I came away with a few good ideas.

Almost Building a Primitive

As I was reading the specs, I noticed the WVG (Wireless Vector Graphics) format, which could be sent inside EMS (Enhanced Messaging Service) messages. It's basically an efficiently encoded SVG, and it sat right there in the official spec, so theoretically you could craft one and devices should be able to render it.

Just like the defs/use combo in SVG, there's a kind of Reuse element here too (it lets you reference other elements as well as itself). So my first thought was a Billion Laughs attack, where elements contain each other exponentially, which forces the parser to run out of memory. The trick here would have been that this is theoretically parsed at a low level by a system process, meaning you could very likely crash the whole system with it.

I even tracked down the format specification, only to find out it's not supported anywhere anymore. It was just a weird transitional step between SMS and MMS, and modern OSes (Android, iOS) never bothered writing a parser for it. Gotta love how everyone just picks and chooses the parts of the spec they want to implement...

I Want One Too!

Regardless of this minor setback, I really liked this tech, so I wanted to build a system that lets me send tricky SMS messages from my own code. That way, if I think of an attack later, I'll have a solid foundation to build on.

How exactly does HushSMS work? With a bit of reverse engineering, I recovered most of the source code from the APK using jadx, then unleashed an agent running Opus 5.5 on it to inspect, understand, and answer my questions.

As it turns out, the app piggybacks on standard SMS sending by wrapping its payload inside a regular message, which gets prefixed with allyourmessagesarebelongtous. The Xposed module then intercepts this, tampers with the resulting PDU (this is where the message becomes "special"), and finally sends it.

To send SMS messages myself, I needed a modem. I ordered a SIM800L module, which was supposed to do the trick. Since the module can only connect to 2G networks (which most carriers are trying to phase out), I checked beforehand whether my carrier still had 2G coverage in the area. Their website had a nice, colorful map that told me that this was entirely possible.

I tried communicating with the modem over serial using an Arduino, and that sort of worked, except the module kept dying during network registration. Through some particularly annoying hardware debugging, I found out that one of the stock capacitors wasn't large enough, because during registration the device needed a bigger burst of current than its own board could supply. Luckily, a friend from abroad had the patience to teach me how to solder, so with a new capacitor we eventually got it working. In the meantime, I also picked up a spare module, and this one worked fine right out of the box.

Going Off-Grid

The SIM I had been experimenting with (along with my phone number and various network identifiers) was tied to my subscription and, thus, my identity. If I were to construct this messaging system as a service, I wouldn't exactly want to use that. Luckily, there's a simple solution: prepaid SIM cards.

You can pick up these bad boys at any surveillance-free corner store. Even though the law technically requires identification (you have to enter a name, email address, and such in their companion app), in practice these are either barely verified or not checked at all. Wonderful. You don't even need a bank card to top them up, since you can pay with vouchers or gift codes, which you can buy with cash.

Even better, the basic plan usually costs next to nothing and includes unlimited on-network SMS. So if you really wanted to, you could easily build your own commercial, nefarious messaging service on top of something like this.

Void API

Next up was the proof of concept. I wanted to build a web API platform capable of talking to the modem and sending magic SMS messages with the right parameters. For seven days and seven nights, agents burned the midnight oil, tearing through the workload.

Since similar projects already existed, a round of research came first. Through some AI wrangling, I documented how HushSMS works, then summarized all the relevant data from the specs. Finally, I looked into existing Go modules (SMS parsing, modem interfacing), such as warthog618/sms and xlab/at. Here, I was more interested in their architecture than the raw code.

For testing, I used the following setup: the modem was connected to my laptop over USB. I also had a rooted phone hooked up so the agent could inspect it over ADB, which allowed it to test every minute detail automatically on a real system. It deduced a format, assembled a PDU, handed it to the modem, sent it out over the network to the target device, and monitored the generated logs and system app activity. It kept tweaking things whenever something refused to work.

This led to a pretty cool late-night research session. After about 15–20 SMS messages, it figured out how everything worked and what each message triggered on the target system. Later, I tested it across multiple devices. Sometimes it couldn't find a relevant log (it was using logcat). The solution it came up with was to pull the messaging app's APK, decompile it with jadx, and locate the relevant code path to verify what had happened.

I Dislike Carriers

Now that I was in control of the lower-level details, it became clear where those few message types had failed earlier. I tested SIM cards from three local carriers. Not all of them allowed sending Class 0 messages. In some cases, the network simply didn't reply and never delivered the message.

The other issue was WAP Push. In theory, this works by sending datagrams to user-defined ports, with the special port being 2948. I could send messages to any other port, but every single carrier filtered this one. I remember this working back in the day, so I suspect this security measure was introduced relatively recently, probably because of the SMS of Death exploit. There is an alternative (port 2949, the encrypted version of the same service), but I couldn't tamper with that one, because without the carrier's signature the device simply drops the message. Since MMS Notification relies on this too, that one was a bust as well.

I managed to test the remaining message types, and they worked. The takeaway is that carriers and phone OSes interpret these specs however they please: sometimes they decide to go against them, and other times they surprisingly implement them to the letter. The result is that it's impossible to know what works where and when unless you actually try it.

Reimplemented SMSs

Alongside regular texts, I managed to implement the tricky ones too. Whichever ones I could, I tested across multiple systems. There were a few that I couldn't test directly, so I can only show those as artistic renditions (beware!). Messages are sent through the web API mentioned above, and a request looks like this:

POST /v1/sms/messages/flash HTTP/1.1
Host: void-api:8080
Authorization: Bearer void_sk_HA9M5lMkV7SMYRyBLBo2UdoyO9COvtDw3BpfBzODSrW
Content-Type: application/json
Idempotency-Key: flash-demo-001

{"to":"+40712345678","text":"Bats are awesome!"}

After a bit of unpacking and parsing, this sends the following commands to the modem:

; Setup
AT+CPIN?                  ; Is the SIM unlocked?
AT+CPIN="7019"            ; Here's a PIN code
AT+CREG?                  ; Registered on the network?
AT+CSQ                    ; Signal strength
AT+CMGF=0                 ; PDU mode instead of text mode
AT+CNMI=2,1,0,1,0         ; Request all delivery reports

; Sending the message
AT+CMGS=28                ; Incoming 28-octet TPDU
0021000B910417325476F800F011C2307D0E0ACBCBA0F0BD3C7FB7CB21

Why all these commands have such esoteric names is beyond me. Nevertheless, the modem doesn't seem to mind, because it usually returns a delivery report a few seconds later, letting us know everything went smoothly.

Long messages (which have to be split into multiple parts) can also be sent, along with messages containing all kinds of Unicode characters. Here are a few screenshots of what these look like in practice on the receiving device.

Plausible Deniability

I discovered a combination that HushSMS didn't support. According to the specification:

When a mobile terminated message is class 0 and the MS has the capability of displaying short messages, the MS shall display the message immediately. ... The message shall not be automatically stored in the (U)SIM or ME.

So Flash messages aren't supposed to be stored automatically, but as we saw, a few devices store them anyway. I was curious whether there was a way to stop the recipient from saving such messages, or to delete them somehow.

The "class" information lives in the TP-DCS (TP-Data-Coding-Scheme) part of the PDU, while the replace flag is in TP-PID (TP-Protocol-Identifier), so in theory they're compatible. What if we send a Flash + Replace message, and later send an empty Replace? Will it overwrite the delivered content?

Flash-Replace overwriting the saved message

Apparently yes! With this kind of burner SMS, you can wipe the message's contents from the target device even if the user intentionally saves it. I checked, and it literally overwrites the row in the local message database, so the original simply vanishes from the device.

Another interesting quirk: an empty overwritten message triggers this error in Google Messages. If you want to avoid that, you can just send an invisible character instead.

What's Next?

I was planning to set up an experiment in the Lab (once it's ready) that people can use for free to test these types of messages. It would require an API key of course, so I don't go bankrupt. Though I might just write an open-source CLI for everyone to mess around with.

This turned out to be a pretty comprehensive project. I learned a lot about telephony primitives, as well as talking to modems. I did some soldering along the way, reverse-engineered Android apps, worked with Xposed modules, built a working messaging platform in Go, and reminisced about an old schoolyard discovery.

Leave a comment

Comments

No comments yet. Be the first one?