-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjs_to_json_converter.py
More file actions
325 lines (280 loc) · 11 KB
/
js_to_json_converter.py
File metadata and controls
325 lines (280 loc) · 11 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
#!/usr/bin/env python3
"""
JavaScript to JSON Configuration Converter
Helps convert JavaScript code to JSON-compatible format for Frida configs
"""
import json
import re
import sys
class JSToJSONConverter:
def __init__(self):
self.common_scripts = {
"ssl_pinning_bypass": {
"description": "Bypass SSL certificate pinning",
"code": """
Java.perform(function() {
var X509TrustManager = Java.use('javax.net.ssl.X509TrustManager');
var SSLContext = Java.use('javax.net.ssl.SSLContext');
var TrustManager = Java.registerClass({
name: 'com.frida.TrustManager',
implements: [X509TrustManager],
methods: {
checkClientTrusted: function(chain, authType) {},
checkServerTrusted: function(chain, authType) {},
getAcceptedIssuers: function() { return []; }
}
});
var trustManager = TrustManager.$new();
var sslContext = SSLContext.getInstance('TLS');
sslContext.init(null, [trustManager], null);
console.log('[+] SSL Pinning bypassed');
});
""".strip()
},
"root_detection_bypass": {
"description": "Bypass common root detection methods",
"code": """
Java.perform(function() {
// RootBeer library bypass
try {
var RootBeer = Java.use('com.scottyab.rootbeer.RootBeer');
RootBeer.isRooted.implementation = function() {
console.log('[+] RootBeer.isRooted() bypassed');
return false;
};
} catch (e) {}
// Common root detection methods
try {
var Runtime = Java.use('java.lang.Runtime');
Runtime.exec.overload('java.lang.String').implementation = function(cmd) {
if (cmd.includes('su') || cmd.includes('busybox') || cmd.includes('which')) {
console.log('[+] Blocked root detection command: ' + cmd);
throw new Error('Command not found');
}
return this.exec(cmd);
};
} catch (e) {}
console.log('[+] Root detection bypass loaded');
});
""".strip()
},
"debug_detection_bypass": {
"description": "Bypass debug detection",
"code": """
Java.perform(function() {
var Debug = Java.use('android.os.Debug');
Debug.isDebuggerConnected.implementation = function() {
console.log('[+] Debug.isDebuggerConnected() bypassed');
return false;
};
// Block gettimeofday checks for debugging detection
var libc = Module.findExportByName("libc.so", "gettimeofday");
if (libc) {
Interceptor.attach(libc, {
onLeave: function(retval) {
// Normalize timing to prevent debug detection
}
});
}
console.log('[+] Debug detection bypass loaded');
});
""".strip()
},
"frida_detection_bypass": {
"description": "Bypass Frida detection",
"code": """
Java.perform(function() {
// Hook common Frida detection methods
var System = Java.use('java.lang.System');
System.getProperty.implementation = function(key) {
if (key === "java.vm.name") {
return "Dalvik";
}
return this.getProperty(key);
};
// Block port scanning for Frida server
var Socket = Java.use('java.net.Socket');
Socket.$init.overload('java.lang.String', 'int').implementation = function(host, port) {
if (port === 27042 || port === 27043) {
console.log('[+] Blocked Frida port scan: ' + host + ':' + port);
throw new Error('Connection refused');
}
return this.$init(host, port);
};
console.log('[+] Frida detection bypass loaded');
});
""".strip()
}
}
def clean_js_for_json(self, js_code):
"""Clean JavaScript code to be JSON-safe"""
# Remove extra whitespace and newlines
js_code = ' '.join(js_code.strip().split())
# Escape quotes for JSON
js_code = js_code.replace('"', '\\"')
return js_code
def create_config_with_js(self, package_name, target_class, js_scripts):
"""Create a complete config with JavaScript"""
config = {
"app": {
"package_name": package_name,
"spawn_mode": True
},
"targets": [
{
"class_name": target_class,
"methods": [".*"],
"enabled": True
}
],
"global_rules": {
"method_logging": [".*"]
},
"custom_javascript": {}
}
# Add JavaScript scripts
for script_name, script_config in js_scripts.items():
config["custom_javascript"][script_name] = {
"description": script_config.get("description", script_name),
"enabled": script_config.get("enabled", True),
"code": self.clean_js_for_json(script_config["code"])
}
return config
def add_custom_script(self, name, description, js_code, enabled=True):
"""Add a custom JavaScript script"""
return {
name: {
"description": description,
"enabled": enabled,
"code": self.clean_js_for_json(js_code)
}
}
def generate_ssl_bypass_config(self, package_name):
"""Generate a config specifically for SSL bypass"""
config = {
"app": {
"package_name": package_name,
"spawn_mode": True
},
"targets": [], # No specific method hooks needed
"global_rules": {},
"custom_javascript": {
"ssl_pinning_bypass": {
"description": "Comprehensive SSL Pinning Bypass",
"enabled": True,
"code": self.clean_js_for_json("""
Java.perform(function() {
// TrustManager bypass
var X509TrustManager = Java.use('javax.net.ssl.X509TrustManager');
var SSLContext = Java.use('javax.net.ssl.SSLContext');
var TrustManager = Java.registerClass({
name: 'com.frida.TrustManager',
implements: [X509TrustManager],
methods: {
checkClientTrusted: function(chain, authType) {},
checkServerTrusted: function(chain, authType) {},
getAcceptedIssuers: function() { return []; }
}
});
// HttpsURLConnection bypass
var HttpsURLConnection = Java.use('javax.net.ssl.HttpsURLConnection');
HttpsURLConnection.setDefaultHostnameVerifier.implementation = function(hostnameVerifier) {
console.log('[+] Bypassing HttpsURLConnection hostname verification');
};
// OkHttp bypass
try {
var OkHttpClient = Java.use('okhttp3.OkHttpClient');
var CertificatePinner = Java.use('okhttp3.CertificatePinner');
CertificatePinner.check.overload('java.lang.String', 'java.util.List').implementation = function(hostname, peerCertificates) {
console.log('[+] Bypassing OkHttp certificate pinning for: ' + hostname);
return;
};
} catch (e) {}
console.log('[+] SSL Pinning bypass loaded');
});
""")
}
}
}
return config
def save_config(self, config, filename):
"""Save configuration to JSON file"""
with open(filename, 'w') as f:
json.dump(config, f, indent=2)
print(f"[+] Configuration saved to {filename}")
def main():
if len(sys.argv) < 2:
print("JavaScript to JSON Configuration Converter")
print("=" * 50)
print("Usage:")
print(f" {sys.argv[0]} ssl-bypass <package_name>")
print(f" {sys.argv[0]} custom <package_name> <class_name>")
print(f" {sys.argv[0]} list")
print()
print("Examples:")
print(f" {sys.argv[0]} ssl-bypass com.banking.app")
print(f" {sys.argv[0]} custom com.app com.app.SecurityManager")
print(f" {sys.argv[0]} list")
sys.exit(1)
converter = JSToJSONConverter()
command = sys.argv[1]
if command == "list":
print("Available built-in scripts:")
print("=" * 30)
for name, script in converter.common_scripts.items():
print(f"📜 {name}")
print(f" Description: {script['description']}")
print()
elif command == "ssl-bypass":
if len(sys.argv) < 3:
print("[-] Please specify package name")
sys.exit(1)
package_name = sys.argv[2]
config = converter.generate_ssl_bypass_config(package_name)
filename = f"ssl_bypass_{package_name.replace('.', '_')}.json"
converter.save_config(config, filename)
print(f"✅ SSL bypass configuration created!")
print(f"📁 File: {filename}")
print(f"🚀 Run with: python frida_config.py run {filename}")
elif command == "custom":
if len(sys.argv) < 4:
print("[-] Please specify package name and class name")
sys.exit(1)
package_name = sys.argv[2]
target_class = sys.argv[3]
# Interactive script selection
print("Select scripts to include:")
print("=" * 30)
selected_scripts = {}
for i, (name, script) in enumerate(converter.common_scripts.items(), 1):
print(f"{i}. {name} - {script['description']}")
choice = input(f" Include? (y/n): ").strip().lower()
if choice == 'y':
selected_scripts[name] = script
# Ask for custom JavaScript
print("\nAdd custom JavaScript code? (y/n): ", end="")
if input().strip().lower() == 'y':
custom_name = input("Script name: ")
custom_desc = input("Description: ")
print("Enter JavaScript code (end with '###' on a new line):")
custom_code_lines = []
while True:
line = input()
if line.strip() == '###':
break
custom_code_lines.append(line)
custom_code = '\n'.join(custom_code_lines)
selected_scripts[custom_name] = {
"description": custom_desc,
"code": custom_code
}
# Create configuration
config = converter.create_config_with_js(package_name, target_class, selected_scripts)
filename = f"custom_{package_name.replace('.', '_')}.json"
converter.save_config(config, filename)
print(f"✅ Custom configuration created!")
print(f"📁 File: {filename}")
print(f"🚀 Run with: python frida_config.py run {filename}")
else:
print(f"[-] Unknown command: {command}")
sys.exit(1)