Repository navigation
Expand file tree
/
Copy pathroot_detection_bypass.js
More file actions
336 lines (310 loc) · 13 KB
/
Copy pathroot_detection_bypass.js
File metadata and controls
336 lines (310 loc) · 13 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
(() => {
'use strict';
const CONFIG = {
fingerprint: "google/crosshatch/crosshatch:10/QQ3A.200805.001/6578210:user/release-keys",
secureProps: {
"ro.secure": "1",
"ro.debuggable": "0",
"ro.build.type": "user",
"ro.build.tags": "release-keys"
}
};
const ROOT_INDICATORS = {
paths: new Set([
"/data/local/bin/su",
"/data/local/su",
"/data/local/xbin/su",
"/dev/com.koushikdutta.superuser.daemon/",
"/sbin/su",
"/su/bin/su",
"/system/bin/su",
"/system/xbin/su",
"/system/sbin/su",
"/vendor/bin/su",
"/data/adb/su/bin/su",
"/system/bin/failsafe/su",
"/system/bin/.ext/.su",
"/system/bin/.ext/su",
"/system/bin/failsafe/su",
"/system/sd/xbin/su",
"/system/usr/we-need-root/su",
"/cache/su",
"/data/su",
"/dev/su",
"/data/adb/magisk",
"/sbin/.magisk",
"/cache/.disable_magisk",
"/dev/.magisk.unblock",
"/cache/magisk.log",
"/data/adb/magisk.img",
"/data/adb/magisk.db",
"/data/adb/magisk_simple",
"/init.magisk.rc",
"/system/app/Superuser.apk",
"/system/etc/init.d/99SuperSUDaemon",
"/system/xbin/daemonsu",
"/system/xbin/ku.sud",
"/data/adb/ksu",
"/data/adb/ksud",
"/system/xbin/busybox",
"/system/app/Kinguser.apk"
]),
packages: new Set([
"com.noshufou.android.su",
"com.noshufou.android.su.elite",
"eu.chainfire.supersu",
"com.koushikdutta.superuser",
"com.thirdparty.superuser",
"com.yellowes.su",
"com.koushikdutta.rommanager",
"com.koushikdutta.rommanager.license",
"com.dimonvideo.luckypatcher",
"com.chelpus.lackypatch",
"com.ramdroid.appquarantine",
"com.ramdroid.appquarantinepro",
"com.topjohnwu.magisk",
"me.weishu.kernelsu"
]),
commands: new Set([
"su",
"which su",
"whereis su",
"locate su",
"find / -name su",
"mount",
"magisk",
"/system/bin/su",
"/system/xbin/su",
"/sbin/su",
"/su/bin/su"
]),
binaries: new Set([
"su",
"busybox",
"magisk",
"supersu",
"ksud",
"daemonsu"
])
};
const Logger = {
prefix: "RootBypass: ",
info(message) {
console.log(`${this.prefix}${message}`);
},
error(message, error) {
console.error(`${this.prefix}ERROR: ${message}`, error || "");
}
};
function bypassNativeFileCheck() {
const fopen = Module.findExportByName("libc.so", "fopen");
if (fopen) {
Interceptor.attach(fopen, {
onEnter(args) {
this.path = args[0].readUtf8String();
},
onLeave(retval) {
if (retval.toInt32() !== 0) {
const path = this.path.toLowerCase();
if (ROOT_INDICATORS.paths.has(this.path) || path.includes("magisk") || path.includes("/su") || path.endsWith("/su")) {
Logger.info(`Blocked fopen: ${this.path}`);
retval.replace(ptr(0x0));
}
}
}
});
}
const access = Module.findExportByName("libc.so", "access");
if (access) {
Interceptor.attach(access, {
onEnter(args) {
this.path = args[0].readUtf8String();
},
onLeave(retval) {
if (retval.toInt32() === 0) {
const path = this.path.toLowerCase();
if (ROOT_INDICATORS.paths.has(this.path) || path.includes("magisk") || path.includes("/su") || path.endsWith("/su")) {
Logger.info(`Blocked access: ${this.path}`);
retval.replace(ptr(-1));
}
}
}
});
}
const stat = Module.findExportByName("libc.so", "stat");
if (stat) {
Interceptor.attach(stat, {
onEnter(args) {
this.path = args[0].readUtf8String();
},
onLeave(retval) {
const path = this.path.toLowerCase();
if (ROOT_INDICATORS.paths.has(this.path) || path.includes("magisk") || path.includes("/su") || path.endsWith("/su")) {
Logger.info(`Blocked stat: ${this.path}`);
retval.replace(ptr(-1));
}
}
});
}
const lstat = Module.findExportByName("libc.so", "lstat");
if (lstat) {
Interceptor.attach(lstat, {
onEnter(args) {
this.path = args[0].readUtf8String();
},
onLeave(retval) {
const path = this.path.toLowerCase();
if (ROOT_INDICATORS.paths.has(this.path) || path.includes("magisk") || path.includes("/su") || path.endsWith("/su")) {
Logger.info(`Blocked lstat: ${this.path}`);
retval.replace(ptr(-1));
}
}
});
}
}
function bypassJavaFileCheck() {
const UnixFileSystem = Java.use("java.io.UnixFileSystem");
UnixFileSystem.checkAccess.implementation = function(file, access) {
const filename = file.getAbsolutePath();
if (ROOT_INDICATORS.paths.has(filename) || filename.includes("magisk") || filename.includes("su")) {
Logger.info(`Blocked file access check: ${filename}`);
return false;
}
return this.checkAccess(file, access);
};
const File = Java.use("java.io.File");
File.exists.implementation = function() {
const filename = this.getAbsolutePath();
if (ROOT_INDICATORS.paths.has(filename) || filename.includes("magisk") || filename.includes("su")) {
Logger.info(`Blocked file exists check: ${filename}`);
return false;
}
return this.exists();
};
File.length.implementation = function() {
const filename = this.getAbsolutePath();
if (ROOT_INDICATORS.paths.has(filename) || filename.includes("magisk") || filename.includes("su")) {
Logger.info(`Blocked file length check: ${filename}`);
return 0;
}
return this.length();
};
const FileInputStream = Java.use("java.io.FileInputStream");
FileInputStream.$init.overload('java.io.File').implementation = function(file) {
const filename = file.getAbsolutePath();
if (ROOT_INDICATORS.paths.has(filename) || filename.includes("magisk") || filename.includes("su")) {
Logger.info(`Blocked FileInputStream creation: ${filename}`);
throw new Java.use("java.io.FileNotFoundException").$new(filename);
}
return this.$init(file);
};
}
function setProp() {
try {
const Build = Java.use("android.os.Build");
const fields = {
"TAGS": "release-keys",
"TYPE": "user",
"FINGERPRINT": CONFIG.fingerprint
};
Object.entries(fields).forEach(([field, value]) => {
const fieldObj = Build.class.getDeclaredField(field);
fieldObj.setAccessible(true);
fieldObj.set(null, value);
});
const system_property_get = Module.findExportByName("libc.so", "__system_property_get");
if (system_property_get) {
Interceptor.attach(system_property_get, {
onEnter(args) {
this.key = args[0].readCString();
this.ret = args[1];
},
onLeave(retval) {
const secureValue = CONFIG.secureProps[this.key];
if (secureValue !== undefined) {
const valuePtr = Memory.allocUtf8String(secureValue);
Memory.copy(this.ret, valuePtr, secureValue.length + 1);
}
}
});
}
const Runtime = Java.use('java.lang.Runtime');
Runtime.exec.overload('java.lang.String').implementation = function(cmd) {
if (cmd.startsWith("getprop ")) {
const prop = cmd.split(" ")[1];
if (CONFIG.secureProps[prop]) {
Logger.info(`Blocked getprop command: ${cmd}`);
return null;
}
}
return this.exec(cmd);
};
} catch (error) {
Logger.error("Error setting up build properties bypass", error);
}
}
function bypassRootPackageCheck() {
const ApplicationPackageManager = Java.use("android.app.ApplicationPackageManager");
ApplicationPackageManager.getPackageInfo.overload('java.lang.String', 'int').implementation = function(str, i) {
if (ROOT_INDICATORS.packages.has(str)) {
Logger.info(`Blocked package check: ${str}`);
str = "com.nonexistent.package";
}
return this.getPackageInfo(str, i);
};
ApplicationPackageManager.getInstalledPackages.overload('int').implementation = function(flags) {
const packages = this.getInstalledPackages(flags);
const packageList = packages.toArray();
const filteredPackages = packageList.filter(pkg => !ROOT_INDICATORS.packages.has(pkg.packageName.value));
return Java.use("java.util.ArrayList").$new(filteredPackages);
};
}
function bypassShellCommands() {
try {
const ProcessBuilder = Java.use('java.lang.ProcessBuilder');
ProcessBuilder.command.overload('java.util.List').implementation = function(commands) {
const cmdList = commands.toArray();
if (cmdList.length > 0) {
const cmd = cmdList[0].toString();
if (ROOT_INDICATORS.commands.has(cmd) || (cmdList.length > 1 && ROOT_INDICATORS.binaries.has(cmdList[1].toString()))) {
Logger.info(`Blocked ProcessBuilder command: ${cmdList.join(' ')}`);
return this.command(Java.use("java.util.Arrays").asList([""]));
}
}
return this.command(commands);
};
const Runtime = Java.use('java.lang.Runtime');
Runtime.exec.overload('[Ljava.lang.String;').implementation = function(cmdArray) {
if (cmdArray.length > 0) {
const cmd = cmdArray[0];
if (ROOT_INDICATORS.commands.has(cmd) || (cmdArray.length > 1 && ROOT_INDICATORS.binaries.has(cmdArray[1]))) {
Logger.info(`Blocked Runtime.exec command array: ${cmdArray.join(' ')}`);
return this.exec([""]);
}
}
return this.exec(cmdArray);
};
const ProcessImpl = Java.use("java.lang.ProcessImpl");
ProcessImpl.start.implementation = function(cmdArray, env, dir, redirects, redirectErrorStream) {
if (cmdArray.length > 0) {
const cmd = cmdArray[0].toString();
const arg = cmdArray.length > 1 ? cmdArray[1].toString() : "";
if (ROOT_INDICATORS.commands.has(cmd) || ROOT_INDICATORS.binaries.has(arg)) {
Logger.info(`Blocked ProcessImpl command: ${cmdArray.join(' ')}`);
return ProcessImpl.start.call(this, [Java.use("java.lang.String").$new("")], env, dir, redirects, redirectErrorStream);
}
}
return ProcessImpl.start.call(this, cmdArray, env, dir, redirects, redirectErrorStream);
};
} catch (error) {
Logger.error("Error setting up shell command bypass", error);
}
}
Logger.info("Initializing root detection bypass...");
bypassNativeFileCheck();
bypassJavaFileCheck();
setProp();
bypassRootPackageCheck();
bypassShellCommands();
Logger.info("Root detection bypass initialized successfully");
})();