netlane 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- netlane-0.1.0/PKG-INFO +248 -0
- netlane-0.1.0/README.md +238 -0
- netlane-0.1.0/pyproject.toml +55 -0
- netlane-0.1.0/pyproject.toml.orig +45 -0
- netlane-0.1.0/src/netlane/__init__.py +3 -0
- netlane-0.1.0/src/netlane/__main__.py +3 -0
- netlane-0.1.0/src/netlane/adb.py +67 -0
- netlane-0.1.0/src/netlane/cli.py +182 -0
- netlane-0.1.0/src/netlane/config.py +394 -0
- netlane-0.1.0/src/netlane/modes/__init__.py +0 -0
- netlane-0.1.0/src/netlane/modes/adb_reverse.py +229 -0
- netlane-0.1.0/src/netlane/modes/interface.py +34 -0
- netlane-0.1.0/src/netlane/modes/wireguard_ssh_reverse.py +335 -0
- netlane-0.1.0/src/netlane/remote.py +85 -0
- netlane-0.1.0/src/netlane/rulesets/__init__.py +0 -0
- netlane-0.1.0/src/netlane/rulesets/iptables.py +181 -0
- netlane-0.1.0/src/netlane/rulesets/nftables.py +194 -0
- netlane-0.1.0/src/netlane/scripts/ubuntu/install.sh +73 -0
- netlane-0.1.0/src/netlane/utils.py +157 -0
netlane-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: netlane
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Intercept mobile app traffic via WireGuard and forward it to tools such as Burp Suite
|
|
5
|
+
Author: Benjamin Faller
|
|
6
|
+
Author-email: Benjamin Faller <benjamin.faller@redguard.ch>
|
|
7
|
+
Requires-Dist: qrcode>=8.2
|
|
8
|
+
Requires-Python: >=3.12
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
|
|
11
|
+
# netlane
|
|
12
|
+
|
|
13
|
+
[](https://github.com/Redguard/netlane/actions/workflows/ci.yml?query=branch%3Amain)
|
|
14
|
+
[](https://github.com/Redguard/netlane/actions/workflows/ci.yml?query=branch%3Amain)
|
|
15
|
+
|
|
16
|
+
netlane routes mobile device traffic during security analysis.
|
|
17
|
+
Rules decide per connection whether traffic is forwarded to a local tool such as Burp Suite, passed through to the internet, or dropped/rejected.
|
|
18
|
+
The idea behind this is to simplify traditional error-prone network interception setups encompassing VPNs, firewall rules and tunnels with a config file for most test scenarios.
|
|
19
|
+
|
|
20
|
+
It supports two modes:
|
|
21
|
+
|
|
22
|
+
1. **WireGuard SSH Reverse Tunneling (`wireguard_ssh_reverse`)**: Dual-stack (IPv4/IPv6) using a remote VPS.
|
|
23
|
+
2. **ADB Reverse Tunneling (`adb_reverse`)**: Dual-stack (IPv4/IPv6) interception on rooted devices via iptables and `adb reverse`.
|
|
24
|
+
|
|
25
|
+
## Architecture
|
|
26
|
+
|
|
27
|
+
### WireGuard SSH Reverse Tunneling
|
|
28
|
+
|
|
29
|
+
```mermaid
|
|
30
|
+
flowchart
|
|
31
|
+
Internet@{ shape: cloud }
|
|
32
|
+
|
|
33
|
+
subgraph Device
|
|
34
|
+
App1[Target App]
|
|
35
|
+
WG[WireGuard App]
|
|
36
|
+
OS
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
subgraph External Server
|
|
40
|
+
Server[WireGuard Server]
|
|
41
|
+
sshd
|
|
42
|
+
Reject@{ shape: rounded }
|
|
43
|
+
Drop@{ shape: rounded }
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
subgraph Host_Machine [Laptop]
|
|
47
|
+
ssh[SSH Client]
|
|
48
|
+
MitM
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
App1 --> OS
|
|
52
|
+
OS -->|Selective Interception| WG
|
|
53
|
+
WG -->|Tunnel| OS
|
|
54
|
+
|
|
55
|
+
OS -->|Other App Traffic| Internet
|
|
56
|
+
OS -->|Tunnel| Server
|
|
57
|
+
|
|
58
|
+
Server -->|DNAT to tcp:8080| sshd
|
|
59
|
+
Server -->|e.g. udp/443| Reject
|
|
60
|
+
Server -->|e.g. tcp/8080| Drop
|
|
61
|
+
|
|
62
|
+
Server -->|Passthrough| Internet
|
|
63
|
+
sshd -->|SSH Reverse Tunnel| ssh
|
|
64
|
+
|
|
65
|
+
ssh -- "tcp:8080" --> MitM
|
|
66
|
+
MitM --> Internet
|
|
67
|
+
|
|
68
|
+
style WG fill:#ff4d4d,stroke:#b30000,stroke-width:3px,color:#ffffff
|
|
69
|
+
style Server fill:#2d7dd2,stroke:#1a5a9e,stroke-width:2px,color:#ffffff
|
|
70
|
+
style Drop fill:#444444,stroke:#222222,color:#ffffff
|
|
71
|
+
style Reject fill:#444444,stroke:#222222,color:#ffffff
|
|
72
|
+
style sshd fill:#444444,stroke:#222222,color:#ffffff
|
|
73
|
+
style ssh fill:#444444,stroke:#222222,color:#ffffff
|
|
74
|
+
style MitM fill:#ff4d4d,stroke:#b30000,stroke-width:3px,color:#ffffff
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
```mermaid
|
|
78
|
+
sequenceDiagram
|
|
79
|
+
box Mobile Device
|
|
80
|
+
participant App as Mobile App
|
|
81
|
+
participant Client as WireGuard Client
|
|
82
|
+
end
|
|
83
|
+
box Server / Gateway (VPS)
|
|
84
|
+
participant GW as WireGuard Server
|
|
85
|
+
participant SSH_Tunnel as SSH Tunnel Listener
|
|
86
|
+
end
|
|
87
|
+
box Local Tester Device
|
|
88
|
+
participant Burp as Burp Suite (Local)
|
|
89
|
+
end
|
|
90
|
+
participant Internet as Internet
|
|
91
|
+
|
|
92
|
+
App->>Client: Routed Traffic
|
|
93
|
+
Client-->>()GW: Encrypted WireGuard Tunnel (UDP 51820)
|
|
94
|
+
alt Matching Rule (tunnel:<name>)
|
|
95
|
+
GW->>SSH_Tunnel: nftables DNAT to tcp:8080
|
|
96
|
+
SSH_Tunnel()-->>Burp: Encrypted Tunnel
|
|
97
|
+
Burp->>Internet: HTTP(S) Request Traffic
|
|
98
|
+
else Passthrough Route
|
|
99
|
+
GW->>Internet: nftables MASQUERADE
|
|
100
|
+
else Reject / Drop
|
|
101
|
+
GW--xGW: Blocked
|
|
102
|
+
end
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### ADB Reverse Tunneling
|
|
106
|
+
|
|
107
|
+
```mermaid
|
|
108
|
+
flowchart TD
|
|
109
|
+
subgraph Device
|
|
110
|
+
App1[Target App] --> OS
|
|
111
|
+
Reject@{ shape: rounded }
|
|
112
|
+
Drop@{ shape: rounded }
|
|
113
|
+
DevicePort[adbd\nlocalhost:8080]
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
subgraph Host_Machine [Laptop]
|
|
117
|
+
ADB[adb Server]
|
|
118
|
+
MitM
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
OS -->|e.g. udp/443| Reject
|
|
122
|
+
OS -->|e.g. tcp/8080| Drop
|
|
123
|
+
OS -->|DNAT to tcp:8080| DevicePort
|
|
124
|
+
OS -->|Passthrough| Internet
|
|
125
|
+
|
|
126
|
+
DevicePort -- adb reverse Tunnel --> ADB
|
|
127
|
+
ADB -- "tcp:8080" --> MitM
|
|
128
|
+
|
|
129
|
+
MitM --> Internet
|
|
130
|
+
|
|
131
|
+
Internet@{ shape: cloud }
|
|
132
|
+
|
|
133
|
+
style MitM fill:#ff4d4d,stroke:#b30000,stroke-width:3px,color:#ffffff
|
|
134
|
+
style Drop fill:#444444,stroke:#222222,color:#ffffff
|
|
135
|
+
style Reject fill:#444444,stroke:#222222,color:#ffffff
|
|
136
|
+
style DevicePort fill:#444444,stroke:#222222,color:#ffffff
|
|
137
|
+
style ADB fill:#444444,stroke:#222222,color:#ffffff
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Setup
|
|
141
|
+
|
|
142
|
+
Install the `netlane` command with [uv](https://docs.astral.sh/uv/):
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
uv tool install .
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Requirements per mode:
|
|
149
|
+
|
|
150
|
+
- `wireguard_ssh_reverse`: `ssh`, `scp` and WireGuard tools (`wg`) locally, a dedicated Ubuntu VPS with root access and the WireGuard app on the device.
|
|
151
|
+
- `adb_reverse`: `adb` locally and a rooted device or emulator.
|
|
152
|
+
|
|
153
|
+
## Configuration
|
|
154
|
+
|
|
155
|
+
Profiles and interception rules are configured in `config.toml` in the platform's config directory:
|
|
156
|
+
|
|
157
|
+
| Platform | Path |
|
|
158
|
+
|---|---|
|
|
159
|
+
| Linux | `$XDG_CONFIG_HOME/netlane/config.toml` (default `~/.config/netlane/config.toml`) |
|
|
160
|
+
| macOS | `~/Library/Application Support/netlane/config.toml` |
|
|
161
|
+
| Windows | `%APPDATA%\netlane\config\config.toml` |
|
|
162
|
+
|
|
163
|
+
Use `config.toml` from this repository as a starting point, e.g. on Linux:
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
mkdir -p ~/.config/netlane
|
|
167
|
+
cp config.toml ~/.config/netlane/config.toml
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
Each profile has a `mode`, `mode_opts`, `rules` and optional `hooks`:
|
|
171
|
+
|
|
172
|
+
| Key | Description |
|
|
173
|
+
|---|---|
|
|
174
|
+
| `mode_opts.tunnels` | Tunnel names mapped to local ports, e.g. `{ proxy = 8080 }`. |
|
|
175
|
+
| `mode_opts.elevation` | How to become root on the VPS or device: `sudo`, `doas`, `su`, or `""` if already root. |
|
|
176
|
+
| `mode_opts.ssh_host`, `mode_opts.ssh_user` | SSH login of the VPS (`wireguard_ssh_reverse`). |
|
|
177
|
+
| `mode_opts.serial` | Device serial from `adb devices`, optional with a single device (`adb_reverse`). |
|
|
178
|
+
| `hooks` | Shell commands run as root on the VPS or device: `pre_up`, `post_up`, `pre_down`, `post_down`. |
|
|
179
|
+
|
|
180
|
+
Rules are evaluated from top-to-bottom.
|
|
181
|
+
The first matching rule wins.
|
|
182
|
+
Packets matching no rule are dropped.
|
|
183
|
+
It's recommended to define a catch-all passthrough rule to let all other traffic through.
|
|
184
|
+
|
|
185
|
+
A rule matches when each of its fields matches one of the field's values. Omitted fields match everything.
|
|
186
|
+
|
|
187
|
+
| Field | Values |
|
|
188
|
+
|---|---|
|
|
189
|
+
| `name` | Required. Added as comment to the firewall rules. |
|
|
190
|
+
| `target` | Required. `action:passthrough`, `action:reject`, `action:drop` or `tunnel:<name>`. |
|
|
191
|
+
| `saddr`, `daddr` | IP addresses or networks. They restrict the rule to their address families, e.g. `["0.0.0.0/0"]` to IPv4. |
|
|
192
|
+
| `protocol` | Protocol names or numbers. |
|
|
193
|
+
| `sport`, `dport` | Ports. |
|
|
194
|
+
| `app`, `skuid` | Android package names or uids. |
|
|
195
|
+
|
|
196
|
+
## Usage
|
|
197
|
+
|
|
198
|
+
Each profile's mode defines which steps it needs. `netlane list` shows them per profile:
|
|
199
|
+
|
|
200
|
+
| Mode | Steps |
|
|
201
|
+
|---|---|
|
|
202
|
+
| `wireguard_ssh_reverse` | setup → pair → up |
|
|
203
|
+
| `adb_reverse` | up |
|
|
204
|
+
|
|
205
|
+
**setup**: One-time setup of the profile's remote server (see [`src/netlane/scripts/ubuntu/install.sh`](src/netlane/scripts/ubuntu/install.sh)). The server is assumed to be used exclusively for the interception purpose.
|
|
206
|
+
|
|
207
|
+
```bash
|
|
208
|
+
netlane setup jailed --distro ubuntu
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
**pair**: Creates the keys and shows the client config as a QR code to scan on the test device. `--save <path>` also writes the client config to disk. Existing keys are only replaced with `--force`.
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
netlane pair jailed
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
**up**: Applies the profile's interception rules and starts its tunnels until Ctrl-C.
|
|
218
|
+
|
|
219
|
+
```bash
|
|
220
|
+
netlane up jailed
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
For `adb_reverse`, `up` also exits when the device disconnects. In this case rules stay active until `down` or a reboot.
|
|
224
|
+
|
|
225
|
+
Ensure your local tool, e.g. Burp Suite, listens on `127.0.0.1` and `[::1]` on each tunnel port with invisible proxying enabled.
|
|
226
|
+
|
|
227
|
+
**down**: Cleans up if `up` was interrupted without tearing down.
|
|
228
|
+
|
|
229
|
+
Use `--config <path>` before the command to use a different config.
|
|
230
|
+
|
|
231
|
+
For debugging, `-v` before the command shows executed commands and `--log <path>` writes a JSON Lines log including debug output and the loaded config.
|
|
232
|
+
|
|
233
|
+
## Special behavior
|
|
234
|
+
|
|
235
|
+
### `wireguard_ssh_reverse`
|
|
236
|
+
|
|
237
|
+
- The client config uses `1.1.1.1` as DNS server, so the rules must let it through.
|
|
238
|
+
|
|
239
|
+
### `adb_reverse`
|
|
240
|
+
|
|
241
|
+
- Rules don't apply to traffic to the device itself, i.e. to loopback and the device's own addresses.
|
|
242
|
+
- Replies of adbd on its listen ports bypass the rules, so ADB over the network keeps working.
|
|
243
|
+
- Without IPv6 NAT on the device, tunnel rules must be restricted to IPv4 with `daddr = ["0.0.0.0/0"]`.
|
|
244
|
+
- Connections opened before `up` that match a tunnel rule are reset, so apps reconnect through the tunnel.
|
|
245
|
+
|
|
246
|
+
## Development
|
|
247
|
+
|
|
248
|
+
See [docs/development.md](docs/development.md) for the development setup and how the unit and integration tests work.
|
netlane-0.1.0/README.md
ADDED
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
# netlane
|
|
2
|
+
|
|
3
|
+
[](https://github.com/Redguard/netlane/actions/workflows/ci.yml?query=branch%3Amain)
|
|
4
|
+
[](https://github.com/Redguard/netlane/actions/workflows/ci.yml?query=branch%3Amain)
|
|
5
|
+
|
|
6
|
+
netlane routes mobile device traffic during security analysis.
|
|
7
|
+
Rules decide per connection whether traffic is forwarded to a local tool such as Burp Suite, passed through to the internet, or dropped/rejected.
|
|
8
|
+
The idea behind this is to simplify traditional error-prone network interception setups encompassing VPNs, firewall rules and tunnels with a config file for most test scenarios.
|
|
9
|
+
|
|
10
|
+
It supports two modes:
|
|
11
|
+
|
|
12
|
+
1. **WireGuard SSH Reverse Tunneling (`wireguard_ssh_reverse`)**: Dual-stack (IPv4/IPv6) using a remote VPS.
|
|
13
|
+
2. **ADB Reverse Tunneling (`adb_reverse`)**: Dual-stack (IPv4/IPv6) interception on rooted devices via iptables and `adb reverse`.
|
|
14
|
+
|
|
15
|
+
## Architecture
|
|
16
|
+
|
|
17
|
+
### WireGuard SSH Reverse Tunneling
|
|
18
|
+
|
|
19
|
+
```mermaid
|
|
20
|
+
flowchart
|
|
21
|
+
Internet@{ shape: cloud }
|
|
22
|
+
|
|
23
|
+
subgraph Device
|
|
24
|
+
App1[Target App]
|
|
25
|
+
WG[WireGuard App]
|
|
26
|
+
OS
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
subgraph External Server
|
|
30
|
+
Server[WireGuard Server]
|
|
31
|
+
sshd
|
|
32
|
+
Reject@{ shape: rounded }
|
|
33
|
+
Drop@{ shape: rounded }
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
subgraph Host_Machine [Laptop]
|
|
37
|
+
ssh[SSH Client]
|
|
38
|
+
MitM
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
App1 --> OS
|
|
42
|
+
OS -->|Selective Interception| WG
|
|
43
|
+
WG -->|Tunnel| OS
|
|
44
|
+
|
|
45
|
+
OS -->|Other App Traffic| Internet
|
|
46
|
+
OS -->|Tunnel| Server
|
|
47
|
+
|
|
48
|
+
Server -->|DNAT to tcp:8080| sshd
|
|
49
|
+
Server -->|e.g. udp/443| Reject
|
|
50
|
+
Server -->|e.g. tcp/8080| Drop
|
|
51
|
+
|
|
52
|
+
Server -->|Passthrough| Internet
|
|
53
|
+
sshd -->|SSH Reverse Tunnel| ssh
|
|
54
|
+
|
|
55
|
+
ssh -- "tcp:8080" --> MitM
|
|
56
|
+
MitM --> Internet
|
|
57
|
+
|
|
58
|
+
style WG fill:#ff4d4d,stroke:#b30000,stroke-width:3px,color:#ffffff
|
|
59
|
+
style Server fill:#2d7dd2,stroke:#1a5a9e,stroke-width:2px,color:#ffffff
|
|
60
|
+
style Drop fill:#444444,stroke:#222222,color:#ffffff
|
|
61
|
+
style Reject fill:#444444,stroke:#222222,color:#ffffff
|
|
62
|
+
style sshd fill:#444444,stroke:#222222,color:#ffffff
|
|
63
|
+
style ssh fill:#444444,stroke:#222222,color:#ffffff
|
|
64
|
+
style MitM fill:#ff4d4d,stroke:#b30000,stroke-width:3px,color:#ffffff
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
```mermaid
|
|
68
|
+
sequenceDiagram
|
|
69
|
+
box Mobile Device
|
|
70
|
+
participant App as Mobile App
|
|
71
|
+
participant Client as WireGuard Client
|
|
72
|
+
end
|
|
73
|
+
box Server / Gateway (VPS)
|
|
74
|
+
participant GW as WireGuard Server
|
|
75
|
+
participant SSH_Tunnel as SSH Tunnel Listener
|
|
76
|
+
end
|
|
77
|
+
box Local Tester Device
|
|
78
|
+
participant Burp as Burp Suite (Local)
|
|
79
|
+
end
|
|
80
|
+
participant Internet as Internet
|
|
81
|
+
|
|
82
|
+
App->>Client: Routed Traffic
|
|
83
|
+
Client-->>()GW: Encrypted WireGuard Tunnel (UDP 51820)
|
|
84
|
+
alt Matching Rule (tunnel:<name>)
|
|
85
|
+
GW->>SSH_Tunnel: nftables DNAT to tcp:8080
|
|
86
|
+
SSH_Tunnel()-->>Burp: Encrypted Tunnel
|
|
87
|
+
Burp->>Internet: HTTP(S) Request Traffic
|
|
88
|
+
else Passthrough Route
|
|
89
|
+
GW->>Internet: nftables MASQUERADE
|
|
90
|
+
else Reject / Drop
|
|
91
|
+
GW--xGW: Blocked
|
|
92
|
+
end
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### ADB Reverse Tunneling
|
|
96
|
+
|
|
97
|
+
```mermaid
|
|
98
|
+
flowchart TD
|
|
99
|
+
subgraph Device
|
|
100
|
+
App1[Target App] --> OS
|
|
101
|
+
Reject@{ shape: rounded }
|
|
102
|
+
Drop@{ shape: rounded }
|
|
103
|
+
DevicePort[adbd\nlocalhost:8080]
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
subgraph Host_Machine [Laptop]
|
|
107
|
+
ADB[adb Server]
|
|
108
|
+
MitM
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
OS -->|e.g. udp/443| Reject
|
|
112
|
+
OS -->|e.g. tcp/8080| Drop
|
|
113
|
+
OS -->|DNAT to tcp:8080| DevicePort
|
|
114
|
+
OS -->|Passthrough| Internet
|
|
115
|
+
|
|
116
|
+
DevicePort -- adb reverse Tunnel --> ADB
|
|
117
|
+
ADB -- "tcp:8080" --> MitM
|
|
118
|
+
|
|
119
|
+
MitM --> Internet
|
|
120
|
+
|
|
121
|
+
Internet@{ shape: cloud }
|
|
122
|
+
|
|
123
|
+
style MitM fill:#ff4d4d,stroke:#b30000,stroke-width:3px,color:#ffffff
|
|
124
|
+
style Drop fill:#444444,stroke:#222222,color:#ffffff
|
|
125
|
+
style Reject fill:#444444,stroke:#222222,color:#ffffff
|
|
126
|
+
style DevicePort fill:#444444,stroke:#222222,color:#ffffff
|
|
127
|
+
style ADB fill:#444444,stroke:#222222,color:#ffffff
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Setup
|
|
131
|
+
|
|
132
|
+
Install the `netlane` command with [uv](https://docs.astral.sh/uv/):
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
uv tool install .
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Requirements per mode:
|
|
139
|
+
|
|
140
|
+
- `wireguard_ssh_reverse`: `ssh`, `scp` and WireGuard tools (`wg`) locally, a dedicated Ubuntu VPS with root access and the WireGuard app on the device.
|
|
141
|
+
- `adb_reverse`: `adb` locally and a rooted device or emulator.
|
|
142
|
+
|
|
143
|
+
## Configuration
|
|
144
|
+
|
|
145
|
+
Profiles and interception rules are configured in `config.toml` in the platform's config directory:
|
|
146
|
+
|
|
147
|
+
| Platform | Path |
|
|
148
|
+
|---|---|
|
|
149
|
+
| Linux | `$XDG_CONFIG_HOME/netlane/config.toml` (default `~/.config/netlane/config.toml`) |
|
|
150
|
+
| macOS | `~/Library/Application Support/netlane/config.toml` |
|
|
151
|
+
| Windows | `%APPDATA%\netlane\config\config.toml` |
|
|
152
|
+
|
|
153
|
+
Use `config.toml` from this repository as a starting point, e.g. on Linux:
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
mkdir -p ~/.config/netlane
|
|
157
|
+
cp config.toml ~/.config/netlane/config.toml
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
Each profile has a `mode`, `mode_opts`, `rules` and optional `hooks`:
|
|
161
|
+
|
|
162
|
+
| Key | Description |
|
|
163
|
+
|---|---|
|
|
164
|
+
| `mode_opts.tunnels` | Tunnel names mapped to local ports, e.g. `{ proxy = 8080 }`. |
|
|
165
|
+
| `mode_opts.elevation` | How to become root on the VPS or device: `sudo`, `doas`, `su`, or `""` if already root. |
|
|
166
|
+
| `mode_opts.ssh_host`, `mode_opts.ssh_user` | SSH login of the VPS (`wireguard_ssh_reverse`). |
|
|
167
|
+
| `mode_opts.serial` | Device serial from `adb devices`, optional with a single device (`adb_reverse`). |
|
|
168
|
+
| `hooks` | Shell commands run as root on the VPS or device: `pre_up`, `post_up`, `pre_down`, `post_down`. |
|
|
169
|
+
|
|
170
|
+
Rules are evaluated from top-to-bottom.
|
|
171
|
+
The first matching rule wins.
|
|
172
|
+
Packets matching no rule are dropped.
|
|
173
|
+
It's recommended to define a catch-all passthrough rule to let all other traffic through.
|
|
174
|
+
|
|
175
|
+
A rule matches when each of its fields matches one of the field's values. Omitted fields match everything.
|
|
176
|
+
|
|
177
|
+
| Field | Values |
|
|
178
|
+
|---|---|
|
|
179
|
+
| `name` | Required. Added as comment to the firewall rules. |
|
|
180
|
+
| `target` | Required. `action:passthrough`, `action:reject`, `action:drop` or `tunnel:<name>`. |
|
|
181
|
+
| `saddr`, `daddr` | IP addresses or networks. They restrict the rule to their address families, e.g. `["0.0.0.0/0"]` to IPv4. |
|
|
182
|
+
| `protocol` | Protocol names or numbers. |
|
|
183
|
+
| `sport`, `dport` | Ports. |
|
|
184
|
+
| `app`, `skuid` | Android package names or uids. |
|
|
185
|
+
|
|
186
|
+
## Usage
|
|
187
|
+
|
|
188
|
+
Each profile's mode defines which steps it needs. `netlane list` shows them per profile:
|
|
189
|
+
|
|
190
|
+
| Mode | Steps |
|
|
191
|
+
|---|---|
|
|
192
|
+
| `wireguard_ssh_reverse` | setup → pair → up |
|
|
193
|
+
| `adb_reverse` | up |
|
|
194
|
+
|
|
195
|
+
**setup**: One-time setup of the profile's remote server (see [`src/netlane/scripts/ubuntu/install.sh`](src/netlane/scripts/ubuntu/install.sh)). The server is assumed to be used exclusively for the interception purpose.
|
|
196
|
+
|
|
197
|
+
```bash
|
|
198
|
+
netlane setup jailed --distro ubuntu
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
**pair**: Creates the keys and shows the client config as a QR code to scan on the test device. `--save <path>` also writes the client config to disk. Existing keys are only replaced with `--force`.
|
|
202
|
+
|
|
203
|
+
```bash
|
|
204
|
+
netlane pair jailed
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
**up**: Applies the profile's interception rules and starts its tunnels until Ctrl-C.
|
|
208
|
+
|
|
209
|
+
```bash
|
|
210
|
+
netlane up jailed
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
For `adb_reverse`, `up` also exits when the device disconnects. In this case rules stay active until `down` or a reboot.
|
|
214
|
+
|
|
215
|
+
Ensure your local tool, e.g. Burp Suite, listens on `127.0.0.1` and `[::1]` on each tunnel port with invisible proxying enabled.
|
|
216
|
+
|
|
217
|
+
**down**: Cleans up if `up` was interrupted without tearing down.
|
|
218
|
+
|
|
219
|
+
Use `--config <path>` before the command to use a different config.
|
|
220
|
+
|
|
221
|
+
For debugging, `-v` before the command shows executed commands and `--log <path>` writes a JSON Lines log including debug output and the loaded config.
|
|
222
|
+
|
|
223
|
+
## Special behavior
|
|
224
|
+
|
|
225
|
+
### `wireguard_ssh_reverse`
|
|
226
|
+
|
|
227
|
+
- The client config uses `1.1.1.1` as DNS server, so the rules must let it through.
|
|
228
|
+
|
|
229
|
+
### `adb_reverse`
|
|
230
|
+
|
|
231
|
+
- Rules don't apply to traffic to the device itself, i.e. to loopback and the device's own addresses.
|
|
232
|
+
- Replies of adbd on its listen ports bypass the rules, so ADB over the network keeps working.
|
|
233
|
+
- Without IPv6 NAT on the device, tunnel rules must be restricted to IPv4 with `daddr = ["0.0.0.0/0"]`.
|
|
234
|
+
- Connections opened before `up` that match a tunnel rule are reset, so apps reconnect through the tunnel.
|
|
235
|
+
|
|
236
|
+
## Development
|
|
237
|
+
|
|
238
|
+
See [docs/development.md](docs/development.md) for the development setup and how the unit and integration tests work.
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "netlane"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Intercept mobile app traffic via WireGuard and forward it to tools such as Burp Suite"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.12"
|
|
7
|
+
dependencies = ["qrcode>=8.2"]
|
|
8
|
+
|
|
9
|
+
[[project.authors]]
|
|
10
|
+
name = "Benjamin Faller"
|
|
11
|
+
email = "benjamin.faller@redguard.ch"
|
|
12
|
+
|
|
13
|
+
[project.scripts]
|
|
14
|
+
netlane = "netlane.cli:main"
|
|
15
|
+
|
|
16
|
+
[dependency-groups]
|
|
17
|
+
dev = [
|
|
18
|
+
"pyright>=1.1.414",
|
|
19
|
+
"pytest>=9.1.1",
|
|
20
|
+
"ruff>=0.17.1",
|
|
21
|
+
"zizmor>=1.31.1",
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
[build-system]
|
|
25
|
+
requires = ["uv_build>=0.13.0,<0.14.0"]
|
|
26
|
+
build-backend = "uv_build"
|
|
27
|
+
|
|
28
|
+
[tool.ruff]
|
|
29
|
+
src = [
|
|
30
|
+
"src",
|
|
31
|
+
"tests",
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
[tool.ruff.lint]
|
|
35
|
+
extend-select = [
|
|
36
|
+
"B",
|
|
37
|
+
"C4",
|
|
38
|
+
"PIE",
|
|
39
|
+
"PT",
|
|
40
|
+
"RET",
|
|
41
|
+
"RUF",
|
|
42
|
+
"SIM",
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
[tool.pyright]
|
|
46
|
+
include = [
|
|
47
|
+
"src",
|
|
48
|
+
"tests",
|
|
49
|
+
]
|
|
50
|
+
pythonVersion = "3.12"
|
|
51
|
+
typeCheckingMode = "standard"
|
|
52
|
+
|
|
53
|
+
[tool.pytest.ini_options]
|
|
54
|
+
addopts = ["--import-mode=importlib"]
|
|
55
|
+
markers = ["""integration: marks tests as integration tests that require containers/services (deselect with '-m "not integration"')"""]
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "netlane"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Intercept mobile app traffic via WireGuard and forward it to tools such as Burp Suite"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
authors = [
|
|
7
|
+
{ name = "Benjamin Faller", email = "benjamin.faller@redguard.ch" }
|
|
8
|
+
]
|
|
9
|
+
requires-python = ">=3.12"
|
|
10
|
+
dependencies = [
|
|
11
|
+
"qrcode>=8.2",
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
[project.scripts]
|
|
15
|
+
netlane = "netlane.cli:main"
|
|
16
|
+
|
|
17
|
+
[dependency-groups]
|
|
18
|
+
dev = [
|
|
19
|
+
"pyright>=1.1.414",
|
|
20
|
+
"pytest>=9.1.1",
|
|
21
|
+
"ruff>=0.17.1",
|
|
22
|
+
"zizmor>=1.31.1",
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
[build-system]
|
|
26
|
+
requires = ["uv_build>=0.13.0,<0.14.0"]
|
|
27
|
+
build-backend = "uv_build"
|
|
28
|
+
|
|
29
|
+
[tool.ruff]
|
|
30
|
+
src = ["src", "tests"]
|
|
31
|
+
|
|
32
|
+
[tool.ruff.lint]
|
|
33
|
+
extend-select = ["B", "C4", "PIE", "PT", "RET", "RUF", "SIM"]
|
|
34
|
+
|
|
35
|
+
[tool.pyright]
|
|
36
|
+
include = ["src", "tests"]
|
|
37
|
+
pythonVersion = "3.12"
|
|
38
|
+
typeCheckingMode = "standard"
|
|
39
|
+
|
|
40
|
+
[tool.pytest.ini_options]
|
|
41
|
+
# Unit and integration tests share module basenames (e.g. test_adb_reverse.py).
|
|
42
|
+
addopts = ["--import-mode=importlib"]
|
|
43
|
+
markers = [
|
|
44
|
+
"integration: marks tests as integration tests that require containers/services (deselect with '-m \"not integration\"')",
|
|
45
|
+
]
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
import shlex
|
|
3
|
+
import subprocess
|
|
4
|
+
import tempfile
|
|
5
|
+
from collections.abc import Iterable
|
|
6
|
+
|
|
7
|
+
from netlane.utils import run_cmd
|
|
8
|
+
|
|
9
|
+
logger = logging.getLogger(__name__)
|
|
10
|
+
|
|
11
|
+
DEVICE_TMP_DIR = "/data/local/tmp"
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def run(
|
|
15
|
+
serial: str | None, args: Iterable[str], check: bool = True
|
|
16
|
+
) -> subprocess.CompletedProcess:
|
|
17
|
+
"""Runs `adb <args>` against the device with `serial`, or the only connected one."""
|
|
18
|
+
return run_cmd([*_adb(serial), *args], check=check)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def shell(
|
|
22
|
+
serial: str | None, cmd: str, check: bool = True
|
|
23
|
+
) -> subprocess.CompletedProcess:
|
|
24
|
+
"""Runs `cmd` in an unprivileged shell on the device."""
|
|
25
|
+
return run(serial, ["shell", "-n", cmd], check=check)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def run_script(
|
|
29
|
+
serial: str | None, elevation: str, content: str, check: bool = True
|
|
30
|
+
) -> subprocess.CompletedProcess:
|
|
31
|
+
"""Runs `content` from a device temp file as stdin of the root shell `elevation`. An empty `elevation` requires adbd to run as root."""
|
|
32
|
+
tmp = _upload_temp(serial, content)
|
|
33
|
+
root_shell = shlex.quote(elevation) if elevation else "sh"
|
|
34
|
+
return shell(
|
|
35
|
+
serial,
|
|
36
|
+
f"{_remove_on_exit(tmp)}; {root_shell} < {shlex.quote(tmp)}",
|
|
37
|
+
check=check,
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def start(serial: str | None, args: Iterable[str]) -> subprocess.Popen:
|
|
42
|
+
"""Starts `adb <args>` in the background."""
|
|
43
|
+
cmd = [*_adb(serial), *args]
|
|
44
|
+
logger.debug(f"Starting: {' '.join(cmd)}")
|
|
45
|
+
return subprocess.Popen(cmd, stdin=subprocess.DEVNULL)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def _adb(serial: str | None) -> list:
|
|
49
|
+
return ["adb", "-s", serial] if serial else ["adb"]
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def _upload_temp(serial: str | None, content: str) -> str:
|
|
53
|
+
"""Copies `content` to a new device temp file and returns its path."""
|
|
54
|
+
cmd = f"mktemp -p {DEVICE_TMP_DIR}"
|
|
55
|
+
tmp = shell(serial, cmd).stdout.decode("utf-8").strip()
|
|
56
|
+
with tempfile.NamedTemporaryFile(
|
|
57
|
+
mode="w", delete=True, delete_on_close=False
|
|
58
|
+
) as local:
|
|
59
|
+
local.write(content)
|
|
60
|
+
# Ensure data is written to disk before adb reads it
|
|
61
|
+
local.flush()
|
|
62
|
+
run(serial, ["push", local.name, tmp])
|
|
63
|
+
return tmp
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _remove_on_exit(path: str) -> str:
|
|
67
|
+
return f"trap {shlex.quote(f'rm -f {shlex.quote(path)}')} EXIT"
|