android手機root後的安全問題 (二)

來源:互聯網
上載者:User

導讀:本文介紹殺毒軟體和病毒是如何擷取通知欄上的所有通知,並且利用其資訊殺死應用。

上一篇將過如何利用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}

然後從中提取出包名即可

其中的正則就是為了提取包名用的,想瞭解正則的同學可以看我的正則教程

深入入門Regex(java)

這裡我執行的結果為(看來有一個應用提示了兩個通知)

app:pkg=com.zdworks.android.toolboxapp:pkg=com.zdworks.android.toolboxapp:pkg=androidapp:pkg=com.htc.android.psclient 

之後的工作就是把這個list展示給使用者,讓使用者去選擇了

既然360可以這樣,病毒為什麼不可以呢?病毒Fake.apk可以在半夜偷偷安裝應用Real.apk,幾秒鐘後,Fake.apk執行上面的這些操作,擷取360,然後kill!爽!

大家有興趣可以反編譯一下金山和360,他們基本就是這麼乾的,我發現360比較壞,至於為什麼這麼說,大家自己去發現吧

ps:我使用的是卡巴斯基免費版,殺毒軟體是不會去管有沒有廣告推送的,廣告不是病毒,殺毒軟體也不應該幹一些不該乾的事!

請大家不要用root的手機隨意下載軟體,更不要以任何借口製造任何病毒!

android手機root後的安全問題 (一)

android手機root後的安全問題 (二)

android手機root後的安全問題 (三)

android手機root後的安全問題 (四)

android安全問題(一) 靜音拍照與被拍

android安全問題(二) 程式鎖

android安全問題(三) 釣魚程式

轉貼請保留以下連結

本人blog地址

http://su1216.iteye.com/

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.