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

导读:本文介绍杀毒软件和病毒是如何获取通知栏上的所有通知,并且利用其信息杀死应用。

上一篇将过如何利用root权限来做一次静默安装,有的人会说,安装apk就安装呗,反正哥有金山手机卫士,哥有360主动防御……他们都会弹出通知告诉我的!
安装了新的应用,手机会发送广播,这些所谓的杀毒软件监听这些广播,然后弹出通知
好吧,我承认,他们在一定意义上还是有点用处的,我们先把这个问题放一放,先来说两句题外话

360和和金山手机卫士都有一个让广大android开发者比较蛋疼的一个功能:那就是检查广告通知!
当有通知栏有广告的时候,运行360执行检查,它会告诉你是哪个应用程序的广告(当然,这里并不局限于广告,他们是获得所有通知,然后过滤),然后他会让用户选择:不处理;关闭通知(实际上是把这个进程kill掉,整个软件停止运行);卸载此软件。

虽然我没有发布过android应用,但是我知道,靠软件赚钱的各位,本来收入已经够尴尬的了,再加上这些操蛋的软件提供这些操蛋的功能……哎
大家不喜欢收费软件那咱们就免费,点点广告支持一下总行吧,就是不点,你就放在那呗(当然,有的软件发起广告来没玩没了也挺操蛋)

说了这么多废话,我们就来看看那些所谓的杀毒软件是如何对付大家的
到了关键的地方,实际也就那么一行代码……又让大家失望了。。。
adb shell dumpsys notification

比如,我现在在我机器上面执行一下,输出的结果为
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)
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
NotificationRecord{40dacad8 pkg=com.htc.android.psclient id=7f020010 tag=null pri=100}

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

这里我执行的结果为(看来有一个应用提示了两个通知)
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比较坏,至于为什么这么说,大家自己去发现吧


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

猜你喜欢

转载自iaiai.iteye.com/blog/2229916