-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforce_use_proxy.js
77 lines (64 loc) · 3.1 KB
/
force_use_proxy.js
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
// Hardcoded proxy configuration
const PROXY_HOST = '127.0.0.1'; // Proxy server address
const PROXY_PORT = 8080; // Proxy server port
Java.perform(() => {
// Set default JVM system properties for proxy settings
const System = Java.use('java.lang.System');
System.setProperty('http.proxyHost', PROXY_HOST);
System.setProperty('http.proxyPort', PROXY_PORT.toString());
System.setProperty('https.proxyHost', PROXY_HOST);
System.setProperty('https.proxyPort', PROXY_PORT.toString());
// Clear non-proxy hosts
System.clearProperty('http.nonProxyHosts');
System.clearProperty('https.nonProxyHosts');
// Prevent reset of proxy properties by Android internals
const controlledProperties = [
'http.proxyHost',
'http.proxyPort',
'https.proxyHost',
'https.proxyPort',
'http.nonProxyHosts',
'https.nonProxyHosts'
];
System.clearProperty.implementation = function (property) {
if (controlledProperties.includes(property)) {
console.log(`[*] Ignored attempt to clear ${property}`);
return this.getProperty(property);
}
return this.clearProperty(...arguments);
};
System.setProperty.implementation = function (property) {
if (controlledProperties.includes(property)) {
console.log(`[*] Ignored attempt to override ${property}`);
return this.getProperty(property);
}
return this.setProperty(...arguments);
};
// Configure app's proxy directly using ConnectivityManager
const ConnectivityManager = Java.use('android.net.ConnectivityManager');
const ProxyInfo = Java.use('android.net.ProxyInfo');
ConnectivityManager.getDefaultProxy.implementation = () => ProxyInfo.$new(PROXY_HOST, PROXY_PORT, '');
console.log(`== [*] Proxy system configuration set to ${PROXY_HOST}:${PROXY_PORT} ==`);
// Override ProxySelector to ensure all traffic goes through our proxy
const Collections = Java.use('java.util.Collections');
const ProxyType = Java.use('java.net.Proxy$Type');
const InetSocketAddress = Java.use('java.net.InetSocketAddress');
const ProxyCls = Java.use('java.net.Proxy');
const targetProxy = ProxyCls.$new(
ProxyType.HTTP.value,
InetSocketAddress.$new(PROXY_HOST, PROXY_PORT)
);
const getTargetProxyList = () => Collections.singletonList(targetProxy);
const ProxySelector = Java.use('java.net.ProxySelector');
// Scan for ProxySelector implementations and override them
const proxySelectorClasses = Java.enumerateMethods('*!select(java.net.URI): java.util.List/s')
.flatMap((matchingLoader) => matchingLoader.classes
.map((classData) => Java.use(classData.name))
.filter((Cls) => ProxySelector.class.isAssignableFrom(Cls.class))
);
proxySelectorClasses.forEach(ProxySelectorCls => {
ProxySelectorCls.select.implementation = () => getTargetProxyList();
console.log(`[*] Overrode ProxySelector in ${ProxySelectorCls}`);
});
console.log(`== Proxy configuration successfully set to ${PROXY_HOST}:${PROXY_PORT} ==`);
});