android手机root后的安全问题 (二)

本文解析了杀毒软件如何监听并处理Android系统的应用通知,通过adb shell命令获取系统通知记录,并从中提取应用包名。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

上一篇将过如何利用root权限来做一次静默安装,有的人会说,安装apk就安装呗,反正哥有金山手机卫士,哥有360主动防御……他们都会弹出通知告诉我的!

安装了新的应用,手机会发送广播,这些所谓的杀毒软件监听这些广播,然后弹出通知

好吧,我承认,他们在一定意义上还是有点用处的,我们先把这个问题放一放,先来说两句题外话

360和和金山手机卫士都有一个让广大android开发者比较蛋疼的一个功能:那就是检查广告通知!

当有通知栏有广告的时候,运行360执行检查,它会告诉你是哪个应用程序的广告(当然,这里并不局限于广告,他们是获得所有通知,然后过滤),然后他会让用户选择:不处理;关闭通知(实际上是把这个进程kill掉,整个软件停止运行);卸载此软件。

虽然我没有发布过android应用,但是我知道,靠软件赚钱的各位,本来收入已经够尴尬的了,再加上这些操蛋的软件提供这些操蛋的功能……哎

大家不喜欢收费软件那咱们就免费,点点广告支持一下总行吧,就是不点,你就放在那呗(当然,有的软件发起广告来没玩没了也挺操蛋)

说了这么多废话,我们就来看看那些所谓的杀毒软件是如何对付大家的

到了关键的地方,实际也就那么一行代码……又让大家失望了。。。

Shell代码 复制代码 收藏代码
  1. adbshelldumpsysnotification
adb shell dumpsys notification

比如,我现在在我机器上面执行一下,输出的结果为

Log代码 复制代码 收藏代码
  1. CurrentNotificationManagerstate:
  2. NotificationList:
  3. NotificationRecord{41453c70pkg=com.zdworks.android.toolboxid=7f090092tag=nullpri=0}
  4. icon=0x0/<nameunknown>
  5. contentIntent=null
  6. deleteIntent=null
  7. tickerText=null
  8. contentView=null
  9. defaults=0x0
  10. flags=0x62
  11. sound=null
  12. vibrate=null
  13. ledARGB=0x0ledOnMS=0ledOffMS=0
  14. NotificationRecord{415f48e8pkg=com.zdworks.android.toolboxid=7f090080tag=nullpri=100}
  15. icon=0x7f0200fd/com.zdworks.android.toolbox:drawable/barttery_notify_icon
  16. contentIntent=PendingIntent{41949028:PendingIntentRecord{412e3c20com.zdworks.android.toolboxstartActivity}}
  17. deleteIntent=null
  18. tickerText=电量提示
  19. contentView=android.widget.RemoteViews@416e7b90
  20. defaults=0x0
  21. flags=0x22
  22. sound=null
  23. vibrate=null
  24. ledARGB=0x0ledOnMS=0ledOffMS=0
  25. NotificationRecord{416db3e0pkg=androidid=1040414tag=nullpri=100}
  26. icon=0x10804f5/android:drawable/stat_sys_adb
  27. contentIntent=PendingIntent{41275de8:PendingIntentRecord{416dade8androidstartActivity}}
  28. deleteIntent=null
  29. tickerText=USB调试已连接
  30. contentView=android.widget.RemoteViews@416daf40
  31. defaults=0x0
  32. flags=0x2
  33. sound=null
  34. vibrate=null
  35. ledARGB=0x0ledOnMS=0ledOffMS=0
  36. NotificationRecord{41790de8pkg=com.htc.android.psclientid=7f020010tag=nullpri=100}
  37. icon=0x7f020010/com.htc.android.psclient:drawable/usb_to_pc_notify
  38. contentIntent=PendingIntent{416c3e38:PendingIntentRecord{417bc968com.htc.android.psclientstartActivity}}
  39. deleteIntent=null
  40. tickerText=null
  41. contentView=android.widget.RemoteViews@4169d128
  42. defaults=0x0
  43. flags=0x2
  44. sound=null
  45. vibrate=null
  46. ledARGB=0x0ledOnMS=0ledOffMS=0
  47. mSoundNotification=null
  48. mSound=com.android.server.NotificationPlayer@413e73b8
  49. mVibrateNotification=null
  50. mDisabledNotifications=0x0
  51. mSystemReady=true
