赞
踩
APK 完整性校验,虽然很难做到绝对的安全,但能提高应用的安全性和破解难度。
可以通过修改客户端文件篡改客户端行为。攻击者可以让客户端显示自己制作的钓鱼网站,偷取用户信息
Android对每一个Apk文件都会进行签名,在Apk文件安装时,系统会对其签名信息进行比对,判断程序的完整性,从而决定该Apk文件是否可以安装,在一定程度上达到安全的目的。
结论:从上面的总结可以看出,META-INFO里面的说那个文件环环相扣,从而保证Android程序的安全性。(只是防止开发者的程序不被攻击者修改,如果开发者的公私钥对对攻击者得到或者开发者开发出攻击程序,Android系统都无法检测出来。)
虽然系统通过以上方式可以防止,但如果是root的手机就不安全了,建议通过服务器来校验,
用crc32对classes.dex文件的完整性进行校验
- public class MainActivity extends Activity {
-
- @Override
-
- protected void onCreate(BundlesavedInstanceState) {
-
- super.onCreate(savedInstanceState);
-
- setContentView(R.layout.activity_main);
-
- String apkPath = getPackageCodePath();
-
- Long dexCrc = Long.parseLong(getString(R.string.classesdex_crc));
- //建议将dexCrc值放在服务器做校验
-
- try
-
- {
-
- ZipFile zipfile = new ZipFile(apkPath);
-
- ZipEntry dexentry = zipfile.getEntry("classes.dex");
-
- Log.i("verification","classes.dexcrc="+dexentry.getCrc());
-
- if(dexentry.getCrc() != dexCrc){
-
- Log.i("verification","Dexhas been modified!");
-
- }else{
-
- Log.i("verification","Dex hasn't been modified!");
-
- }
-
- } catch (IOException e) {
-
- // TODO Auto-generated catch block
-
- e.printStackTrace();
-
- }
-
- }
-
- }

用哈希值对整个apk完整性进行校验
- public class MainActivity extends Activity {
-
- @Override
-
- protected void onCreate(BundlesavedInstanceState) {
-
- super.onCreate(savedInstanceState);
-
- setContentView(R.layout.activity_main);
-
-
- String apkPath = getPackageCodePath();
-
- MessageDigest msgDigest = null;
-
- try {
-
- msgDigest = MessageDigest.getInstance("SHA-1");
-
- byte[] bytes = new byte[1024];
-
- int byteCount;
-
- FileInputStream fis = new FileInputStream(new File(apkPath));
-
- while ((byteCount = fis.read(bytes)) > 0)
-
- {
-
- msgDigest.update(bytes, 0, byteCount);
-
- }
-
- BigInteger bi = new BigInteger(1, msgDigest.digest());
-
- String sha = bi.toString(16);
-
- fis.close();
-
- //这里添加从服务器中获取哈希值然后进行对比校验
-
- } catch (Exception e) {
-
- e.printStackTrace();
-
- }
-
-
-
- }
-
- }

我们将把crc值和sha1值放在服务器做处理
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。