Talking about Android security 2 - Activity hijacking prevention program

Talking about Android security 2 - Activity hijacking prevention program

The previous article introduced phishing vulnerabilities caused by design flaws in Android, and also introduced user prevention methods at the end of the article.
However, if such a malicious program really breaks out, we cannot be so careful to check and determine which program is currently running every time we start the program. Therefore, I spent some time writing a program called Anti-Hijacking Assistant a few weeks ago. The principle is very simple, which is to obtain which program is currently running and display it in a floating window to help users determine which program is currently running and prevent the deception of some phishing programs.

This time, because it is "self-defense", we no longer use enumeration to obtain the currently running program, but add a permission in the manifest file:

  1. <uses-permission android:name= "android.permission.GET_TASKS" />


Then when the program is started, a Service is started, a floating window is started in the Service, and the currently running program is periodically detected and then displayed in the floating window.
The program screenshots are as follows:

The Service code is as follows:

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

The floating window is just a simple textview, which is not the technical focus of this article and will not be discussed here.
Of course, it can be seen from the above code that this program can only prevent programs that use Activity as a phishing interface, because it obtains the program name through the running top-level Activity. It is still powerless against another phishing method recently mentioned by WooYun. We will talk about this next time.

<<:  Talking about Android security 1——Activity hijacking and user prevention

>>:  How to safely exit multiple Activities on Android

Recommend

Reality is your brain's best guess

© Brain Latam Leviathan Press: We often joke abou...

Live worms found in milk powder! Is it the powder's fault or the worm's?

As the saying goes, "When spring thunder roa...

The soldier wiped his butt with its leaves and committed suicide due to the pain

Makes people and animals go crazy with pain The l...

Analysis from 3 aspects: two Weibo, one Douyin, one Bilibili, and one Live!

An indisputable fact is that new media operators ...

What knowledge is needed to operate Tik Tok?

Douyin in the south and Kuaishou in the north are...

A collection of 50 promotional plans!

For marketing, there is no doubt that promotion i...