Upload
others
View
18
Download
0
Embed Size (px)
Citation preview
Osmocom SIMtraceSIM card protocol tracing - why and how
Harald Welte
Harald Welte Osmocom SIMtrace November 2014 1 / 30
SIM Cards Smart Card Basics
Terminology
SIM Subscriber Identity ModuleUSIM Universal Subscriber Identity MdouleUICC Universal Integrated Chip Card
MS GSM Mobile Station (phone, modem)UE UMTS User EquipmentME GSM Mobile Equipment (MS + SIM)
OTA Over The AirSAT SIM Application ToolkitCAT Card (UICC) Application Toolkit
USAT USIM Application ToolkitTAR Toolkit Application Reference
Harald Welte Osmocom SIMtrace November 2014 2 / 30
SIM Cards Smart Card Basics
Relevant Specification Bodies
ISO (ISO 7816) smart cardsETSI (Eurpoean Telecomms Standardisation Institute)
Classic GSM SIMUICC card as basis for various telecom ID purposesCard Application Toolkit (CAT)
3GPP (3rd Generation Partnership Project)USIM ApplicationUSIM Application Toolkit (USAT)API based applet interworking
Global PlatformOverall spec for SIM/USIM with Java
Sun Microsystems (now Oracle)Java Card Virtual MachineJava Card Runtime Environment
Harald Welte Osmocom SIMtrace November 2014 3 / 30
SIM Cards Smart Card Basics
The Subscriber Identity Module (SIM)
Basic idea was to store cryptographic identity of subscriber insidesmart cardUser can thus migrate identity from one device to anotherUser can furthermore use different SIM in same device (e.g. localprepaid SIM while travelling)Original SIM card design mostly ISO 7816-4 filesystem and singlecommand to execute A3/A8 algorithm inside card
This could even be done in logic, no processor required
Harald Welte Osmocom SIMtrace November 2014 4 / 30
SIM Cards Smart Card Basics
The modern SIM
The modern SIM is an entirely different beastCryptographic processor smart card
Symmetric cryptography such as DES, 3DES, AESPublic key cryptography such as RSA, ECC
Java Card including a small Java VM and Java REMultiple application supportAbility to download applications (Applets) into card
Harald Welte Osmocom SIMtrace November 2014 5 / 30
SIM Cards Smart Card Basics
Smart Card Basics
microprocessor with RAM, Flash and Operating SystemInterface: Electrical + Logical Protocol (ISO7816-3, ISO7816-4)File System based representation of informationProtocol describes remote operations on the file systemFew non-filesystem related commands for e.g. authentication
Harald Welte Osmocom SIMtrace November 2014 6 / 30
SIM Cards Smart Card Basics
Smart Card Filesystem
Hierarchical file system like on PCMF (master file): root directoryDF (dedicated file): subdirectoryEF (entry file): actual file
transparent or record orientedrecord linear fixed/variable or record cyclic
File names don’t exist on card. 16bit FID (File ID) or 8bit SFIDused instead
Harald Welte Osmocom SIMtrace November 2014 7 / 30
SIM Cards Smart Card Basics
Smart Card Filesystem Hierarchy
Harald Welte Osmocom SIMtrace November 2014 8 / 30
SIM Cards Smart Card Basics
SIM Card APDU Commands
Classic SIM card commands include the followingSELECT (change directory / open file)READ BINARY, UPDATE BINARY (read/write transparent EF)READ RECORD, UPDATE RECORD (read/write record EF)ENABLE CHV, DISABLE CHV, CHANGE CHV (enable, disable orchange PIN)VERIFY CHV, UNBLOCK CHV (verify or unblock PIN)RUN GSM ALGORITHM (A3/A8 authentication)
Harald Welte Osmocom SIMtrace November 2014 9 / 30
SIM Cards Smart Card Basics
Smart Card Filesystem
Typical operations of the phone includenavigating inside filesystem by SELECT on DF/EFauthenticating the user PINreading/updating files
reading IMSIold-school SMS and contact storagestoring session keys (Kc/KcGPRS, ...)storing last cell on power-off
Harald Welte Osmocom SIMtrace November 2014 10 / 30
SIM Cards Smart Card Basics
Smart Card PINs
The level of access to the filesystem and other card features isdetermined by authentication using a shared secret, called ’PIN’.
Regular PIN for normal use of the card by the end userPUK for resetting the pin after too many retriesADM1..n PIN for access by the operator only
Harald Welte Osmocom SIMtrace November 2014 11 / 30
SIM Cards SIM Application Toolkit (SAT)
SIM Application Toolkit (SAT)
Ability for card to run applications that have UI on the phoneDisplay menu items on-screenGet user input from keypad/touch-screen
Original Version Described in TS 11.14 and 11.11
Harald Welte Osmocom SIMtrace November 2014 12 / 30
SIM Cards SIM Application Toolkit (SAT)
SAT – Proactive SIM
The Proactive SIM featuresSending a short messageSetting up a voice callPlayback of a tone in earpieceProviding location information from ME to SIMHave ME execute timers on behalf of SIMSending DTMF to networkRunning an AT command received from SIM, sending result backto SIMAsk ME to launch browser to SIM-provided URL
Harald Welte Osmocom SIMtrace November 2014 13 / 30
SIM Cards SIM Application Toolkit (SAT)
SAT – Call and SMS Control
ME passes MO call setup attempts to SIM for approvalSIM can then
approve or decline the MO callmodify the call details such as phone numberreplace the call with USSD message
ME passes USSD requests similar to Call ControlSimilar mechanism exists for all MO SMS
Harald Welte Osmocom SIMtrace November 2014 14 / 30
SIM Cards SIM Application Toolkit (SAT)
SAT – Provide local information
The SIM can inquire the ME aboutMCC / MNC / LAC / Cell IDIMEI of MENetwork Measurement ResultsBCCH channel listDate, Time, TimezoneME language settingTiming Advance
Harald Welte Osmocom SIMtrace November 2014 15 / 30
SIM Cards SIM Application Toolkit (SAT)
SAT – Event download
The SIM is notified by ME about certain events such asCall Connected / DisconnectedLocation Status (Location Area change)User activity (keyboard input)Idle screen availableBrowser termination
Harald Welte Osmocom SIMtrace November 2014 16 / 30
SIM Cards SIM Application Toolkit (SAT)
SAT - Data download
Enables Operator to exchange arbitrary data with the SIMCould be RFM (Remote File Management)
Read or modify phone book entriesEven change the IMSI of the SIM (!)
In case of Java Card, can be download of card appletsApplets are stored permanently on SIMCan later use SAT procedures to interact with METS 03.19 specifies Java API to access SAT from Java RE
Harald Welte Osmocom SIMtrace November 2014 17 / 30
SIM Cards SIM Application Toolkit (SAT)
SAT - Data download
SAT Data Download can happen viavia SMS or Cell Broadcast
Uses TS 03.40 TP-PID SIM DATA DownloadME forwards such SMS to the SIM in ENVELOPE APDUResponse from SIM is sent back as MO-SMS or DELIVERYREPORT
via BIP (Bearer Independent Protocol)Dedicated CSD call between network and SIMGPRS session between network and SIM
Harald Welte Osmocom SIMtrace November 2014 18 / 30
SIM Cards SIM Application Toolkit (SAT)
SAT - Data downloadData download security
GSM TS 03.48 specifies secure messaging for data downloadIncludes replay protectionSupports DES and 3DESSMS chaining for long commands / large data
Harald Welte Osmocom SIMtrace November 2014 19 / 30
SIM Cards SIM threat model
SIM card abuse by hostile operator
Even if the phone might be considered trusted, the SIM card isowned and controlled by the operatorUsing SAT features, the operator can control many aspects of thephoneExamples
Remotely reading address book / stored SMSMonitor user behavior (browser termination, idle screen, ...)Ask phone to establish packet data session
Harald Welte Osmocom SIMtrace November 2014 20 / 30
SIM Cards SIM threat model
SIM card re-programming by attacker
If the SIM is not properly secured (auth + encryption keys, ...) athird party attacker can send SAT envelope SMS to the card andinstall resident Java appletsThe attacker can then
Obtain detailed location information and send it via SMSIntercept/log outgoing callsSending copies of incoming + outgoing SMS elsewhere
Even using SIM card channel to exploit baseband stack is feasible
Harald Welte Osmocom SIMtrace November 2014 21 / 30
SIM Cards SIM threat model
SIM card proxy / MITM by attacker
As soon as an attacker has temporary physical access to a phone, hecan
Insert a proxy-SIM between real SIM and phoneDo everything a Java applet could do, but even with a securelyconfigured SIM as he does not modify the existing SIMSniff current Kc and send it out e.g. via SMS or even UDP/TCPpackets over GPRS... by only using standard interfaces that are common among allphones (as opposed to baseband software hacking which is verymodel-specific)
Most users would never notice this as they rarely check their SIM slot
Harald Welte Osmocom SIMtrace November 2014 22 / 30
SIM Cards SIM attacks countermeasures
Defending against SIM based attacks
SIM cards are Operator issued, Ki is on the SIMSIM card can thus not be replaced, but original SIM must be used
Configure telephone to not store contacts or SMS on SIMCommunication between SIM and ME is notencrypted/authenticatedSolution: Proxy SIM between SIM and ME to break STK / OTA
Filter all STK/OTA/Proactive commands like ENVELOPEIndicate lack of STK support to ME (EF.Phase)
Harald Welte Osmocom SIMtrace November 2014 23 / 30
SIM Cards SIM attacks countermeasures
Proxy SIM with firewall
There are no known commercial products that implementSTK/OTA filteringBut there are a number of shim SIM cards that are pluggedbetween SIM and SIM slotMost of them are used for SIM unlocking modern phonesSome vendors produce freely (re)programmable proxy SIMs:
Figure: Bladox TurboSIM (AVR) and RebelSIM II (8051)
Harald Welte Osmocom SIMtrace November 2014 24 / 30
Osmocom SIMtrace Analyzing SIM drivers and STK apps
Analyzing SIM toolkit applications is hard
Regular end-user phone does not give much debuggingSIM card itself has no debug interface for printing error messages,warnings, etc.However, as SIM-ME interface is unencrypted, sniffing / tracing ispossibleCommercial / proprietary solutions exist, but are expensive (USD5,000 and up)Technically, sniffing smard card interfaces is actually very simple
Harald Welte Osmocom SIMtrace November 2014 25 / 30
Osmocom SIMtrace Osmocom SIMtrace Introduction
Introducing Osmocom SIMtrace
Osmocom SIMtrace is a passive (U)SIM-ME communicationsnifferInsert SIM adapter cable into actual phoneInsert (U)SIM into SIMtrace hardwareSIMtrace hardware provides USB interface to host PCsimtrace host PC program encapsulates APDU in GSMTAPGSMTAP is sent via UDP to localhostwireshark dissector for GSM TS 11.11 decodes APDUs
Harald Welte Osmocom SIMtrace November 2014 26 / 30
Osmocom SIMtrace Osmocom SIMtrace Hardware
Osmocom SIMtrace Principle
Harald Welte Osmocom SIMtrace November 2014 27 / 30
Osmocom SIMtrace Osmocom SIMtrace Hardware
Osmocom SIMtrace Hardware
Harald Welte Osmocom SIMtrace November 2014 28 / 30
Osmocom SIMtrace Osmocom SIMtrace Hardware
Osmocom SIMtrace Hardware
Hardware is based around AT91SAM7S controllerSAM7S Offers two ISO 7816-3 compatible USARTsUSARTs can be clock master (SIM reader) or slave (SIM card)Open Source Firmware on SAM7S implementing APDU sniffingAuto-bauding depending CLK signal, PPS supportedSchematics / layout is open source (CC-BY-SA)Assembled + tested kits can be bought fromhttp://shop.sysmocom.de/
Harald Welte Osmocom SIMtrace November 2014 29 / 30
Osmocom SIMtrace Osmocom SIMtrace Hardware
wireshark decoding
Harald Welte Osmocom SIMtrace November 2014 30 / 30
Osmocom SIMtrace Osmocom SIMtrace Hardware
SIMtrace TODO
SIMtrace hardware is capable, but no software yet for:perform MITM (APDU filtering)full software SIM card emulationPC/SC compatible smart card readerautonomous tracing operation (No PC / USB), store APDU logs inthe field on integrated SPI flash
Firmware and host software all FOSS, anyone can extend andinnovate!
Harald Welte Osmocom SIMtrace November 2014 31 / 30