大谈android安全2——Activity劫持的防范程序

上篇在里面介绍了由于Android设计上的缺陷而导致的钓鱼漏洞,并且也在文末介绍了用户防范的方法。
然而,如果真的爆发了这种恶意程序,我们并不能在启动程序时每一次都那么小心去查看判断当前在运行的是哪一个程序。因此,前几个星期花了一点时间写了一个程序,叫反劫持助手。原理很简单,就是获取当前运行的是哪一个程序,并且显示在一个浮动窗口中,以帮忙用户判断当前运行的是哪一个程序,防范一些钓鱼程序的欺骗。

在这一次,由于是“正当防卫”,就不再通过枚举来获取当前运行的程序了,在manifest文件中增加一个权限:

 
 
  1.   

然后启动程序的时候,启动一个Service,在Service中启动一个浮动窗口,并周期性检测当前运行的是哪一个程序,然后显示在浮动窗口中。
程序截图如下:

其中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. }  

 

浮动窗口仅为一个简单的textview,非此次的技术重点,在这里省略不讲。
当然,从以上代码也可以看出本程序只能防范通过Activity作为钓鱼界面的程序,因为它是通过运行的顶层的Activity来获取程序名称的,对WooYun最近提到的另一个钓鱼方法它还是无能为力的,关于这一点将在下次谈。

网站栏目:大谈android安全2——Activity劫持的防范程序
网页链接:http://www.shufengxianlan.com/qtweb/news23/325523.html

网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联