Skip to content

Commit 2ad47d3

Browse files
committed
feat: allow the user to display DroidGround's IP address in the UI
1 parent a04aa4f commit 2ad47d3

File tree

5 files changed

+37
-5
lines changed

5 files changed

+37
-5
lines changed

.env.sample

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ DROIDGROUND_TERMINAL_DISABLED=false # Feature enabled by default if not set othe
2323
DROIDGROUND_RESET_DISABLED=false # Feature enabled by default if not set otherwise
2424
DROIDGROUND_EXPLOIT_APP_DURATION=10 # The time (in seconds) the exploit app will be active before the target app is restarted. This field makes sense only if the App Manager is enabled. Default value is 10
2525
DROIDGROUND_NUM_TEAMS=0 # Number of teams playing, this enables the usage of team-based tokens/keys to lock down the usage of installed apps and log servers
26-
DROIDGROUND_TEAM_TOKEN_1=RANDOMSTRING # Token for team #1, this only makes sense if DROIDGROUND_NUM_TEAMS is higher than 0. If a team token is not explicitly defined it'll be randomly generated on boot and present in the output logs
26+
DROIDGROUND_TEAM_TOKEN_1=RANDOMSTRING # Token for team #1, this only makes sense if DROIDGROUND_NUM_TEAMS is higher than 0. If a team token is not explicitly defined it'll be randomly generated on boot and present in the output logs
27+
DROIDGROUND_IP_IFACE=eth0 # If this is set the UI will display the IP address associated with it. Useful to provide to the users the IP of the exploit server if dynamic. Empty by default

src/client/views/ExploitServer.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,16 @@ export const ExploitServer: React.FC = () => {
5757

5858
return (
5959
<div className="w-full flex flex-col gap-2">
60-
<div className="flex gap-2 items-center mb-2">
61-
<BiSolidServer size={32} />
62-
<h1 className="text-2xl font-semibold select-none">Exploit Server</h1>
60+
<div className="flex items-center justify-between mb-2">
61+
<div className="flex items-center gap-2">
62+
<BiSolidServer size={32} />
63+
<h1 className="text-2xl font-semibold select-none">Exploit Server</h1>
64+
</div>
65+
{featuresConfig.ipAddress.length > 0 && (
66+
<span className="indicator-item badge badge-primary">
67+
<b>IP Address:</b> <code>{featuresConfig.ipAddress}</code>
68+
</span>
69+
)}
6370
</div>
6471
<div className="card bg-base-300 border border-base-300">
6572
<div className="card-body p-4">

src/server/manager.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { AppStatus, WebsocketClient } from "@server/utils/types";
1515
import { setupFrida } from "@server/utils/frida";
1616
import { setupScrcpy } from "@server/utils/scrcpy";
1717
import { AdbScrcpyClient } from "@yume-chan/adb-scrcpy";
18-
import { safeFileExists } from "@server/utils/helpers";
18+
import { getIP, safeFileExists } from "@server/utils/helpers";
1919

2020
export class ManagerSingleton {
2121
private static instance: ManagerSingleton;
@@ -45,6 +45,9 @@ export class ManagerSingleton {
4545
// private constructor prevents direct instantiation
4646
const port: any = process.env.DROIDGROUND_ADB_PORT ?? "";
4747
const exploitAppDuration: any = process.env.DROIDGROUND_EXPLOIT_APP_DURATION ?? "";
48+
// Check if IP address should be displayed
49+
const iface = process.env.DROIDGROUND_IP_IFACE ?? "";
50+
const ipAddress = getIP(iface); // Either an empty string or the IP address
4851
// Check team-mode
4952
const teamNumEnv: any = process.env.DROIDGROUND_NUM_TEAMS ?? "";
5053
const teamNum = isNaN(teamNumEnv) || teamNumEnv.trim().length === 0 ? 0 : teamNumEnv;
@@ -74,6 +77,7 @@ export class ManagerSingleton {
7477
fridaType: process.env.DROIDGROUND_FRIDA_TYPE === "full" ? "full" : "jail",
7578
exploitAppDuration:
7679
isNaN(exploitAppDuration) || exploitAppDuration.trim().length === 0 ? 10 : parseInt(exploitAppDuration),
80+
ipAddress: ipAddress,
7781
},
7882
teams: teams,
7983
debugToken: crypto.randomBytes(64).toString("hex"),

src/server/utils/helpers.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Package imports
22
import * as fs from "fs";
3+
import { NetworkInterfaceInfo, networkInterfaces } from "os";
34
import { LsEntry } from "@server/utils/types";
45
import { fileURLToPath } from "url";
56
import path, { dirname } from "path";
@@ -164,3 +165,21 @@ export const buildExtra = (extra: IntentExtra): string[] => {
164165
export const shellEscape = (value: string): string => {
165166
return `'${value.replace(/'/g, `'\\''`)}'`;
166167
};
168+
169+
export const getIP = (name: string) => {
170+
// Return an empty string by default
171+
let ipAddress = "";
172+
173+
const interfaces = networkInterfaces();
174+
if (!Object.keys(interfaces).includes(name)) {
175+
return ipAddress;
176+
}
177+
178+
const iface = (interfaces[name] as NetworkInterfaceInfo[]).find(i => i.family === "IPv4");
179+
180+
if (!iface || iface.internal) {
181+
return ipAddress;
182+
}
183+
184+
return iface.address;
185+
};

src/shared/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export interface DroidGroundFeatures {
1818
teamModeEnabled: boolean;
1919
fridaType: "full" | "jail";
2020
exploitAppDuration: number;
21+
ipAddress: string;
2122
}
2223

2324
export interface DroidGroundTeam {

0 commit comments

Comments
 (0)