Skip to content

Commit dbf2a41

Browse files
committed
Add support for skipping known-problematic ports in Frida native capture
This only affects Frida's native connect hook, which forcibly captures traffic that ignores the proxy server. In most cases that's fine and important (e.g. for Flutter apps) but in certain scenarios where the traffic is completely non-HTTP it can cause problems. We could make this configurable later, but for now we just track a few high profile cases.
1 parent ff1e15e commit dbf2a41

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

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

+8-1
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,12 @@ export async function getAndroidFridaTargets(adbClient: AdbClient, hostId: strin
195195
return apps;
196196
}
197197

198+
// Various ports which we know that certain apps use for non-HTTP traffic that we
199+
// can't currently intercept, so we avoid capturing for now.
200+
const KNOWN_APP_PROBLEMATIC_PORTS: Record<string, number[] | undefined> = {
201+
'com.spotify.music': [4070]
202+
};
203+
198204
export async function interceptAndroidFridaTarget(
199205
adbClient: AdbClient,
200206
hostId: string,
@@ -229,7 +235,8 @@ export async function interceptAndroidFridaTarget(
229235
const interceptionScript = await buildAndroidFridaScript(
230236
caCertContent,
231237
proxyIp,
232-
proxyPort
238+
proxyPort,
239+
KNOWN_APP_PROBLEMATIC_PORTS[appId] ?? []
233240
);
234241

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

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

+8-1
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ export async function getIosFridaTargets(usbmuxClient: UsbmuxClient, hostId: str
115115
return apps;
116116
}
117117

118+
// Various ports which we know that certain apps use for non-HTTP traffic that we
119+
// can't currently intercept, so we avoid capturing for now.
120+
const KNOWN_APP_PROBLEMATIC_PORTS: Record<string, number[] | undefined> = {
121+
'com.spotify.client': [4070]
122+
};
123+
118124
export async function interceptIosFridaTarget(
119125
usbmuxClient: UsbmuxClient,
120126
hostId: string,
@@ -138,7 +144,8 @@ export async function interceptIosFridaTarget(
138144
const interceptionScript = await buildIosFridaScript(
139145
caCertContent,
140146
proxyIp,
141-
proxyPort
147+
proxyPort,
148+
KNOWN_APP_PROBLEMATIC_PORTS[appId] ?? []
142149
);
143150

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

src/interceptors/frida/frida-scripts.ts

+10-6
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,26 @@ function buildFridaConfig(
99
configScriptTemplate: string,
1010
caCertContent: string,
1111
proxyHost: string,
12-
proxyPort: number
12+
proxyPort: number,
13+
portsToIgnore: number[]
1314
) {
1415
return configScriptTemplate
1516
.replace(/(?<=const CERT_PEM = `)[^`]+(?=`)/s, caCertContent.trim())
1617
.replace(/(?<=const PROXY_HOST = ')[^']+(?=')/, proxyHost)
17-
.replace(/(?<=const PROXY_PORT = )\d+(?=;)/, proxyPort.toString());
18+
.replace(/(?<=const PROXY_PORT = )\d+(?=;)/, proxyPort.toString())
19+
.replace(/(?<=const IGNORED_NON_HTTP_PORTS = )\[\s*\](?=;)/s, JSON.stringify(portsToIgnore));
1820
}
1921

2022
export async function buildAndroidFridaScript(
2123
caCertContent: string,
2224
proxyHost: string,
23-
proxyPort: number
25+
proxyPort: number,
26+
portsToIgnore: number[]
2427
) {
2528
const scripts = await Promise.all([
2629
fs.readFile(path.join(FRIDA_SCRIPTS_ROOT, 'config.js'), { encoding: 'utf8' })
2730
.then((configTemplate) =>
28-
buildFridaConfig(configTemplate, caCertContent, proxyHost, proxyPort)
31+
buildFridaConfig(configTemplate, caCertContent, proxyHost, proxyPort, portsToIgnore)
2932
),
3033
...[
3134
['native-connect-hook.js'],
@@ -45,12 +48,13 @@ export async function buildAndroidFridaScript(
4548
export async function buildIosFridaScript(
4649
caCertContent: string,
4750
proxyHost: string,
48-
proxyPort: number
51+
proxyPort: number,
52+
portsToIgnore: number[]
4953
) {
5054
const scripts = await Promise.all([
5155
fs.readFile(path.join(FRIDA_SCRIPTS_ROOT, 'config.js'), { encoding: 'utf8' })
5256
.then((configTemplate) =>
53-
buildFridaConfig(configTemplate, caCertContent, proxyHost, proxyPort)
57+
buildFridaConfig(configTemplate, caCertContent, proxyHost, proxyPort, portsToIgnore)
5458
),
5559
...[
5660
['ios', 'ios-connect-hook.js'],

0 commit comments

Comments
 (0)