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

上篇在里面介绍了由于Android设计上的缺陷而导致的钓鱼漏洞,并且也在文末介绍了用户防范的方法。

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

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

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

程序截图如下:

其中Service代码如下:

/*

* @(#)AntiService.java Project:ActivityHijackingDemo

* Date:2012-9-13

*

* Copyright (c) 2011 CFuture09, Institute of Software,

* Guangdong Ocean University, Zhanjiang, GuangDong, China.

* All rights reserved.

*

* Licensed under the Apache License, Version 2.0 (the "License");

* you may not use this file except in compliance with the License.

* You may obtain a copy of the License at

*

* http://www.apache.org/licenses/LICENSE-2.0

*

* Unless required by applicable law or agreed to in writing, software

* distributed under the License is distributed on an "AS IS" BASIS,

* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

* See the License for the specific language governing permissions and

* limitations under the License.

*/

packagecom.sinaapp.msdxblog.antihijacking.service;

importandroid.app.ActivityManager;

importandroid.app.Notification;

importandroid.app.Service;

importandroid.content.Context;

importandroid.content.Intent;

importandroid.content.pm.PackageManager;

importandroid.content.pm.PackageManager.NameNotFoundException;

importandroid.os.Bundle;

importandroid.os.Handler;

importandroid.os.IBinder;

importandroid.os.Message;

importandroid.util.Log;

importcom.sinaapp.msdxblog.androidkit.thread.HandlerFactory;

importcom.sinaapp.msdxblog.antihijacking.AntiConstants;

importcom.sinaapp.msdxblog.antihijacking.view.AntiView;

/**

* @author Geek_Soledad (66704238@51uc.com)

*/

publicclassAntiServiceextendsService {

privatebooleanshouldLoop =false;

privateHandler handler;

privateActivityManager am;

privatePackageManager pm;

privateHandler mainHandler;

privateAntiView mAntiView;

privateintcircle =2000;

@Override

publicIBinder onBind(Intent intent) {

returnnull;

}

@Override

publicvoidonStart(Intent intent,intstartId) {

super.onStart(intent, startId);

startForeground(19901008,newNotification());

if(intent !=null) {

circle = intent.getIntExtra(AntiConstants.CIRCLE, 2000);

}

Log.i("circle", circle +"ms");

if(true== shouldLoop) {

return;

}

mAntiView = newAntiView(this);

mainHandler = newHandler() {

publicvoidhandleMessage(Message msg) {

String name = msg.getData().getString("name");

mAntiView.setText(name);

};

};

pm = getPackageManager();

shouldLoop = true;

am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);

handler = newHandler(

HandlerFactory.getHandlerLooperInOtherThread("anti")) {

@Override

publicvoidhandleMessage(Message msg) {

super.handleMessage(msg);

String packageName = am.getRunningTasks(1).get(0).topActivity

.getPackageName();

try{

String progressName = pm.getApplicationLabel(

pm.getApplicationInfo(packageName,

PackageManager.GET_META_DATA)).toString();

updateText(progressName);

} catch(NameNotFoundException e) {

e.printStackTrace();

}

if(shouldLoop) {

handler.sendEmptyMessageDelayed(0, circle);

}

}

};

handler.sendEmptyMessage(0);

}

privatevoidupdateText(String name) {

Message message = newMessage();

Bundle data = newBundle();

data.putString("name", name);

message.setData(data);

mainHandler.sendMessage(message);

}

@Override

publicvoidonDestroy() {

shouldLoop = false;

mAntiView.remove();

super.onDestroy();

}

}

浮动窗口仅为一个简单的textview,非此次的技术重点,在这里省略不讲。

当然,从以上代码也可以看出本程序只能防范通过Activity作为钓鱼界面的程序,因为它是通过运行的顶层的Activity来获取程序名称的,对WooYun最近提到的另一个钓鱼方法它还是无能为力的,关于这一点将在下次谈。

【编辑推荐】

【责任编辑:chenqingxiang TEL:(010)68476606】

点赞 0

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值