Current Notification Manager state:
  Notification List:
    NotificationRecord{41453c70 pkg=com.zdworks.android.toolbox id=7f090092 tag=null pri=0}
      icon=0x0 / <name unknown>
      contentIntent=null
      deleteIntent=null
      tickerText=null
      contentView=null
      defaults=0x0
      flags=0x62
      sound=null
      vibrate=null
      ledARGB=0x0 ledOnMS=0 ledOffMS=0
    NotificationRecord{415f48e8 pkg=com.zdworks.android.toolbox id=7f090080 tag=null pri=100}
      icon=0x7f0200fd / com.zdworks.android.toolbox:drawable/barttery_notify_icon
      contentIntent=PendingIntent{41949028: PendingIntentRecord{412e3c20 com.zdworks.android.toolbox startActivity}}
      deleteIntent=null
      tickerText=电量提示
      contentView=android.widget.RemoteViews@416e7b90
      defaults=0x0
      flags=0x22
      sound=null
      vibrate=null
      ledARGB=0x0 ledOnMS=0 ledOffMS=0
    NotificationRecord{416db3e0 pkg=android id=1040414 tag=null pri=100}
      icon=0x10804f5 / android:drawable/stat_sys_adb
      contentIntent=PendingIntent{41275de8: PendingIntentRecord{416dade8 android startActivity}}
      deleteIntent=null
      tickerText=USB 调试已连接
      contentView=android.widget.RemoteViews@416daf40
      defaults=0x0
      flags=0x2
      sound=null
      vibrate=null
      ledARGB=0x0 ledOnMS=0 ledOffMS=0
    NotificationRecord{41790de8 pkg=com.htc.android.psclient id=7f020010 tag=null pri=100}
      icon=0x7f020010 / com.htc.android.psclient:drawable/usb_to_pc_notify
      contentIntent=PendingIntent{416c3e38: PendingIntentRecord{417bc968 com.htc.android.psclient startActivity}}
      deleteIntent=null
      tickerText=null
      contentView=android.widget.RemoteViews@4169d128
      defaults=0x0
      flags=0x2
      sound=null
      vibrate=null
      ledARGB=0x0 ledOnMS=0 ledOffMS=0
  
  mSoundNotification=null
  mSound=com.android.server.NotificationPlayer@413e73b8
  mVibrateNotification=null
  mDisabledNotifications=0x0
  mSystemReady=true

现在大家知道了吧,这么简单就把咱们给搞定了

下面的事情就简单

1.想办法获取这段log

2.提取包名

3.根据数据库中的黑名单白名单不同处理

4.你的应用很可能在黑名单中,最后的结果也基本是进程被杀死

(这里就不演示3、4部分了,只演示1、2)

Java代码 复制代码 收藏代码
  1. testButton=(Button)findViewById(R.id.exec);
  2. testButton.setOnClickListener(newView.OnClickListener(){
  3. publicvoidonClick(Viewv){
  4. String[]commands={"dumpsysnotification"};
  5. Processprocess=null;
  6. DataOutputStreamdataOutputStream=null;
  7. try{
  8. process=Runtime.getRuntime().exec("su");
  9. dataOutputStream=newDataOutputStream(process.getOutputStream());
  10. intlength=commands.length;
  11. for(inti=0;i<length;i++){
  12. Log.e(TAG,"commands["+i+"]:"+commands[i]);
  13. dataOutputStream.writeBytes(commands[i]+"\n");
  14. }
  15. dataOutputStream.writeBytes("exit\n");
  16. dataOutputStream.flush();
  17. process.waitFor();
  18. BufferedReaderreader=null;
  19. reader=newBufferedReader(newInputStreamReader(process.getInputStream()));
  20. Stringline="";
  21. List<String>lineList=newArrayList<String>();
  22. finalStringBuilderlog=newStringBuilder();
  23. Stringseparator=System.getProperty("line.separator");
  24. Patternpattern=Pattern.compile("pkg=[^\\s]+");
  25. while((line=reader.readLine())!=null){
  26. if(line!=null&&line.trim().startsWith("NotificationRecord")){
  27. Matchermatcher=pattern.matcher(line);
  28. if(matcher.find()){
  29. lineList.add(matcher.group());
  30. }else{
  31. Log.e(TAG,"what'sthis?!");
  32. }
  33. }
  34. log.append(line);
  35. log.append(separator);
  36. }
  37. Log.v(TAG,"log:"+log.toString());
  38. intsize=lineList.size();
  39. for(inti=0;i<size;i++){
  40. Log.i(TAG,"app:"+lineList.get(i));
  41. }
  42. }catch(Exceptione){
  43. Log.e(TAG,"copyfail",e);
  44. }finally{
  45. try{
  46. if(dataOutputStream!=null){
  47. dataOutputStream.close();
  48. }
  49. process.destroy();
  50. }catch(Exceptione){
  51. }
  52. }
  53. Log.v(TAG,"finish");
  54. }
  55. });
  56. }
