DEFCON 21 Bogdan Alecu Attacking SIM Toolkit With SMS WP
DEFCON 21 Bogdan Alecu Attacking SIM Toolkit With SMS WP
DEFCON 21 Bogdan Alecu Attacking SIM Toolkit With SMS WP
Bogdan Alecu
[email protected]
www.m-sec.net
Abstract
In this paper I will show how to make a phone send an SMS message
without the users consent and how to make the phone not to
receive any message. The method used works on any phone, no
matter if its a smartphone or not and also on any GSM/UMTS
network. I will present how you can take advantage of sending a
special crafted SIM Toolkit command message in order to achieve all
that. Finally, I will present the results and their impact on the user
and mobile networks security.
1 Introduction
SMS stands for Short Message Service and represents a way of communication via text
between mobile phones and/or fixed lines, using a standardized protocol. It is an effective
way of communication as the user just writes some text and its almost instantly delivered to
the destination.
SMS as used on modern handsets was originated from radio telegraphy in radio memo
pagers using standardized phone protocols and later defined as part of the Global System for
Mobile Communications (GSM) series of standards in 1985 as a means of sending messages
of up to 160 characters, to and from GSM mobile handsets.1 Since then a lot of things have
changed regarding this service and now it can be used for multiple purposes: MMS
Multimedia Messaging Service, OTA Over The Air phone configuration, notification for
1
http://en.wikipedia.org/wiki/SMS
voice mail, email, fax, micropayments paying a very small sum of money for different
services.
All these ways of using SMS can lead to security issues as their implementation isnt
fully tested and more important because SMS is like an opened firewall: every phone has it
implemented and the phone always receives the message. There have been discovered
different errors, security issues related to the SMS: remote DoS for Nokia S60 phones2,
phone crashing, rebooting, remote executing EXE files, hijacking mobile data connections3,
etc.
Until now most of the SMS related security issues have been found by accident. This is
also the case for the current security issue presented in the paper. I was experimenting with
the binary message sending multipart messages: sending the second part but the message
had only one part, sending the 10000s part message, etc. and trying to configure the SMSC
number stored by sending SIM Application Toolkit messages when suddenly Ive noticed
that my phone started to send a message by itself. Later on, after playing more with the
message that caused this behavior, my phone was not receiving any other messages. I tried
putting the SIM on another phone, resetting the SMSC number but nothing helped.
In this paper I will show how you can achieve the above behavior, why it happens, what
are the security implications and how you can protect.
But first, a little bit of theory
2 SMS
The Point-to-Point Short Message Service (SMS) provides a means of sending messages
of limited size to and from GSM mobiles. The provision of SMS makes use of a Service
Centre, which acts as a store and forward centre for short messages.
Two different point-to-point services have been defined: mobile originated and mobile
terminated. Mobile originated messages will be transported from an MS to a Service Centre
(SC). These may be destined for other mobile users, or for subscribers on a fixed network.
Mobile terminated messages will be transported from a Service Centre to an MS. These may
be input to the Service Centre by other mobile users (via a mobile originated short message)
or by a variety of other sources, e.g. speech, telex, or facsimile. The text messages to be
transferred contain up to 140 octets.
An active MS shall be able to receive a short message TPDU - Transfer protocol data
unit - (SMS-DELIVER) at any time, independently of whether or not there is a speech or data
call in progress. A report will always be returned to the SC; either confirming that the MS has
http://berlin.ccc.de/~tobias/cos/s60-curse-of-silence-advisory.txt
http://www.mseclab.com
received the short message, or informing the SC that it was impossible to deliver the short
message TPDU to the MS, including the reason why.4
An active MS shall be able to submit a short message TPDU (SMS-SUBMIT) at any
time, independently of whether or not there is a speech or data call in progress. A report will
always be returned to the MS; either confirming that the SC has received the short message
TPDU, or informing the MS that it was impossible to deliver the short message TPDU to the
SC, including the reason why.5
2.1.1
Example of SMS-SUBMIT
Octet(s)
00
Description
Info about SMSC here the length is 0, which means that the
SMSC stored in the phone should be used.
01
00
0B
91
4421436587F9
00
00
0B
E8329BFD06DDDF723619
In order to send this message trough AT commands via a GSM modem, the following
steps should be performed:
a) Set the modem in PDU mode: AT+CMGF=0
b) Check if modem is able to process SMS: AT+CSMS=0
c) Send the message: AT+CMGS=23 > 0001000B914421436587F900000B
E8329BFD06DDDF723619
In order to better understand, see below some screenshots from WireShark used for
capturing the debug mode of a Nokia 3310.
Figure 2 Capture from Wireshark compiled with GSMTAP showing an outgoing SMS
http://bb.osmocom.org/trac/wiki/dct3-gsmtap
Figure 3 Capture from Wireshark compiled with GSMTAP showing the SMS-SUBMIT packet
Figure 5 Capture Wireshark compiled with GSMTAP showing details of SMS-DELIVER packet
Length
1 octet
1 octet
1 octet
Ringtone
WAP Push
Operator logo
VCARD
Concatenation of messages
2.3.1
Command Packet Length (CPL) - shall indicate the number of octets from and
including the Command Header Identifier to the end of the Secured Data, including any
padding octets required for ciphering.
Command Header Length (CHL) - the number of octets from and including the SPI to
the end of the RC/CC/DS
9
http://adywicaksono.wordpress.com/2008/05/21/
10
Security Parameter Indicator (SPI) - defines the security level applied to the input and
output message
Ciphering Key Identifier (KIc) - Key and algorithm Identifier for ciphering
Key Identifier (KID) - Key and algorithm Identifier for Redundancy Check (RC) /
Cryptographic Checksum (CC) / Digital Signature (DS)
Toolkit Application Reference (TAR) - is part of the 23.048 header that identifies and
triggers the Over The Air (OTA) feature, which is an application on the SIM
Counter (CNTR) - Replay detection and Sequence Integrity counter
Padding counter (PCNTR) - indicates the number of padding octets used for ciphering
at the end of the secured data
4 Test case
Like I specified before, this security issue has been discovered by a mistake, when
playing with different binary messages. In order to make it easy for me to compose these
binary messages, a few tools have been used. Also since I didnt have any hardware available
for using the OpenBSC or OpenBTS, I just used the live networks. Since I wanted to keep the
spending to minimum, I just chose a pay as you go plan for 5 EUR which has unlimited
texting in the same network.
PDUspy for better understating the incoming message and building my own crafted
message (available at http://www.nobbi.com/pduspy.html)
11
Nokia 3310 with F-BUS USB cable I bought the cable on E-Bay
dct3tap command line utility (Linux) to capture the GSM Um and SIM-ME interfaces
from a Nokia DCT3 phone (eg. 3310) and forward via GSMTAP to the Wireshark
protocol analyzer. This tool has been created by Duncan Salerno and is available on
http://bb.osmocom.org/trac/wiki/dct3-gsmtap
12
Wireshark development release 1.6.0.rc2 compiled and patched with GSMTAP and
SIMCARD in order to decode GSM traffic and SIM access. Instructions on how to
patch it can be found at http://bb.osmocom.org/trac/wiki/dct3-gsmtap
NowSMS Gateway for an easy way of sending messages and connection to an SMS
provider by SMPP - http://www.nowsms.com/download-free-trial
13
in order to work. Below you will find a table with the results from reading the SIM files with
SIMinfo script.
File readed
result
card reader
89490240001381900000
3 tries left (10 to unblock)
3 tries left (10 to unblock)
4
card ATR
ICCID
CVH1
CVH2
number of CHV/UNBLOCK CHV/ADM
CHV1/PIN is disabled
IMSI
Kc [seq.]
PLMN selector (user priority)
- 222 03
- 222 06
- 222 10
- 211 30
forbidden PLMN
- 266 02
- 222 01
- 266 07
- 266 03
user controlled PLMN
operator controlled PLMN
- 222 03
- 000 22
phase
SIM service table
- 1 CHV1 disable function
- 2 Abbreviated Dialling Numbers (ADN)
- 3 Fixed Dialling Numbers (FDN)
- 4 Short Message Storage (SMS)
- 5 Advice of Charge (AoC)
- 6 Capability Configuration Parameters (CCP)
- 7 PLMN selector
- 8 RFU
- 9 MSISDN
- 10 Extension1
- 11 Extension2
- 12 SMS Parameters
- 13 Last Number Dialled (LND)
- 14 Cell Broadcast Message Identifier
262011910185216
3E104356638C70D0 [2]
allocated, activated
allocated, activated
allocated, activated
not allocated, not activated
not allocated, not activated
not allocated, not activated
Table 4 Result of file reading on SIM where Data download via SMS-PP is present
The type of message sent is addressed directly to the SIM, by setting the PID to 0x7F,
corresponding to USIM Data Download, as you will see below. Also the DCS has to be a
class 2 message type. According to GSM 11.14 here is what happens when these are set10:
If the service "data download via SMS Point-to-point" is allocated and activated in the
SIM Service Table, then the ME shall follow the procedure below:
- When the ME receives a Short Message with protocol identifier = SIM data download,
and data coding scheme = class 2 message, then the ME shall pass the message
transparently to the SIM using the ENVELOPE (SMS-PP DOWNLOAD) command.
- The ME shall not display the message, or alert the user of a short message waiting.
In other words, the phone will not display anything and the user will not be aware of this
attack.
Lets have a look at the secure command SMS header. One of its components is the
Security Parameter Indicator (SPI). SPI is 2 octets long and it has the following structure:
10
15
12
The vulnerability is possible due to the second byte: here you can set how the proof of
receipt (PoR) to be sent via SMS-DELIVER-REPORT or SMS-SUBMIT. When is set to be
on SMS-SUBMIT the phone will try to send back a reply to the originated sender.
If we set it to acknowledge the receipt via DELIVER REPORT, the phone will report to
the network the status of the message. Since we dont have valid entries for the KIc, KID,
11
12
16
TAR, the result of the STK command is an error so the report will be an error. The sending
SMSC then thinks that the phone hasnt received the message and it will try again to send the
message, putting on hold any other future messages that are supposed to be delivered, until
the initial message expires.
Below you will find a list of images taken from Wireshark indicating how the phone
behaves when the special crafted message with PoR set to SMS-SUBMIT is sent.
Figure 12 Capture from Wireshark showing the receipt of the STK message
17
Figure 13 - Capture from Wireshark showing the receipt of the STK message
As you can see, the PID is set to SIM Data download, DCS to SIM specific message
class 2 and the Information Element has the STK headers.
18
Next the SIM prepares to send a reply message GSM ENVELOPE packet and sends
it to the network.
19
Figure 16 - Capture from Wireshark showing GSM SIM packet with STK reply
The most important proof: the SMS was sent automatically due to a SIM Toolkit
operation and not due to a human intervention.
SIM Application Toolkit provides Value Added Services for the mobile operators.
Basically is a set of commands written on the SIM card which helps the card to communicate
with the mobile device, making it possible to initiate commands independently of the network
or handset.
Starting with the future phones, all of them are able to communicate via SIM Toolkit.
13
http://www.gemalto.com/techno/stk/
20
14
One of the best examples of the STK usage is the extra-menu that you see on your
phone, from which you can find details about weather, recharge account, your bank account
details, etc.
14
http://www.gemalto.com/techno/stk/
21
In the above capture you can see what happens when the messages comes with the SPI
byte having the POR set to DELIVER REPORT. First the phone receives the message
(Network to MS) and reports to the network that there was an issue (CP-DATA (RP) RPERROR). Further the network believes that the phone was not able to properly receive the
message and it will try over and over to send it, until it has expired.
more operators have these kinds of cards due to the continuous development of the mobile
banking, so it wont be so hard for an attacker to succeed. However, even with this
limitation, the attack works no matter the phone you use or the mobile network GSM
/ UMTS. Tests have been made on different feature phones and smartphone and they all
succeeded.
Another thing that should be taken into consideration is that the type of message is
addressed directly to the SIM. This means that the operator should allow the users to send
this type of SMS, which normally only the mobile operator would send. In practice not many
networks firewall the SMS, making it the perfect environment for an attacker since the SMS
is always on. However, even if the operator would filter such messages, it would be possible
to send the SMS if you have access to a SMSC. This brings us to a developed method of
attack.
When sending the message between different networks or the same network it doesnt
have such a great financial impact. First of all, if you send the message to someone registered
to the same operator as yours, most probably that person wont be charged extra due to the
billing plan which most of the time offers you some messages within the network. If you send
to someone registered on a different network, even internationally, it will cost you too much.
The question is how can we create a considerable financial impact? The answer is to use a
SMSC provider.
There are plenty such providers over the Internet to which you can connect in different
ways: by email, HTTP, SMPP. The issue is that not all forward correctly the APDU packets
to all or some mobile operators. During my research, after contacting about 10 different
providers I found two that correctly forwarded the messages to the destination networks
tested. It will take you some time, but in the end youll find for sure one that works. Most of
these providers allow you to change the sender number (address) to either numeric or
alphanumeric and they have really good rates for SMS somewhere in the low euro cent area
and even cheaper than the rates you have on your own operator.
23
Figure 20 Capture from NowSMS showing the options from SMPP connection
Given all these, now we can send a spoofed binary message coming from Thailand.
Since the command message sends the reply to the originated number, it will send the reply
in Thailand, thus paying much more and making the user get a pretty expensive bill. Even so,
the attacker wont gain any money. To overcome this, the attacker can easily get a premium
rate number which will charge 10 EUR per message received. All that is left to do is to spoof
the sender with the premium rate number he got. Now for only one message sent which is a
few cents he gains 10 times more. This has a great impact on the users and its not much
they can do.
How to protect from such attacks? There are a few ways:
Mobile operators could filter command messages that are not coming from
themselves. Even if its a network protection, users not being protected if not all of
the operators implement such security or in case someone comes with their own built
network like OpenBTS / OpenBSC, I still consider it would be the best protection
especially if we think about the premium rate numbers attack.
Some mobile devices have the option to ask the user about SIM actions. If the
option is set, when the phone will try to send the message it will ask to allow this. See
some images about this configuration and how the phone behaves.
Use a SIM card that has the service "data download via SMS Point-to-point"
deactivated or one that doesnt have any Toolkit Application on it.
24
Use a Nokia DCT3 phone and stay always connected with the F-BUS cable
and Wireshark opened (hard to make it always).
However its hard to answer such an ambiguous question as we dont have any
information about the type of message, the content, the destination. Also some SIM cards are
configured to automatically send a message to the network operator in order to receive
settings for MMS and Internet access when they are put in a new device. Most probably the
users will allow the phone to send the message.
25
References
ETSI TS 100 901 V7.5.0 (2001-12), page 13
ETSI TS 100 901 V7.5.0 (2001-12), page 38
ETSI GSM 11.14, December 1996, Version 5.2.0, page 33
ETSI TS 100 901 V7.5.0 (2001-12), page 42
ETSI TS 101 181 V8.9.0 (2005-06), page 13
ETSI TS 101 181 V8.9.0 (2005-06), page 13
http://adywicaksono.wordpress.com/2008/05/21/
http://bb.osmocom.org/trac/wiki/dct3-gsmtap
http://berlin.ccc.de/~tobias/cos/s60-curse-of-silenceadvisory.txt
http://en.wikipedia.org/wiki/SMS
http://www.gemalto.com/techno/stk/
http://www.mseclab.com
http://www.nobbi.com/pduspy.html
https://gsm.tsaitgaist.info/doku.php?id=siminfo
26