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的手機隨意下載軟件,更不要以任何藉口製造任何病毒!

 

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

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

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

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

 

 

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

android安全問題(二) 程序鎖

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章