Simjacker技术分析报告

admin 2023-12-01 11:45:41 AnQuanKeInfo 来源:ZONE.CI 全球网 0 阅读模式

作者:殷文旭@360安全研究院独角兽安全团队

一、摘要

Simjacker及紧随其后公开的WIB攻击重新引起了各界对SIM卡安全的关注。现代SIM卡本质是由软件和硬件组成的计算机。硬件部分,各个引脚分别实现供电和通信;软件部分,安装了SIM, USIM, S@T Browser等应用,可以与手机、网络交互,实现各种功能。Simjacker攻击利用部分运营商发行的SIM卡中S@T Browser对收到的消息有效性不做校验这个安全配置错误,实现对目标远程定位等攻击。综合各方信息,我们发现Simjacker的攻击手法并非新颖,影响范围也相对有限。

 

二、事件背景

2019年9月12日,AdaptiveMobile Security公布了一种针对SIM卡S@T Browser的远程攻击方式:Simjacker。攻击者使用普通手机发送特殊构造的短信即可远程定位目标,危害较大。

根据AdaptiveMobile Security在2019年10月3日公布的全球受Simjacker攻击影响的地图可见,已发现的受该漏洞影响的SIM卡主要集中在拉丁美洲。

三、攻击原理

据AdaptiveMobile Security称:“The issue is that in affected operators, the SIM cards do not check the origin of messages that use the S@T Browser, and SIMs allow data download via SMS.”

1.条件一

SIM卡不检查使用S@T Browser的短信的来源有效性;

GSM时代,SIM卡是硬件和软件的组合。UMTS时代,SIM的含义发生了变化:SIM仅指软件部分,而硬件部分称为UICC。UMTS引入USIM应用提供双向鉴权等功能,提升了安全性。与USIM应用类似,Simjacker攻击的S@T Browser也只是UICC上的诸多应用之一。

理论上,与S@T Browser直接交互的是S@T Gateway,后者通常由运营商控制,二者通常使用短信交互;实际上,任何普通手机号码都可以尝试向另一个号码发送S@T Browser相关的短信,由运营商决定是否将其过滤掉,目前大部分运营商似乎不会过滤,因为正常情况下,收到短信的号码会对短信内容鉴权,普通人没有目标号码的鉴权密钥,因此发送的此类短信通常不会造成威胁;此外,SIM卡也可以选择只信任特定号码发来的这类短信。

总之,Simjacker攻击需要满足的第一个条件是:运营商和SIM卡不过滤与S@T Browser相关的短信,保证Payload可以送达目标Application: S@T Browser.

2.条件二

SIM卡允许通过短信下载数据;

USIM Application Toolkit (USAT)是UICC中规范应用与外界交互行为的标准,通常用来提供增值服务,如早期的手机银行。其中应用与手机ME交互使用Proactive Commands和Event Download两种形式。

“A proactive command is a command from the SIM application to the handset asking it to do something on your behalf. It is called proactive because, uncharacteristically, the SIM is initiating the communication.”[7] Proactive Commands是指应用“主动”发起的与手机交互的命令,截至2001年底,共有31种,其中包括DISPLAY TEXT,PROVIDE LOCAL INFORMATION(可以向手机查询当前所处小区Cell ID)等,但依然属于APDU(Application Protocol Data Unit)的范畴,手机ME依然是APDU命令的发起方,UICC Application是命令的响应方,只能在ME向其发送普通APDU命令时才能“主动”发送Proactive Commands。

为了解决这个不便,“The SIM can register for events that it wants to be told about. It uses the SET UP EVENT LIST proactive command to do this.”[7] “One of the most useful event downloads is SMS-PP. It is a way of communicating directly with the SIM using SMS.”[7]

SMS-PP Event Download即SMS-PP [Data] Download,手机收到SMS-PP类型的短信后,该事件被触发,短信被直接发送给UICC上的某个Application,由其处理短信内容,在此期间用户完全不知情。与SMS Peer to Peer(SMS-PP)对应的是SMS Cell Broadcast(SMS-CB)。前者即普通号码日常发送的短信的行为,后者只有运营商的短信中心SMS center (SMSC)才能操作。

