Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add additional checks for android. Check if user id 0 can execute su, different which paths and check installs #118

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class GreaterThan23 implements CheckApiVersion {

@Override
public boolean checkRooted() {
return checkRootMethod1() || checkRootMethod2();
return checkRootMethod1() || checkRootMethod2() || checkUserIdAndExecuteSu() || checkFolderAccess() || checkInstalls();
}

private boolean checkRootMethod1() {
Expand All @@ -31,7 +31,16 @@ private boolean checkRootMethod1() {
private boolean checkRootMethod2() {
Process process = null;
try {
process = Runtime.getRuntime().exec(new String[] { "/system/xbin/which", "su" });
final String whichPathOld = "system/xbin/which";
final String whichPathNew = "system/bin/which";

if (new File(whichPathOld).exists()) {
process = Runtime.getRuntime().exec(new String[]{whichPathOld, "su"});
} else if (new File(whichPathNew).exists()) {
process = Runtime.getRuntime().exec(new String[]{whichPathNew, "su"});
} else {
process = Runtime.getRuntime().exec(new String[]{"which", "su"});
}
BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
if (in.readLine() != null) return true;
return false;
Expand All @@ -41,4 +50,62 @@ private boolean checkRootMethod2() {
if (process != null) process.destroy();
}
}

private boolean checkUserIdAndExecuteSu() {
Process process = null;

try {
process = Runtime.getRuntime().exec("id");
BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
if (in.readLine().contains("uid=0")) return true;

// Android Will throw exception if permission denied when user try to invoke Su
process = Runtime.getRuntime().exec("su");
return true;
} catch (Throwable t) {
return false;
} finally {
if (process != null) process.destroy();
}
}

private boolean checkFolderAccess() {
String[] paths = {"/data"};
for (String path : paths) {
if (new File(path).canRead()) return true;
}
return false;
}

private boolean checkInstalls() {
Process process = null;
String[] installs = {
"magisk",
"com.noshufou.androd.au",
"com.thirdparty.superuser",
"eu.chainfire.supersu",
"com.koushikdutta.superuser",
"com.zachspong.temprootromovejb",
"com.ramdroid.appquarantine",
"com.devadvance.rootcloak",
"com.devadvance.rootcloakplus",
};

try {
process = Runtime.getRuntime().exec("pm list packages");
BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = in.readLine();
while (line != null) {
for (String keyWord : installs) {
if (line.contains(keyWord)) {
return true;
}
}
line = in.readLine();
}
} catch (Throwable e) {
return false;
}
return false;
}
}