-
Notifications
You must be signed in to change notification settings - Fork 0
/
sample_code
161 lines (146 loc) · 5.26 KB
/
sample_code
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
/*
* Author: Security Bong
*/
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GoogleApiAvailability;
import com.google.android.gms.safetynet.SafetyNet;
import com.google.android.gms.safetynet.SafetyNetApi;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.gms.tasks.Task;
import android.os.Debug;
import android.util.Log;
import com.talosdigital.safeout.Talos;
public class SecurityHelper {
// Root Detection
public static boolean isRootedDevice() {
return checkRootFiles() || checkRootCommands() || checkRootPackages();
}
private static boolean checkRootFiles() {
String[] rootFiles = { "/system/bin/su", "/system/xbin/su", "/sbin/su", "/system/app/Superuser.apk",
"/system/app/SuperSU.apk", "/system/app/MagiskManager.apk" };
for (String file : rootFiles) {
if (new File(file).exists()) {
return true;
}
}
return false;
}
private static boolean checkRootCommands() {
try {
Process process = Runtime.getRuntime().exec(new String[] { "/system/xbin/which", "su" });
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
if (bufferedReader.readLine() != null) {
return true;
}
} catch (Exception e) {
// Ignore exceptions
}
return false;
}
private static boolean checkRootPackages() {
String[] rootPackages = { "com.noshufou.android.su", "com.thirdparty.superuser", "eu.chainfire.supersu",
"com.koushikdutta.superuser" };
PackageManager packageManager = getApplicationContext().getPackageManager();
for (String packageName : rootPackages) {
try {
packageManager.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
return true;
} catch (PackageManager.NameNotFoundException e) {
// Package not found
}
}
return false;
}
// Tamper Detection
public static boolean isTampered() {
return checkIntegrity() || checkDebuggable() || checkFrida();
}
private static boolean checkIntegrity() {
// Implement integrity check logic, such as checksum verification, to detect tampering with critical files
// Return true if tampering is detected
return false;
}
private static boolean checkDebuggable() {
return (getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
}
private static boolean checkFrida() {
try {
throw new RuntimeException();
} catch (RuntimeException e) {
for (StackTraceElement element : e.getStackTrace()) {
if (element.getClassName().contains("frida") || element.getClassName().contains("objection")) {
return true;
}
}
}
return false;
}
// Anti-Debugging Techniques
public static boolean isDebuggerAttached() {
return Debug.isDebuggerConnected();
}
// Code Obfuscation
// Apply code obfuscation techniques to make it harder for attackers to understand and modify the code.
// This can include using tools like ProGuard,
// Runtime Application Self-Protection (RASP)
public static void initializeRASP() {
Talos.initialize(getApplicationContext());
Talos.startProtection();
}
}
*##or you can do this way*
// Android & iOS
privilegedAccess: () => {
console.log('privilegedAccess');
throw Error('Issue found in privilegedAccess');
},
// Android & iOS
debug: () => {
console.log('debug');
throw Error('Issue found in debug');
},
// Android & iOS
simulator: () => {
console.log('simulator');
throw Error('Issue found in simulator');
},
// Android & iOS
appIntegrity: () => {
console.log('appIntegrity');
throw Error('Issue found in appIntegrity');
},
// Android & iOS
unofficialStore: () => {
console.log('unofficialStore');
throw Error('Issue found in unofficialStore');
},
// Android & iOS
hooks: () => {
console.log('hooks');
throw Error('Issue found in hooks');
},
// Android & iOS
deviceBinding: () => {
console.log('deviceBinding');
throw Error('Issue found in deviceBinding');
},
// Android & iOS
secureHardwareNotAvailable: () => {
console.log('secureHardwareNotAvailable');
throw Error('Issue found in secureHardwareNotAvailable');
},
// Android & iOS
passcode: () => {
console.log('passcode');
throw Error('Issue found in passcode');
},
// iOS only
deviceID: () => {
console.log('deviceID');
throw Error('Issue found in deviceID');
},
// Android only
obfuscationIssues: () => {
console.log('obfuscationIssues');
throw Error('Issue found in obfuscationIssues');
},