日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢(xún)
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問(wèn)題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷(xiāo)解決方案
大談android安全2——Activity劫持的防范程序

上篇在里面介紹了由于Android設(shè)計(jì)上的缺陷而導(dǎo)致的釣魚(yú)漏洞,并且也在文末介紹了用戶防范的方法。
然而,如果真的爆發(fā)了這種惡意程序,我們并不能在啟動(dòng)程序時(shí)每一次都那么小心去查看判斷當(dāng)前在運(yùn)行的是哪一個(gè)程序。因此,前幾個(gè)星期花了一點(diǎn)時(shí)間寫(xiě)了一個(gè)程序,叫反劫持助手。原理很簡(jiǎn)單,就是獲取當(dāng)前運(yùn)行的是哪一個(gè)程序,并且顯示在一個(gè)浮動(dòng)窗口中,以幫忙用戶判斷當(dāng)前運(yùn)行的是哪一個(gè)程序,防范一些釣魚(yú)程序的欺騙。

在這一次,由于是“正當(dāng)防衛(wèi)”,就不再通過(guò)枚舉來(lái)獲取當(dāng)前運(yùn)行的程序了,在manifest文件中增加一個(gè)權(quán)限:

 
 
  1.   

然后啟動(dòng)程序的時(shí)候,啟動(dòng)一個(gè)Service,在Service中啟動(dòng)一個(gè)浮動(dòng)窗口,并周期性檢測(cè)當(dāng)前運(yùn)行的是哪一個(gè)程序,然后顯示在浮動(dòng)窗口中。
程序截圖如下:

其中Service代碼如下:

 
 
  1. /* 
  2. * @(#)AntiService.java Project:ActivityHijackingDemo 
  3. * Date:2012-9-13 
  4. * Copyright (c) 2011 CFuture09, Institute of Software, 
  5. * Guangdong Ocean University, Zhanjiang, GuangDong, China. 
  6. * All rights reserved. 
  7. * Licensed under the Apache License, Version 2.0 (the "License"); 
  8. * you may not use this file except in compliance with the License. 
  9. * You may obtain a copy of the License at 
  10. * http://www.apache.org/licenses/LICENSE-2.0 
  11. * Unless required by applicable law or agreed to in writing, software 
  12. * distributed under the License is distributed on an "AS IS" BASIS, 
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
  14. * See the License for the specific language governing permissions and 
  15. * limitations under the License. 
  16. */ 
  17. package com.sinaapp.msdxblog.antihijacking.service; 
  18. import android.app.ActivityManager; 
  19. import android.app.Notification; 
  20. import android.app.Service; 
  21. import android.content.Context; 
  22. import android.content.Intent; 
  23. import android.content.pm.PackageManager; 
  24. import android.content.pm.PackageManager.NameNotFoundException; 
  25. import android.os.Bundle; 
  26. import android.os.Handler; 
  27. import android.os.IBinder; 
  28. import android.os.Message; 
  29. import android.util.Log; 
  30. import com.sinaapp.msdxblog.androidkit.thread.HandlerFactory; 
  31. import com.sinaapp.msdxblog.antihijacking.AntiConstants; 
  32. import com.sinaapp.msdxblog.antihijacking.view.AntiView; 
  33. /** 
  34. * @author Geek_Soledad (66704238@51uc.com) 
  35. */ 
  36. public class AntiService extends Service { 
  37. private boolean shouldLoop = false; 
  38. private Handler handler; 
  39. private ActivityManager am; 
  40. private PackageManager pm; 
  41. private Handler mainHandler; 
  42. private AntiView mAntiView; 
  43. private int circle = 2000; 
  44. @Override 
  45. public IBinder onBind(Intent intent) { 
  46. return null; 
  47. @Override 
  48. public void onStart(Intent intent, int startId) { 
  49. super.onStart(intent, startId); 
  50. startForeground(19901008, new Notification()); 
  51. if (intent != null) { 
  52. circle = intent.getIntExtra(AntiConstants.CIRCLE, 2000); 
  53. Log.i("circle", circle + "ms"); 
  54. if (true == shouldLoop) { 
  55. return; 
  56. mAntiView = new AntiView(this); 
  57. mainHandler = new Handler() { 
  58. public void handleMessage(Message msg) { 
  59. String name = msg.getData().getString("name"); 
  60. mAntiView.setText(name); 
  61. }; 
  62. }; 
  63. pm = getPackageManager(); 
  64. shouldLoop = true; 
  65. am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); 
  66. handler = new Handler( 
  67. HandlerFactory.getHandlerLooperInOtherThread("anti")) { 
  68. @Override 
  69. public void handleMessage(Message msg) { 
  70. super.handleMessage(msg); 
  71. String packageName = am.getRunningTasks(1).get(0).topActivity 
  72. .getPackageName(); 
  73. try { 
  74. String progressName = pm.getApplicationLabel( 
  75. pm.getApplicationInfo(packageName, 
  76. PackageManager.GET_META_DATA)).toString(); 
  77. updateText(progressName); 
  78. } catch (NameNotFoundException e) { 
  79. e.printStackTrace(); 
  80. if (shouldLoop) { 
  81. handler.sendEmptyMessageDelayed(0, circle); 
  82. }; 
  83. handler.sendEmptyMessage(0); 
  84. private void updateText(String name) { 
  85. Message message = new Message(); 
  86. Bundle data = new Bundle(); 
  87. data.putString("name", name); 
  88. message.setData(data); 
  89. mainHandler.sendMessage(message); 
  90. @Override 
  91. public void onDestroy() { 
  92. shouldLoop = false; 
  93. mAntiView.remove(); 
  94. super.onDestroy(); 
  95. }  

 

浮動(dòng)窗口僅為一個(gè)簡(jiǎn)單的textview,非此次的技術(shù)重點(diǎn),在這里省略不講。
當(dāng)然,從以上代碼也可以看出本程序只能防范通過(guò)Activity作為釣魚(yú)界面的程序,因?yàn)樗峭ㄟ^(guò)運(yùn)行的頂層的Activity來(lái)獲取程序名稱(chēng)的,對(duì)WooYun最近提到的另一個(gè)釣魚(yú)方法它還是無(wú)能為力的,關(guān)于這一點(diǎn)將在下次談。


本文題目:大談android安全2——Activity劫持的防范程序
路徑分享:http://www.dlmjj.cn/article/cceohhg.html