testButton = (Button)findViewById(R.id.exec);
testButton.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
        String[] commands = {"dumpsys notification"};
        Process process = null;
        DataOutputStream dataOutputStream = null;

        try {
            process = Runtime.getRuntime().exec("su");
            dataOutputStream = new DataOutputStream(process.getOutputStream());
            int length = commands.length;
            for (int i = 0; i < length; i++) {
                Log.e(TAG, "commands[" + i + "]:" + commands[i]);
                dataOutputStream.writeBytes(commands[i] + "\n");
            }
            dataOutputStream.writeBytes("exit\n");
            dataOutputStream.flush();
            
            process.waitFor();
            
            BufferedReader reader = null;
            reader = new BufferedReader(new InputStreamReader(process.getInputStream()));  
            String line = "";
            List<String> lineList = new ArrayList<String>();
            final StringBuilder log = new StringBuilder();  
            String separator = System.getProperty("line.separator");
            Pattern pattern = Pattern.compile("pkg=[^\\s]+");
            while ((line = reader.readLine()) != null) {
                if(line != null && line.trim().startsWith("NotificationRecord")){
                    Matcher matcher = pattern.matcher(line);
                    if(matcher.find()){
                        lineList.add(matcher.group());
                    }else{
                        Log.e(TAG, "what's this?!");
                    }
                }
                
                log.append(line);
                log.append(separator);
            }
            Log.v(TAG, "log:" + log.toString());
            
            int size = lineList.size();
            for (int i = 0; i < size; i++) {
                Log.i(TAG, "app:" + lineList.get(i));
            }
        } catch (Exception e) {
            Log.e(TAG, "copy fail", e);
        } finally {
            try {
                if (dataOutputStream != null) {
                    dataOutputStream.close();
                }
                process.destroy();
            } catch (Exception e) {
            }
        }
        Log.v(TAG, "finish");
        }
    });
}

上面的这段代码实在没什么技术含量,让给位网友见笑了

按顺序简单解释一下

首先,我们先执行dumpsys notification这条命令,这在上一期的代码中已经有了

然后通过process.getInputStream()获得其输出按行读取,这里只关心类似于下面这种的log

Log代码 复制代码 收藏代码
  1. NotificationRecord{40dacad8pkg=com.htc.android.psclientid=7f020010tag=nullpri=100}
NotificationRecord{40dacad8 pkg=com.htc.android.psclient id=7f020010 tag=null pri=100}

然后从中提取出包名即可

其中的正则就是为了提取包名用的,想了解正则的同学可以看我的正则教程

深入入门正则表达式(java)

这里我执行的结果为(看来有一个应用提示了两个通知)

Java代码 复制代码 收藏代码
  1. app:pkg=com.zdworks.android.toolbox
  2. app:pkg=com.zdworks.android.toolbox
  3. app:pkg=android
  4. app:pkg=com.htc.android.psclient
app:pkg=com.zdworks.android.toolbox
app:pkg=com.zdworks.android.toolbox
app:pkg=android
app:pkg=com.htc.android.psclient

之后的工作就是把这个list展示给用户,让用户去选择了

既然360可以这样,病毒为什么不可以呢?病毒Fake.apk可以在半夜偷偷安装应用Real.apk,几秒钟后,Fake.apk执行上面的这些操作,获取360,然后kill!爽!

大家有兴趣可以反编译一下金山和360,他们基本就是这么干的,我发现360比较坏,至于为什么这么说,大家自己去发现吧

ps:我使用的是卡巴斯基免费版,杀毒软件是不会去管有没有广告推送的,广告不是病毒,杀毒软件也不应该干一些不该干的事!

请大家不要用root的手机随意下载软件,更不要以任何借口制造任何病毒!

转贴请保留以下链接

本人blog地址

http://su1216.iteye.com/

http://blog.youkuaiyun.com/su1216/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值