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


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

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

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

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

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

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

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

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

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

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

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

    Log代码 复制代码 收藏代码
    1. Current Notification Manager state:   
    2.   Notification List:   
    3.     NotificationRecord{41453c70 pkg=com.zdworks.android.toolbox id=7f090092 tag=null pri=0}   
    4.       icon=0x0 / <name unknown>   
    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=0x0 ledOnMS=0 ledOffMS=0  
    14.     NotificationRecord{415f48e8 pkg=com.zdworks.android.toolbox id=7f090080 tag=null pri=100}   
    15.       icon=0x7f0200fd / com.zdworks.android.toolbox:drawable/barttery_notify_icon   
    16.       contentIntent=PendingIntent{41949028: PendingIntentRecord{412e3c20 com.zdworks.android.toolbox startActivity}}   
    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=0x0 ledOnMS=0 ledOffMS=0  
    25.     NotificationRecord{416db3e0 pkg=android id=1040414 tag=null pri=100}   
    26.       icon=0x10804f5 / android:drawable/stat_sys_adb   
    27.       contentIntent=PendingIntent{41275de8: PendingIntentRecord{416dade8 android startActivity}}   
    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=0x0 ledOnMS=0 ledOffMS=0  
    36.     NotificationRecord{41790de8 pkg=com.htc.android.psclient id=7f020010 tag=null pri=100}   
    37.       icon=0x7f020010 / com.htc.android.psclient:drawable/usb_to_pc_notify   
    38.       contentIntent=PendingIntent{416c3e38: PendingIntentRecord{417bc968 com.htc.android.psclient startActivity}}   
    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=0x0 ledOnMS=0 ledOffMS=0  
    47.      
    48.   mSoundNotification=null   
    49.   mSound=com.android.server.NotificationPlayer@413e73b8   
    50.   mVibrateNotification=null   
    51.   mDisabledNotifications=0x0  
    52.   mSystemReady=true  

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

    下面的事情就简单

    1.想办法获取这段log

    2.提取包名

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

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

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

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

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

    按顺序简单解释一下

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

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

    Log代码 复制代码 收藏代码
    1. 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   

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

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

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

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

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

    转贴请保留以下链接

    本人blog地址

    http://su1216.iteye.com/

    http://blog.csdn.net/su1216/

  • 相关阅读:
    Jser 设计模式系列之面向对象
    jQuery 2.0.3 源码分析 回溯魔法 end()和pushStack()
    jQuery 2.0.3 源码分析 数据缓存
    jQuery 2.0.3 源码分析 Deferred(最细的实现剖析,带图)
    jQuery 2.0.3 源码分析 Deferred概念
    jQuery 2.0.3 源码分析 回调对象
    试试看 ? 离奇古怪的javascript题目
    jQuery 2.0.3 源码分析Sizzle引擎
    设计模式之美:Memento(备忘录)
    设计模式之美:Mediator(中介者)
  • 原文地址:https://www.cnblogs.com/jackrex/p/3001413.html
Copyright © 2020-2023  润新知