Skip to content

Commit ae16ec2

Browse files
committed
Expose SOCKS option for Frida script interception
1 parent 892b13d commit ae16ec2

File tree

5 files changed

+23
-13
lines changed

5 files changed

+23
-13
lines changed

src/interceptors/frida/frida-android-integration.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,8 @@ export async function interceptAndroidFridaTarget(
230230
hostId: string,
231231
appId: string,
232232
caCertContent: string,
233-
proxyPort: number
233+
proxyPort: number,
234+
enableSocks: boolean
234235
) {
235236
console.log(`Intercepting ${appId} via Android Frida on ${hostId}...`);
236237
const deviceClient = adbClient.getDevice(hostId);
@@ -260,7 +261,8 @@ export async function interceptAndroidFridaTarget(
260261
caCertContent,
261262
proxyIp,
262263
proxyPort,
263-
KNOWN_APP_PROBLEMATIC_PORTS[appId] ?? []
264+
KNOWN_APP_PROBLEMATIC_PORTS[appId] ?? [],
265+
enableSocks
264266
);
265267

266268
await launchScript(`Android (${appId})`, session, interceptionScript);

src/interceptors/frida/frida-android-interceptor.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export class FridaAndroidInterceptor implements Interceptor {
5858
options:
5959
| { action: 'setup', hostId: string }
6060
| { action: 'launch', hostId: string }
61-
| { action: 'intercept', hostId: string, targetId: string }
61+
| { action: 'intercept', hostId: string, targetId: string, enableSocks?: boolean }
6262
): Promise<void> {
6363
if (options.action === 'setup') {
6464
await setupAndroidHost(this.config, this.adbClient, options.hostId);
@@ -77,7 +77,8 @@ export class FridaAndroidInterceptor implements Interceptor {
7777
options.hostId,
7878
options.targetId,
7979
this.config.https.certContent,
80-
proxyPort
80+
proxyPort,
81+
options.enableSocks ?? false
8182
);
8283

8384
// Track this session, so we can close it to stop the interception later

src/interceptors/frida/frida-ios-integration.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ export async function interceptIosFridaTarget(
152152
hostId: string,
153153
appId: string,
154154
caCertContent: string,
155-
proxyPort: number
155+
proxyPort: number,
156+
enableSocks: boolean
156157
) {
157158
console.log(`Intercepting ${appId} via iOS Frida on ${hostId}...`);
158159
const deviceId = await getDeviceId(usbmuxClient, hostId);
@@ -171,7 +172,8 @@ export async function interceptIosFridaTarget(
171172
caCertContent,
172173
proxyIp,
173174
proxyPort,
174-
KNOWN_APP_PROBLEMATIC_PORTS[appId] ?? []
175+
KNOWN_APP_PROBLEMATIC_PORTS[appId] ?? [],
176+
enableSocks
175177
);
176178

177179
await launchScript(`iOS (${appId})`, session, interceptionScript);

src/interceptors/frida/frida-ios-interceptor.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,16 @@ export class FridaIosInterceptor implements Interceptor {
5252
async activate(
5353
proxyPort: number,
5454
options:
55-
| { action: 'intercept', hostId: string, targetId: string }
55+
| { action: 'intercept', hostId: string, targetId: string, enableSocks?: boolean }
5656
): Promise<void> {
5757
if (options.action === 'intercept') {
5858
const fridaSession = await interceptIosFridaTarget(
5959
this.usbmuxClient,
6060
options.hostId,
6161
options.targetId,
6262
this.config.https.certContent,
63-
proxyPort
63+
proxyPort,
64+
options.enableSocks ?? false
6465
);
6566

6667
// Track this session, so we can close it to stop the interception later

src/interceptors/frida/frida-scripts.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,29 @@ function buildFridaConfig(
1010
caCertContent: string,
1111
proxyHost: string,
1212
proxyPort: number,
13-
portsToIgnore: number[]
13+
portsToIgnore: number[],
14+
enableSocks: boolean
1415
) {
1516
return configScriptTemplate
1617
.replace(/(?<=const CERT_PEM = `)[^`]+(?=`)/s, caCertContent.trim())
1718
.replace(/(?<=const PROXY_HOST = ')[^']+(?=')/, proxyHost)
1819
.replace(/(?<=const PROXY_PORT = )\d+(?=;)/, proxyPort.toString())
20+
.replace(/(?<=const PROXY_SUPPORTS_SOCKS5 = )false(?=;)/, enableSocks.toString())
1921
.replace(/(?<=const IGNORED_NON_HTTP_PORTS = )\[\s*\](?=;)/s, JSON.stringify(portsToIgnore));
2022
}
2123

2224
export async function buildAndroidFridaScript(
2325
caCertContent: string,
2426
proxyHost: string,
2527
proxyPort: number,
26-
portsToIgnore: number[]
28+
portsToIgnore: number[],
29+
enableSocks: boolean
2730
) {
2831
const scripts = await Promise.all([
2932
fs.readFile(path.join(FRIDA_SCRIPTS_ROOT, 'frida-java-bridge.js'), { encoding: 'utf8' }),
3033
fs.readFile(path.join(FRIDA_SCRIPTS_ROOT, 'config.js'), { encoding: 'utf8' })
3134
.then((configTemplate) =>
32-
buildFridaConfig(configTemplate, caCertContent, proxyHost, proxyPort, portsToIgnore)
35+
buildFridaConfig(configTemplate, caCertContent, proxyHost, proxyPort, portsToIgnore, enableSocks)
3336
),
3437
...[
3538
['native-connect-hook.js'],
@@ -52,13 +55,14 @@ export async function buildIosFridaScript(
5255
caCertContent: string,
5356
proxyHost: string,
5457
proxyPort: number,
55-
portsToIgnore: number[]
58+
portsToIgnore: number[],
59+
enableSocks: boolean
5660
) {
5761
const scripts = await Promise.all([
5862
fs.readFile(path.join(FRIDA_SCRIPTS_ROOT, 'frida-objc-bridge.js'), { encoding: 'utf8' }),
5963
fs.readFile(path.join(FRIDA_SCRIPTS_ROOT, 'config.js'), { encoding: 'utf8' })
6064
.then((configTemplate) =>
61-
buildFridaConfig(configTemplate, caCertContent, proxyHost, proxyPort, portsToIgnore)
65+
buildFridaConfig(configTemplate, caCertContent, proxyHost, proxyPort, portsToIgnore, enableSocks)
6266
),
6367
...[
6468
['ios', 'ios-connect-hook.js'],

0 commit comments

Comments
 (0)