本文旨在配置windows subsystem for android(win安卓子系统)来作为win在开启了hyper-v的情况下的一种轻量的安卓模拟器方案。使用MagiskOnWsa设置root权限,最终使其正常与开发环境、frida、ida打通。
常用的Wsa版本在目前是没有默认root的。在物理机上要解决这一情况就需要刷机,而模拟器显然是不具备刷机的条件的 —— 要么就直接下载带root的系统镜像,或者自己魔改一个带root的——Wsa的root方案和这个思路类似,在Github的LSPosed仓库里有MagiskOnWsa方案,利用其可以编译出自带Magisk的WSA系统。
重要 如果使用wsl虚拟机进行制作,请务必使用ubuntu 16虚拟机。高版本(截止2023.7.11的最新版本)下的MagiskOnWsa的run.sh、install.sh在wsl的ubuntu 20、22下并不会解析vhdx镜像。
安装16.04版本
1
|
wsl --install
-d
Ubuntu
|
git配置:
1
2
3
4
5
6
7
8
|
# fatal: unable to connect to github.com
git config --global url.
"https://github.com"
.insteadOf git:
//github
.com
# fatal: unable to access ‘https://github.com/robbyrussell/oh-my-zsh.git/’: LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443
git config --global --
unset
http.proxy
git config --global --
unset
https.proxy
# OpenSSL SSL_read: Connection was reset, errno 10054
git init
|
build
1
2
3
|
git clone https:
//github
.com
/LSPosed/MagiskOnWSALocal
.git --depth 1
cd
MagiskOnWSALocal
.
/scripts/run
.sh
|
install
1
|
PowerShell.exe
-ExecutionPolicy
Bypass
-File
.\Install.ps1
|
开发模式
connect
1
2
3
4
|
adb connect 127.0.0.1:58526
#may failed,continue
adb shell
redfin:/ $ su
redfin:/
#
|
WSA安装完成后会弹出Magisk界面,如果点那个安装,安装失败了也无所谓,不影响。
开始测试之前,我们需要简单检查一下WSA的设置:
这里一定要关闭高级网络。WSA的高级网络的级别和WSL相似,甚至可以说更高。开启WSA后其可以直接探测、同步物理机wifi,可以说这二者用的是同一张网卡。几个佐证是①开启高级网络后安卓虚拟机更改连接的wifi会同步更改物理机wifi②安卓虚拟机的ip和物理机一致。
这里的佐证②也直接导致了一点:端口冲突。
通常的frida链接情景可以说默认是“两台机器”—— 无论是物理链接还是模拟器、远程链接都是两台机器,这也意味着这里至少会有“两个ip”。在这个情况下,adb需要为目标机器的frida_server和开发机器的frida-tools之间做端口转发。如adb forward tcp:27043 tcp:27043。但是当WSA是处于高级网络这种,共用一张网卡,甚至ip都一样的情况下,端口冲突问题就显然而然的出现了。(甚至WSA需要通过127.0.0.1:58526来链接,普通的修改连接的端口并不能很好地解决这个问题)
此外,注意这个选项是会影响到系统服务的。建议资源富余就开启始终分配,不富余就部分运行中结合使用时挂起一个应用
1
2
3
4
5
6
7
|
adb push frida_android_x64_server /data/local/tmp
adb connect 127.0.0.1:58526
adb shell
redfin:/ $ su root
redfin:/
# cd /data/local/tmp
redfin:/
# chmod 777 frida-server-16.0.19-android-x86_64
redfin:/data/local/tmp
# ./frida-server-16.0.19-android-x86_64
|
1
2
3
4
5
6
7
|
frida-ps
-Ua
PID Name Identifier
4 -------------- ---------------------------------------
4139 Google com.google.android.googlequicksearchbox
4139 Google com.google.android.googlequicksearchbox
4231 Magisk com.topjohnwu.magisk
2150 My Application com.example.myapplication
|
用AS写一个测试demo,这里我使用了有点击选项的样例,添加了hook目标函数knockKnock:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
.
.
.
binding.fab.setOnClickListener(
new
View.OnClickListener() {
@Override
public
void
onClick(View view) {
Snackbar.make(view,
"Replace with your own action"
, Snackbar.LENGTH_LONG)
.setAction(
"Action"
,
null
).show();
konckKnock();
}
});
.
.
.
public
void
konckKnock(){
Log.d(
"123"
,
"123"
);
}
.
.
.
|
可以注意到调试机器选择里默认连上了我们的wsa系统:
frida测试脚本,缝缝补补得来的:
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
|
function
hook1(clz) {
console.log(
"234"
);
//var MainActivity = Java.use("com.example.myapplication");
console.log(
"456"
);
var
konckKnock = clz.konckKnock;
konckKnock.implementation =
function
() {
var
result =
this
.konckKnock()
console.log(
"GetTime called"
,
',result =>'
, result)
return
result
}
}
Java.perform(
function
() {
Java.choose(
"dalvik.system.PathClassLoader"
, {
onMatch:
function
(instance) {
console.log(instance)
console.log(Java.ClassFactory)
var
factory = Java.ClassFactory.get(instance)
console.log(factory)
try
{
var
myClass = factory.use(
"com.example.myapplication.MainActivity"
)
hook1(myClass)
console.log(
"stop"
)
return
"stop"
}
catch
(e) {
console.log(
"next"
)
// console.log(e)
}
},
onComplete:
function
() {
console.log(
"Done"
)
}
})
})
|
结果(记得点按钮)
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
|
frida
-U
'My Application'
-l
.\enmuClass.js
____
/ _ | Frida 16.0.19 - A world-class dynamic instrumentation toolkit
| (_| |
> _ | Commands:
/_/
|_
| help -> Displays the help system
. . . . object? -> Display information about
'object'
. . . . exit/quit -> Exit
. . . .
. . . . More info at https://frida.re/docs/home/
. . . .
. . . . Connected to Pixel 5 (id=127.0.0.1:58526)
Attaching...
dalvik.system.PathClassLoader[DexPathList[[zip file
"/system/framework/android.hidl.manager-V1.0-java.jar"
],nativeLibraryDirectories=[/system/lib64, /system_ext/lib64]]]
function
k() {
[native code]
}
[object Object]
next
dalvik.system.PathClassLoader[DexPathList[[directory
"."
],nativeLibraryDirectories=[/system/lib64, /system_ext/lib64, /system/lib64, /system_ext/lib64]]]
function
k() {
[native code]
}
[object Object]
next
dalvik.system.PathClassLoader[DexPathList[[zip file
"/system/framework/android.hidl.base-V1.0-java.jar"
],nativeLibraryDirectories=[/system/lib64, /system_ext/lib64]]]
function
k() {
[native code]
}
[object Object]
next
dalvik.system.PathClassLoader[DexPathList[[zip file
"/system/framework/android.test.base.jar"
],nativeLibraryDirectories=[/system/lib64, /system_ext/lib64]]]
function
k() {
[native code]
}
[object Object]
next
dalvik.system.PathClassLoader[DexPathList[[dex file
"/data/data/com.example.myapplication/code_cache/.overlay/base.apk/classes4.dex"
, zip file
"/data/app/~~ZuASwv4tbYUhGso4vQY7Ng==/com.example.myapplication-wE3oqwa5449uXSAVac29jg==/base.apk"
],nativeLibraryDirectories=[/data/app/~~ZuASwv4tbYUhGso4vQY7Ng==/com.example.myapplication-wE3oqwa5449uXSAVac29jg==/lib/x86_64, /data/app/~~ZuASwv4tbYUhGso4vQY7Ng==/com.example.myapplication-wE3oqwa5449uXSAVac29jg==/base.apk!/lib/x86_64, /system/lib64, /system_ext/lib64]]]
function
k() {
[native code]
}
[object Object]
234
456
stop
Done
[Pixel 5::My Application ]-> GetTime called ,result => undefined
|
server:
1
2
3
4
5
|
adb push .\android_x64_server /data/local/tmp
redfin:/data/local/tmp
# chmod 777 android_x64_server
redfin:/data/local/tmp
# ./android_x64_server
IDA Android x86 64-bit remote debug server(ST) v7.7.27. Hex-Rays (c) 2004-2022
Listening on 0.0.0.0:23946...
|
ip,在安卓设置的wifi里查看:
ida远程附加调试linux,并非调试arm linux/android:
更多【WSA - root frida与ida测试】相关视频教程:www.yxfzedu.com