Skip to content

Commit 6909633

Browse files
authored
Merge branch 'master' into pr-https
2 parents 6bd3c74 + e76e370 commit 6909633

File tree

16 files changed

+404
-121
lines changed

16 files changed

+404
-121
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2024 Wind Wong <me@windtfw.com>
1+
Copyright (c) 2026 Tsz Fung Wong <im@windtfw.com>
22

33
Permission to use, copy, modify, and distribute this software for any
44
purpose with or without fee is hereby granted, provided that the above

README.md

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
# wireproxy
2+
23
[![ISC licensed](https://img.shields.io/badge/license-ISC-blue)](./LICENSE)
34
[![Build status](https://github.com/octeep/wireproxy/actions/workflows/build.yml/badge.svg)](https://github.com/octeep/wireproxy/actions)
45
[![Documentation](https://img.shields.io/badge/godoc-wireproxy-blue)](https://pkg.go.dev/github.com/octeep/wireproxy)
56

67
A wireguard client that exposes itself as a socks5/http proxy or tunnels.
78

89
# What is this
10+
911
`wireproxy` is a completely userspace application that connects to a wireguard peer,
1012
and exposes a socks5/http proxy or tunnels on the machine. This can be useful if you need
1113
to connect to certain sites via a wireguard peer, but can't be bothered to setup a new network
1214
interface for whatever reasons.
1315

1416
# Why you might want this
17+
1518
- You simply want to use wireguard as a way to proxy some traffic.
1619
- You don't want root permission just to change wireguard settings.
1720

@@ -20,23 +23,33 @@ and configured my browser to use wireproxy for certain sites. It's pretty useful
2023
wireproxy is completely isolated from my network interfaces, and I don't need root to configure
2124
anything.
2225

23-
Users who want something similar but for Amnezia VPN can use [this fork](https://github.com/juev/wireproxy/tree/feature/amnezia-go)
24-
of wireproxy by [@juev](https://github.com/juev).
26+
Users who want something similar but for Amnezia VPN can use [this fork](https://github.com/artem-russkikh/wireproxy-awg)
27+
of wireproxy by [@artem-russkikh](https://github.com/artem-russkikh).
28+
29+
# Sponsor
30+
31+
This project is supported by [IPRoyal](https://iproyal.com/?r=795836). You can get premium quality proxies at unbeatable prices
32+
with a discount using [this referral link](https://iproyal.com/?r=795836)! 🚀
33+
34+
![IPRoyal](/assets/iproyal.png)
2535

2636
# Feature
37+
2738
- TCP static routing for client and server
2839
- SOCKS5/HTTP proxy (currently only CONNECT is supported)
2940

3041
# TODO
42+
3143
- UDP Support in SOCKS5
3244
- UDP static routing
3345

3446
# Usage
35-
```
47+
48+
```bash
3649
./wireproxy [-c path to config]
3750
```
3851

39-
```
52+
```bash
4053
usage: wireproxy [-h|--help] [-c|--config "<value>"] [-s|--silent]
4154
[-d|--daemon] [-i|--info "<value>"] [-v|--version]
4255
[-n|--configtest]
@@ -54,21 +67,29 @@ Arguments:
5467
-v --version Print version
5568
-n --configtest Configtest mode. Only check the configuration file for
5669
validity.
57-
5870
```
5971

6072
# Build instruction
61-
```
73+
74+
```bash
6275
git clone https://github.com/octeep/wireproxy
6376
cd wireproxy
6477
make
6578
```
6679

80+
# Install
81+
82+
```bash
83+
go install github.com/pufferffish/wireproxy/cmd/wireproxy@v1.0.9 # or @latest
84+
```
85+
6786
# Use with VPN
87+
6888
Instructions for using wireproxy with Firefox container tabs and auto-start on MacOS can be found [here](/UseWithVPN.md).
6989

7090
# Sample config file
71-
```
91+
92+
```ini
7293
# The [Interface] and [Peer] configurations follow the same semantics and meaning
7394
# of a wg-quick configuration. To understand what these fields mean, please refer to:
7495
# https://wiki.archlinux.org/title/WireGuard#Persistent_configuration
@@ -139,7 +160,8 @@ BindAddress = 127.0.0.1:25345
139160

140161
Alternatively, if you already have a wireguard config, you can import it in the
141162
wireproxy config file like this:
142-
```
163+
164+
```ini
143165
WGConfig = <path to the wireguard config>
144166

145167
# Same semantics as above
@@ -155,7 +177,8 @@ WGConfig = <path to the wireguard config>
155177

156178
Having multiple peers is also supported. `AllowedIPs` would need to be specified
157179
such that wireproxy would know which peer to forward to.
158-
```
180+
181+
```ini
159182
[Interface]
160183
Address = 10.254.254.40/32
161184
PrivateKey = XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX=
@@ -187,7 +210,8 @@ Target = service-three.servicenet:80
187210
```
188211

189212
Wireproxy can also allow peers to connect to it:
190-
```
213+
214+
```ini
191215
[Interface]
192216
ListenPort = 5400
193217
...
@@ -197,7 +221,9 @@ PublicKey = YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY=
197221
AllowedIPs = 10.254.254.100/32
198222
# Note there is no Endpoint defined here.
199223
```
224+
200225
# Health endpoint
226+
201227
Wireproxy supports exposing a health endpoint for monitoring purposes.
202228
The argument `--info/-i` specifies an address and port (e.g. `localhost:9080`), which exposes a HTTP server that provides health status metric of the server.
203229

@@ -208,7 +234,8 @@ Currently two endpoints are implemented:
208234
`/readyz`: This responds with a json which shows the last time a pong is received from an IP specified with `CheckAlive`. When `CheckAlive` is set, a ping is sent out to addresses in `CheckAlive` per `CheckAliveInterval` seconds (defaults to 5) via wireguard. If a pong has not been received from one of the addresses within the last `CheckAliveInterval` seconds (+2 seconds for some leeway to account for latency), then it would respond with a 503, otherwise a 200.
209235

210236
For example:
211-
```
237+
238+
```ini
212239
[Interface]
213240
PrivateKey = censored
214241
Address = 10.2.0.2/32
@@ -224,8 +251,10 @@ Endpoint = 149.34.244.174:51820
224251
[Socks5]
225252
BindAddress = 127.0.0.1:25344
226253
```
254+
227255
`/readyz` would respond with
228-
```
256+
257+
```text
229258
< HTTP/1.1 503 Service Unavailable
230259
< Date: Thu, 11 Apr 2024 00:54:59 GMT
231260
< Content-Length: 35
@@ -235,15 +264,18 @@ BindAddress = 127.0.0.1:25344
235264
```
236265

237266
And for:
238-
```
267+
268+
```ini
239269
[Interface]
240270
PrivateKey = censored
241271
Address = 10.2.0.2/32
242272
DNS = 10.2.0.1
243273
CheckAlive = 1.1.1.1
244274
```
275+
245276
`/readyz` would respond with
246-
```
277+
278+
```text
247279
< HTTP/1.1 200 OK
248280
< Date: Thu, 11 Apr 2024 00:56:21 GMT
249281
< Content-Length: 23
@@ -257,4 +289,5 @@ If nothing is set for `CheckAlive`, an empty JSON object with 200 will be the re
257289
The peer which the ICMP ping packet is routed to depends on the `AllowedIPs` set for each peers.
258290

259291
# Stargazers over time
292+
260293
[![Stargazers over time](https://starchart.cc/octeep/wireproxy.svg)](https://starchart.cc/octeep/wireproxy)

UseWithVPN.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
# Getting a Wireguard Server
2+
23
You can create your own wireguard server using a host service like DigitalOcean,
34
or you can get a VPN service that provides WireGuard configs.
45

56
I recommend ProtonVPN, because it is highly secure and has a great WireGuard
67
config generator.
78

8-
Simply go to https://account.protonvpn.com/downloads and scroll down to the
9+
Simply go to <https://account.protonvpn.com/downloads> and scroll down to the
910
wireguard section to generate your configs, then paste into the appropriate
1011
section below.
1112

@@ -25,9 +26,11 @@ naming should also be similar (e.g.
2526
`/Users/jonny/Library/LaunchAgents/com.ProtonUS.adblock.plist`)
2627

2728
## Config File
29+
2830
Make sure you use a unique port for every separate server
2931
I recommend you set proxy authentication, you can use the same user/pass for all
30-
```
32+
33+
```ini
3134
# Link to the Downloaded config
3235
WGConfig = /Users/jonny/vpntabs/ProtonUS.adblock.server.conf
3336

@@ -43,24 +46,27 @@ BindAddress = 127.0.0.1:25344 # Update the port here for each new server
4346
```
4447

4548
## Startup Script File
49+
4650
This is a bash script to facilitate startup, not strictly essential, but adds
4751
ease.
4852
Note, you MUST update the first path to wherever you installed this code to.
4953
Make sure you use the path for the config file above, not the one you downloaded
5054
from e.g. protonvpn.
51-
```
55+
56+
```bash
5257
#!/bin/bash
5358
/Users/jonny/wireproxy/wireproxy -c /Users/jonny/vpntabs/ProtonUS.adblock.conf
5459
```
5560

5661
## MacOS LaunchAgent
62+
5763
To make it run every time you start your computer, you can create a launch agent
5864
in `$HOME/Library/LaunchAgents`. Name reference above.
5965

6066
That file should contain the following, the label should be the same as the file
6167
name and the paths should be set correctly:
6268

63-
```
69+
```xml
6470
<?xml version="1.0" encoding="UTF-8"?>
6571
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
6672
<plist version="1.0">
@@ -70,7 +76,7 @@ name and the paths should be set correctly:
7076
<key>Program</key>
7177
<string>/Users/jonny/vpntabs/ProtonUS.adblock.sh</string>
7278
<key>RunAtLoad</key>
73-
<true/>
79+
<true/>
7480
<key>KeepAlive</key>
7581
<true/>
7682
</dict>
@@ -82,6 +88,7 @@ To enable it, run
8288
`launchtl start ~/Library/LaunchAgents/com.PortonUS.adblock.plist`
8389

8490
# Firefox Setup
91+
8592
You will need to enable the Multi Account Container Tabs extension and a proxy extension, I
8693
recommend Sideberry, but Container Proxy also works.
8794

assets/iproyal.png

2.57 KB
Loading

cmd/wireproxy/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ func lock(stage string) {
8080
// Linux
8181
panicIfError(landlock.V1.BestEffort().RestrictPaths(
8282
landlock.RODirs("/"),
83+
landlock.RWFiles("/dev/null").IgnoreIfMissing(),
8384
))
8485
case "boot-daemon":
8586
case "read-config":
@@ -236,7 +237,7 @@ func main() {
236237
// Wireguard doesn't allow configuring which FD to use for logging
237238
// https://github.com/WireGuard/wireguard-go/blob/master/device/logger.go#L39
238239
// so redirect STDOUT to STDERR, we don't want to print anything to STDOUT anyways
239-
os.Stdout = os.NewFile(uintptr(syscall.Stderr), "/dev/stderr")
240+
os.Stdout = os.Stderr
240241
logLevel := device.LogLevelVerbose
241242
if *silent {
242243
logLevel = device.LogLevelSilent

config.go

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,21 @@ type DeviceConfig struct {
3333
CheckAliveInterval int
3434
}
3535

36+
type UDPProxyTunnelConfig struct {
37+
BindAddress string
38+
Target string
39+
InactivityTimeout int
40+
}
41+
3642
type TCPClientTunnelConfig struct {
3743
BindAddress *net.TCPAddr
3844
Target string
3945
}
4046

4147
type STDIOTunnelConfig struct {
4248
Target string
49+
Input *os.File
50+
Output *os.File
4351
}
4452

4553
type TCPServerTunnelConfig struct {
@@ -328,7 +336,8 @@ func ParsePeers(cfg *ini.File, peers *[]PeerConfig) error {
328336
peer.PreSharedKey = value
329337
}
330338

331-
if value, err := parseString(section, "Endpoint"); err == nil {
339+
if sectionKey, err := section.GetKey("Endpoint"); err == nil {
340+
value := sectionKey.String()
332341
decoded, err = resolveIPPAndPort(strings.ToLower(value))
333342
if err != nil {
334343
return err
@@ -378,6 +387,8 @@ func parseSTDIOTunnelConfig(section *ini.Section) (RoutineSpawner, error) {
378387
return nil, err
379388
}
380389
config.Target = targetSection
390+
config.Input = os.Stdin
391+
config.Output = os.Stdout
381392

382393
return config, nil
383394
}
@@ -442,6 +453,34 @@ func parseHTTPConfig(section *ini.Section) (RoutineSpawner, error) {
442453
return config, nil
443454
}
444455

456+
func parseUDPProxyTunnelConfig(section *ini.Section) (RoutineSpawner, error) {
457+
config := &UDPProxyTunnelConfig{}
458+
459+
bindAddress, err := parseString(section, "BindAddress")
460+
if err != nil {
461+
return nil, err
462+
}
463+
config.BindAddress = bindAddress
464+
465+
target, err := parseString(section, "Target")
466+
if err != nil {
467+
return nil, err
468+
}
469+
config.Target = target
470+
471+
inactivityTimeout := 0
472+
if sectionKey, err := section.GetKey("InactivityTimeout"); err == nil {
473+
timeoutVal, err := sectionKey.Int()
474+
if err != nil {
475+
return nil, err
476+
}
477+
inactivityTimeout = timeoutVal
478+
}
479+
config.InactivityTimeout = inactivityTimeout
480+
481+
return config, nil
482+
}
483+
445484
// Takes a function that parses an individual section into a config, and apply it on all
446485
// specified sections
447486
func parseRoutinesConfig(routines *[]RoutineSpawner, cfg *ini.File, sectionName string, f func(*ini.Section) (RoutineSpawner, error)) error {
@@ -526,6 +565,11 @@ func ParseConfig(path string) (*Configuration, error) {
526565
return nil, err
527566
}
528567

568+
err = parseRoutinesConfig(&routinesSpawners, cfg, "UDPProxyTunnel", parseUDPProxyTunnelConfig)
569+
if err != nil {
570+
return nil, err
571+
}
572+
529573
return &Configuration{
530574
Device: device,
531575
Routines: routinesSpawners,

go.mod

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,16 @@ require (
99
github.com/akamensky/argparse v1.4.0
1010
github.com/go-ini/ini v1.67.0
1111
github.com/landlock-lsm/go-landlock v0.0.0-20240216195629-efb66220540a
12-
github.com/sourcegraph/conc v0.3.0
1312
github.com/things-go/go-socks5 v0.0.5
14-
golang.org/x/net v0.23.0
13+
golang.org/x/net v0.33.0
1514
golang.zx2c4.com/wireguard v0.0.0-20231211153847-12269c276173
1615
suah.dev/protect v1.2.3
1716
)
1817

1918
require (
2019
github.com/google/btree v1.1.2 // indirect
21-
golang.org/x/crypto v0.21.0 // indirect
22-
golang.org/x/sys v0.18.0 // indirect
20+
golang.org/x/crypto v0.31.0 // indirect
21+
golang.org/x/sys v0.28.0 // indirect
2322
golang.org/x/time v0.5.0 // indirect
2423
golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2 // indirect
2524
gvisor.dev/gvisor v0.0.0-20230927004350-cbd86285d259 // indirect

0 commit comments

Comments
 (0)