首页
社区
课程
招聘
[分享]静态分析-绕过java层root检测
2022-2-2 15:31 7797

[分享]静态分析-绕过java层root检测

2022-2-2 15:31
7797

0x1 什么是root

  1.root介绍

 

root是安卓系统的超级用户,拥有系统最高权限,可以对任意用户的目录或文件进行读取和修改,安卓的沙盒隔离机制对root用户变得无效,我们常说的手机root了,就是拥有了手机的root权限。

0x2 root风险

  1.坏处

 

系统遭到病毒入侵的风险变高,手机系统可能会不稳定。

0x3 什么是root检测

  1.介绍

 

由于root之后的手机环境变得不安全,可能对手机上的应用程序构成威胁,开发者为了保证自己开发的app在安全可靠的环境中运行,通常会进行root环境检测,阻止用户在root手机上运行app。

0x4 root检测实现

  1.方式

 

1)检测su文件,su命令在linux中是用来获取root权限的。

 

2)Superuser.apk,root后手机通过这个apk管理root权限,所以这也是一个特征。

 

3)检查busybox,安卓系统虽然是linux,但是很多命令没有,需要借助busybox工具箱,所以可以对其检测。

 

4)cat /system/bulld.prop | grep ro.bulld.tags,官方版本tags = release-key,通过这个可以判断是否第三方rom或者原生安卓系统,非官方版本。

0x5 实战绕过检测

  1.在模拟器中运行程序,提示设备root,被检测到了。

 

 

  2.将apk拖进Androidkiller工具,通过提示界面,可以看到有“安全警告”字样,使用工程搜索,没有搜索到,可能是中文编码格式的问题,使用编码转换功能,将文本进行Unicode编码再搜索

 

 

  3.双击过来,定位到代码,向上翻,看到if-eqz指令,如果v0是true就向下执行,否则就跳走,如果继续向下走,这里就弹窗警告了。

1
2
3
4
5
6
7
8
9
10
if-eqz v0, :cond_0
 
.line 29
new-instance v0, Landroidx/appcompat/app/AlertDialog$Builder;
 
invoke-direct {v0, p0}, Landroidx/appcompat/app/AlertDialog$Builder;-><init>(Landroid/content/Context;)V
 
.line 31
.local v0, "dialog":Landroidx/appcompat/app/AlertDialog$Builder;
const-string v3, "\u5b89\u5168\u8b66\u544a"

  4.再向上翻,找到给v0赋值的地方,发现执行这个静态方法后,isDeviceRooted()Z,Z代表函数返回值是布尔类型,move-result v0将返回值给v0。

1
2
3
invoke-static {}, Lcom/example/checkroot/rootcheck;->isDeviceRooted()Z
 
move-result v0

  5.找到rootcheck.smali打开看看代码,里面有四个函数

1
2
3
checkrelease()Z  //检查固件版本
const-string v1, "dev-keys"  //测试版
const-string v1, "test-keys"  //测试版

通过adb命令看一下,先adb shell进入系统,然后输入cat /system/build.prop | grep tags:

1
2
aosp:/ # cat /system/build.prop | grep tags
ro.build.tags=release-keys  //发行版,官方版(模拟器可以随便改)
1
2
3
4
5
6
7
8
9
10
11
.method public static checkRootPathSU()Z
 
const-string v1, "/system/bin/"
 
const-string v2, "/system/xbin/"
 
const-string v3, "/system/sbin/"
 
const-string v4, "/sbin/"
 
const-string v5, "/vendor/bin/"

检查这些目录下是否有su命令

1
2
3
.method public static checkSuperuserApk()Z
 
const-string v1, "/system/app/Superuser.apk"

第三个函数检查系统目录下是否存在Superuser.apk文件。

1
2
3
4
5
6
7
.method public static isDeviceRooted()Z
 
invoke-static {}, Lcom/example/checkroot/rootcheck;->checkSuperuserApk()Z
 
invoke-static {}, Lcom/example/checkroot/rootcheck;->checkRootPathSU()Z
 
invoke-static {}, Lcom/example/checkroot/rootcheck;->checkrelease()Z

第四个函数调用了前面三个函数进行检测,只要有一个是true,函数返回值就是true。

 

  6.这里if-eqz,我可以对它逻辑翻转,改成if-nez,这样就会跳走到:cond_0,提示“设备安全”了,保存,编译,安装到模拟器再试试。

 

 

  7.如果对smali代码不熟悉,进入这个类后,可以点上面的工具查看java源代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package com.example.checkroot;
 
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.util.Base64;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AlertDialog.Builder;
import androidx.appcompat.app.AppCompatActivity;
import java.io.UnsupportedEncodingException;
 
public class MainActivity
  extends AppCompatActivity
{
  protected void onCreate(final Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    setContentView(2131427356);
    if (rootcheck.isDeviceRooted())
    {
      paramBundle = new AlertDialog.Builder(this);
      paramBundle.setTitle("安全警告");
      paramBundle.setMessage("设备已root,点击确定退出");
      paramBundle.setCancelable(false);
      paramBundle.setPositiveButton("确定", new DialogInterface.OnClickListener()
      {
        public void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt)
        {
          System.exit(0);
        }
      });
      paramBundle.show();
    }
    else
    {
      paramBundle = new AlertDialog.Builder(this);
      paramBundle.setTitle("安全提示");
      paramBundle.setMessage("设备安全");
      paramBundle.setCancelable(false);
      paramBundle.setPositiveButton("确定", new DialogInterface.OnClickListener()
      {
        public void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt) {}
      });
      paramBundle.show();
    }
    paramBundle = (EditText)findViewById(2131231044);
    ((Button)findViewById(2131230940)).setOnClickListener(new View.OnClickListener()
    {
      public void onClick(View paramAnonymousView)
      {
        paramAnonymousView = null;
        try
        {
          String str = new String(Base64.decode("5Y2K5p2v5YeJ6Iy2", 2), "utf-8");
          paramAnonymousView = str;
        }
        catch (UnsupportedEncodingException localUnsupportedEncodingException)
        {
          localUnsupportedEncodingException.printStackTrace();
        }
        if (paramBundle.getText().toString().equals(paramAnonymousView)) {
          Toast.makeText(MainActivity.this.getApplicationContext(), "恭喜你,闯关成功", 0).show();
        } else {
          Toast.makeText(MainActivity.this.getApplicationContext(), "很遗憾,闯关失败", 0).show();
        }
        paramBundle.setVisibility(0);
      }
    });
  }
}

[CTF入门培训]顶尖高校博士及硕士团队亲授《30小时教你玩转CTF》,视频+靶场+题目!助力进入CTF世界

收藏
点赞2
打赏
分享
最新回复 (2)
雪    币: 31
能力值: ( LV1,RANK:0 )
在线值:
发帖
回帖
粉丝
小春儿 2022-8-7 03:18
2
0
请问例子在哪里可以下载呀
雪    币: 147
活跃值: (207)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
scllqk 2024-1-26 15:20
3
0
请问例子在哪里可以下载呀
游客
登录 | 注册 方可回帖
返回