Skip to content

Commit 2c9457b

Browse files
committed
Test emulator host IPs for connectivity too in Android Frida setup
1 parent 5312c99 commit 2c9457b

File tree

4 files changed

+24
-9
lines changed

4 files changed

+24
-9
lines changed

src/interceptors/android/adb-commands.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ import { streamToBuffer } from '../../util/stream';
1010
export const ANDROID_TEMP = '/data/local/tmp';
1111
export const SYSTEM_CA_PATH = '/system/etc/security/cacerts';
1212

13+
export const EMULATOR_HOST_IPS = [
14+
'10.0.2.2', // Standard emulator localhost ip
15+
'10.0.3.2', // Genymotion localhost ip
16+
];
17+
1318
export function createAdbClient() {
1419
const client = adb.createClient({
1520
port: process.env['ANDROID_ADB_SERVER_PORT']

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ import {
2121
setChromeFlags,
2222
startActivity,
2323
createPersistentReverseTunnel,
24-
closeReverseTunnel
24+
closeReverseTunnel,
25+
EMULATOR_HOST_IPS
2526
} from './adb-commands';
2627
import { streamLatestApk, clearAllApks } from './fetch-apk';
2728
import { parseCert, getCertificateFingerprint, getCertificateSubjectHash } from '../../certificates';
@@ -95,10 +96,7 @@ export class AndroidAdbInterceptor implements Interceptor {
9596

9697
// Build a trigger URL to activate the proxy on the device:
9798
const setupParams = {
98-
addresses: [
99-
'10.0.2.2', // Standard emulator localhost ip
100-
'10.0.3.2', // Genymotion localhost ip
101-
].concat(
99+
addresses: EMULATOR_HOST_IPS.concat(
102100
// Every other external network ip
103101
getReachableInterfaces().filter(a =>
104102
a.family === "IPv4" // Android VPN app supports IPv4 only

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import { Client as AdbClient, DeviceClient } from '@devicefarmer/adbkit';
22
import * as FridaJs from 'frida-js';
33

4-
import { createPersistentReverseTunnel, getConnectedDevices, getRootCommand, isProbablyRooted } from '../android/adb-commands';
4+
import {
5+
EMULATOR_HOST_IPS,
6+
createPersistentReverseTunnel,
7+
getConnectedDevices,
8+
getRootCommand,
9+
isProbablyRooted
10+
} from '../android/adb-commands';
511
import { waitUntil } from '../../util/promise';
612
import { buildAndroidFridaScript } from './frida-scripts';
713
import {
@@ -186,7 +192,10 @@ export async function interceptAndroidFridaTarget(
186192
const proxyIp = await testAndSelectProxyAddress(session, proxyPort, {
187193
// Localhost here is local to the device - it's the reverse tunnel
188194
// over ADB, which is generally more robust than wifi etc
189-
includeLocalhost: true
195+
extraAddresses: [
196+
'127.0.0.1',
197+
...EMULATOR_HOST_IPS,
198+
]
190199
});
191200

192201
const interceptionScript = await buildAndroidFridaScript(

src/interceptors/frida/frida-integration.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,14 @@ export const FRIDA_BINARY_NAME = `adirf-server`; // Reversed to mildly inconveni
3737
export async function testAndSelectProxyAddress(
3838
session: FridaJs.FridaAgentSession,
3939
proxyPort: number,
40-
options: { includeLocalhost?: boolean } = {}
40+
options: { extraAddresses?: string[] } = {}
4141
): Promise<string> {
4242
const interfaceAddresses = getReachableInterfaces();
4343
const ips = interfaceAddresses.map(a => a.address);
44-
if (options.includeLocalhost) ips.push('127.0.0.1');
44+
45+
if (options.extraAddresses?.length) {
46+
ips.push(...options.extraAddresses);
47+
}
4548

4649
if (ips.length === 0) throw new ErrorWithCode('unreachable-proxy', "Couldn't detect proxy external IP");
4750

0 commit comments

Comments
 (0)