Simjacker攻击中,需要SIM卡支持STK标准的Event Download,这样攻击者发送的特殊格式短信可以顺利触发SMS-PP Event Download,从而将Payload传递给S@T Browser完成远程定位等攻击。

3.原理总结

至此,Simjacker的攻击路线就很清楚了:

  1. 攻击者使用普通手机USIM卡,向攻击目标发送SMS-PP类型的短信,且目标应用是UICC上的S@T Browser;
  2. 攻击目标收到SMS-PP类型的短信后,SMS-PP Event Download事件触发,手机将短信直接发送给UICC上的S@T Browser应用;
  3. 与Proactive Commands中的诸多命令类似,S@T Browser也支持多种命令(Byte Codes),可以获取手机当前小区的Cell ID或主动发送短信。

四、Payload构造

Simjacker攻击使用的短信与我们日常发送的短信格式和内容都不同,但熟悉了格式之后,使用常见的上网卡或部分型号的手机,我们每个人都可以发送这种短信,其整体结构如下图所示。

3GPP TS 23.040即早期的GSM 03.40,规定了包括我们日常使用的短信在内的所有短信格式。3GPP TS 31.115即早期的GSM 03.48,则规定了Command Packet这种特殊格式的短信。该类短信不仅在与S@T Browser应用通信时会用到,运营商对SIM卡进行远程配置等OTA操作时亦使用。

1.短信格式

GSM 03.40标准规定了GSM网络下短信传输协议SM-TP中TPDU的格式。通常我们用到的TPDU类型有两种:SMS-SUBMIT和SMS-DELIVER。手机MS发给SC(Mobile Switching Centre )的是SMS-SUBMIT,SC发给MS的是SMS-DELIVER。

SMS-SUBMIT类型的TPDU通常使用的字段如下:

字段

名称

长度

备注

TP-MTI Message Type Indicator 2bits SMS-SUBMIT 01
TP-RD Reject Duplicates 1 bit Set to 0
TP-VPF Validity Period Format 2 bits Set to 00(not present)
TP-SRR Status Report Request 1 bit Set to 0
TP-UDHI User Data Header Indicator 1 bit Set to 1(GSM 03.48)
TP-RP Reply Path 1 bit Set to 0
TP-MR Message Reference 1 octet Set to 0x00
TP-DA Destination Address 2–12 octets Phone number(including country code) length after 0x91: 1octet

0x91

Phone number(0xF as padding to get even)

Example: 0x0D91688113325476F8

TP-PID Protocol Identifier 1 octet Set to 0x7F(USIM Data download)
TP-DCS Data Coding Scheme 1 octet Set to 0xF6

Character Set  8bit data

Class 2 (SIM/USIM-specific)

TP-UDL User Data Length 1 octet Number of octets in TP-UD
TP-UD User Data given by TP-UDL

2.Command Packet

GSM网络中的实体与SIM卡中的实体通过GSM 03.48协议实现安全的数据交换。发送方在应用信息的头部添加Security Header(Command Header)后得到完整的(Secured) Command Packet. 接收方根据Command Header中的指示决定是否发送(Secured) Response Packet.

SMS-PP是基于GSM 03.48格式的一种特殊短信,为运营商网络中和UICC上的Application之间的通信提供安全的信道。SMS-PP类型的短信UDHL为0x02,IEIa为0x70(发送),或0x71(接收),IEDLa为0x00,后面的字段为SMS-PP专属的负载内容。

SMS-PP类型的GSM 03.48 Command Packet字段如下:

字段

名称

长度

备注

UDHL User Data Header Length 1 octet Set to 0x02
IEIa Information Element Identifier a 1 octet Set to 0x70

CPI(Command Packet Indicator)

IEDLa Information Element Identifier Data Length a 1 octet Set to 0x00
CPL Command Packet Length 2 octets Number of octets after
CHL Command Header Length 1 octet Number of octets till RC/CC/DS
SPI Security Parameter Indicator 2 octets MSL
KIC Ciphering Key Identifier 1 octet
KID Key Identifier 1 octet
TAR Toolkit Application Reference 3 octets
CNTR Counter 5 octets
PCNTR Padding Counter 1 octet Number of padding octets used for ciphering

at the end of the secured data

RC/CC/DS Redundancy Check / Cryptographic Checksum / Digital Signature 0/4/8 octet(s)
SD Secured Data CPL – CHL – 1

1)SPI

SMS-PP Command Packet中比较关键的字段之一是SPI,长度2字节,含义如下:

SIM Alliance在Security guidelines for S@T Push [13]中所说的Minimum Security Level(MSL)在SPI的第一个字节设置,Cryptographic Checksum(10) + Encryption(1)的MSL = 0x06,即0000 0110;Cryptographic Checksum(10) + Encryption(1) + Anti-replay Counter(10)的MSL = 0x16,即0001 0110。

Bit 6设为1表示目标收到短信后,使用SMS-SUBMIT而不是普通的SMS-DELIVER-REPORT发送Response。

2)TAR

SIM toolkit applet的TAR长度为3个字节,ETSI TS 101 220将其定义为applet的AID的第13、14和15个字节。

根据标准,S@T Browser对应的TAR是0x505348(对应字符串’PSH’)和0x534054(对应字符串’S@T’)。

3.Response Packet

SMS-PP类型的GSM 03.48 Response Packet字段如下:

字段

名称

长度

备注

UDHL User Data Header Length 1 octet Set to 0x02
IEIa Information Element Identifier a 1 octet Set to 0x71

RPI(Response Packet Indicator)

IEDLa Information Element Identifier Data Length a 1 octet Set to 0x00
RPL Response Packet Length 2 octets Number of octets following
RHL Response Header Length 1 octet Number of octets till RC/CC/DS
TAR Toolkit Application Reference 3 octets The same as Command Packet
CNTR Counter 5 octets
PCNTR Padding Counter 1 octet
RSC Response Status Code 1 octet
Integrity Value RC/CC/DS Optional
Data Optional

 

五、SIM Browsers

在智能手机广泛使用之前,手机上除了打电话、发短信之外的其他联网服务,如手机银行,WAP上网等,都由运营商直接提供。在SIM卡上安装应用是扩展手机功能的主要方式之一,这些应用由运营商开发,通过OTA远程安装到用户SIM卡中。一些运营商认为OTA安装应用的效率较低,于是出现了SIM Browser,应用从用户的SIM卡转移到了运营商的服务器上,SIM卡上的Browser角色就像现代PC上的浏览器,只负责解析服务器传回的数据,而运营商可以随时增加、修改应用。

“As of mid 2001, there are three SIM microbrowsers: the original one from Across Wireless (now called Sonera Smarttrust), one originally developed by Gemplus and marketed by all the SIM card manufacturers under the umbrella of the SIMalliance, and another one called the USAT Interpreter that was wending its way through the 3GPP standardization process.”[7]

Simjacker攻击利用的S@T Browser就是上述三种Browser之一,而WIB攻击[10]则利用SmartTrust主导的Wireless Internet Browser(WIB).

1.SmartTrust Wireless Internet Browser

  • TAR值:0x000001, 0x000002
  • 客户端:Wireless Internet Browser(WIB)
  • 服务器:Wireless Internet Gateway(WIG)

“All messages have a GSM 03.48 security header.”[8] “The GSM 03.48 Proof of Receipt (PoR) mechanism is not used.”[8] “By default, if the WIB receives a message with a TAR value of 1, then it came from the WIG server (pull); if it receives a message with a TAR value of 2, then it came from the WIG client (push).”[7]

2.SIM Alliance S@T Browser

  • TAR值:0x534054, 0x505348
  • 客户端:S@T Browser
  • 服务器:S@T Gateway

S@T Browser主动发起的连接称为Pull,S@T Gateway主动发起的连接称为Push。Simjacker攻击存在原因是某些运营商的卡将S@T Browser的MSL设为0x00,即完全没有任何保护。攻击者以S@T Gateway的身份向目标UICC的S@T Browser发送Byte Codes,达到远程定位、发送短信等目的。

3.3GPP USAT Interpreter

“The 3GPP USAT Interpreter originally was supposed to be a merge of the Across Wireless microbrowser and the SIMalliance microbrowser but it has found a voice of its own in the process. It’s not too far from the truth to say that it combines some of the best features of its two parents.”[7]

六、NSA相关工具

在Simjacker之前,大家对SIM卡远程攻击的主要印象来自美国国家安全局NSA旗下Tailored Access Operations (TAO)组织泄露的两款工具:MONKEYCALENDAR和GOPHERSET。与Simjacker利用SIM卡的安全配置错误进行远程攻击不同,这两款工具使用的前提是攻击者掌握目标SIM卡的OTA密钥,从而能以合法的发卡运营商身份远程安装攻击程序。

MONKEYCALENDAR和GOPHERSET两种攻击工具需要运行在目标的SIM卡上,虽然同样难以察觉,但相比Simjacker这种无需安装,直接远程发送控制命令的攻击方式相比,使用门槛较高。

三者的相同之处在于:

  1. 攻击触发都是利用STK标准中的Event Download;
  2. 具体敏感信息的获取都是利用STK标准中的Proactive Command;
  3. 都使用短信外发数据。

七、防御措施

The SIMalliance在”Security guidelines for S@T Push”中 recommends to implement security for S@T push messages. This security can be introduced at two different levels:

  1. At the network level, filtering can be implemented to intercept and block the illegitimate binary SMS messages
  2. At the SIM card level, the Minimum Security Level – MSL – attached to the S@T browser in push mode can force Cryptographic Checksum + Encryption (MSL = 0x06 at least) In such cases where the replay of legitimate messages could lead to undesirable effects, MSL with Cryptographic Checksum + Encryption and anti- replay Counter is recommended (e.g. 0x16)

Simjacker攻击存在的根源在于某些运营商的(U)SIM卡对卡上的某些Application(如S@T Browser, Wireless Internet Browser)的SPI配置错误(MSL为0)。如果SPI配置无误,正常情况下攻击者很难绕过GSM 03.48的鉴权、加密。当然,像S@T Browser, WIB这种目前不再使用的Application还是建议运营商通过OTA将其卸载,以减小攻击面。

Reference

  1. https://srlabs.de/bites/rooting-sim-cards/
  2. https://srlabs.de/bites/sim_attacks_demystified/
  3. https://opensource.srlabs.de/projects/simtester
  4. https://www.evilsocket.net/2015/07/27/how-to-use-old-gsm-protocolsencodings-know-if-a-user-is-online-on-the-gsm-network-aka-pingsms-2-0/
  5. https://android.googlesource.com/platform/frameworks/opt/telephony/+/tools_r22/src/java/com/android/internal/telephony/gsm/UsimDataDownloadHandler.java
  6. https://github.com/mitshell/card
  7. Mobile Application Development with SMS and the SIM Toolkit. Scott B. Guthery Mary J. Cronin.
  8. https://www.slideshare.net/JulienSIMON5/wib-13
  9. https://ginnoslab.org/2019/09/27/stattack-vulnerability-in-st-sim-browser-can-let-attackers-globally-take-control-of-hundreds-of-millions-of-the-victim-mobile-phones-worldwide-to-make-a-phone-call-send-sms-to-any-phone-numbers/
  10. https://ginnoslab.org/2019/09/21/wibattack-vulnerability-in-wib-sim-browser-can-let-attackers-globally-take-control-of-hundreds-of-millions-of-the-victim-mobile-phones-worldwide-to-make-a-phone-call-send-sms-to-any-phone-numbers/
  11. https://adywicaksono.wordpress.com/2008/05/21/understanding-gsm-0348/
  12. http://rednaxela.net/pdu.php
  13. Security guidelines for S@T Push. The SIMalliance.
  14. https://simjacker.com/downloads/technicalpapers/AdaptiveMobile_Security_Simjacker_Technical_Paper.pdf
  15. https://www.schneier.com/blog/archives/2014/02/monkeycalendar.html
weinxin
版权声明
本站原创文章转载请注明文章出处及链接,谢谢合作!
Simjacker技术分析报告 AnQuanKeInfo

Simjacker技术分析报告

作者:殷文旭@360安全研究院独角兽安全团队 一、摘要 Simjacker及紧随其后公开的WIB攻击重新引起了各界对SIM卡安全的关注。现代SIM卡本质是由软件
评论:0   参与:  0