一個將自身暴露為socks5/http代理或隧道的wireguard客戶端。
wireproxy
是一個完全用戶空間的應用程序,它連接到wireguard對等點,並在電腦上公開socks5/http代理或隧道。如果您需要透過wireguard對等點連接到某些站點,但出於某種原因又懶得設定新的網路接口,那麼這可能很有用。
目前,我正在執行連接到另一個國家的wireguard 伺服器的wireproxy,並將我的瀏覽器設定為對某些網站使用wireproxy。它非常有用,因為wireproxy 與我的網路介面完全隔離,而且我不需要 root 來配置任何內容。
想要類似但 Amnezia VPN 的使用者可以使用@artem-russkikh 的這個wireproxy 分支。
./wireproxy [-c path to config]
usage: wireproxy [-h|--help] [-c|--config ""] [-s|--silent]
[-d|--daemon] [-i|--info ""] [-v|--version]
[-n|--configtest]
Userspace wireguard client for proxying
Arguments:
-h --help Print help information
-c --config Path of configuration file
Default paths: /etc/wireproxy/wireproxy.conf, $HOME/.config/wireproxy.conf
-s --silent Silent mode
-d --daemon Make wireproxy run in background
-i --info Specify the address and port for exposing health status
-v --version Print version
-n --configtest Configtest mode. Only check the configuration file for
validity.
git clone https://github.com/octeep/wireproxy
cd wireproxy
make
有關在 Firefox 容器標籤中使用wireproxy 以及在 MacOS 上自動啟動的說明,請參閱此處。
# The [Interface] and [Peer] configurations follow the same semantics and meaning
# of a wg-quick configuration. To understand what these fields mean, please refer to:
# https://wiki.archlinux.org/title/WireGuard#Persistent_configuration
# https://www.wireguard.com/#simple-network-interface
[Interface]
Address = 10.200.200.2/32 # The subnet should be /32 and /128 for IPv4 and v6 respectively
# MTU = 1420 (optional)
PrivateKey = uCTIK+56CPyCvwJxmU5dBfuyJvPuSXAq1FzHdnIxe1Q=
# PrivateKey = $MY_WIREGUARD_PRIVATE_KEY # Alternatively, reference environment variables
DNS = 10.200.200.1
[Peer]
PublicKey = QP+A67Z2UBrMgvNIdHv8gPel5URWNLS4B3ZQ2hQIZlg=
# PresharedKey = UItQuvLsyh50ucXHfjF0bbR4IIpVBd74lwKc8uIPXXs= (optional)
Endpoint = my.ddns.example.com:51820
# PersistentKeepalive = 25 (optional)
# TCPClientTunnel is a tunnel listening on your machine,
# and it forwards any TCP traffic received to the specified target via wireguard.
# Flow:
# --> localhost:25565 --(wireguard)--> play.cubecraft.net:25565
[TCPClientTunnel]
BindAddress = 127.0.0.1:25565
Target = play.cubecraft.net:25565
# TCPServerTunnel is a tunnel listening on wireguard,
# and it forwards any TCP traffic received to the specified target via local network.
# Flow:
# --(wireguard)--> 172.16.31.2:3422 --> localhost:25545
[TCPServerTunnel]
ListenPort = 3422
Target = localhost:25545
# STDIOTunnel is a tunnel connecting the standard input and output of the wireproxy
# process to the specified TCP target via wireguard.
# This is especially useful to use wireproxy as a ProxyCommand parameter in openssh
# For example:
# ssh -o ProxyCommand='wireproxy -c myconfig.conf' ssh.myserver.net
# Flow:
# Piped command -->(wireguard)--> ssh.myserver.net:22
[STDIOTunnel]
Target = ssh.myserver.net:22
# Socks5 creates a socks5 proxy on your LAN, and all traffic would be routed via wireguard.
[Socks5]
BindAddress = 127.0.0.1:25344
# Socks5 authentication parameters, specifying username and password enables
# proxy authentication.
#Username = ...
# Avoid using spaces in the password field
#Password = ...
# http creates a http proxy on your LAN, and all traffic would be routed via wireguard.
[http]
BindAddress = 127.0.0.1:25345
# HTTP authentication parameters, specifying username and password enables
# proxy authentication.
#Username = ...
# Avoid using spaces in the password field
#Password = ...
或者,如果您已經有wireguard配置,則可以將其匯入wireproxy設定檔中,如下所示:
WGConfig =
# Same semantics as above
[TCPClientTunnel]
...
[TCPServerTunnel]
...
[Socks5]
...
也支援擁有多個對等點。需要指定AllowedIPs
,以便wireproxy知道要轉送到哪個對等點。
[Interface]
Address = 10.254.254.40/32
PrivateKey = XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX=
[Peer]
Endpoint = 192.168.0.204:51820
PublicKey = YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY=
AllowedIPs = 10.254.254.100/32
PersistentKeepalive = 25
[Peer]
PublicKey = ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ=
AllowedIPs = 10.254.254.1/32, fdee:1337:c000:d00d::1/128
Endpoint = 172.16.0.185:44044
PersistentKeepalive = 25
[TCPServerTunnel]
ListenPort = 5000
Target = service-one.servicenet:5000
[TCPServerTunnel]
ListenPort = 5001
Target = service-two.servicenet:5001
[TCPServerTunnel]
ListenPort = 5080
Target = service-three.servicenet:80
Wireproxy 還可以允許對等方連接到它:
[Interface]
ListenPort = 5400
...
[Peer]
PublicKey = YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY=
AllowedIPs = 10.254.254.100/32
# Note there is no Endpoint defined here.
Wireproxy 支援公開健康端點以進行監控。參數--info/-i
指定位址和連接埠(例如localhost:9080
),它公開提供伺服器健康狀況指標的 HTTP 伺服器。
目前實現了兩個端點:
/metrics
:公開wireguard 守護程式的訊息,這提供了與使用wg show
獲得的相同資訊。這顯示了響應的範例。
/readyz
:這會傳回一個 json 回應,該 json 顯示上次從CheckAlive
指定的 IP 接收到 pong 的時間。設定CheckAlive
後,每CheckAliveInterval
秒(預設為 5)透過wireguard 向CheckAlive
中的位址傳送 ping。如果在最後CheckAliveInterval
秒內(+2 秒,有一定的餘地來考慮延遲)尚未從某個位址之一收到 pong,則它將回應 503,否則回應 200。
例如:
[Interface]
PrivateKey = censored
Address = 10.2.0.2/32
DNS = 10.2.0.1
CheckAlive = 1.1.1.1, 3.3.3.3
CheckAliveInterval = 3
[Peer]
PublicKey = censored
AllowedIPs = 0.0.0.0/0
Endpoint = 149.34.244.174:51820
[Socks5]
BindAddress = 127.0.0.1:25344
/readyz
會回應
< HTTP/1.1 503 Service Unavailable
< Date: Thu, 11 Apr 2024 00:54:59 GMT
< Content-Length: 35
< Content-Type: text/plain; charset=utf-8
<
{"1.1.1.1":1712796899,"3.3.3.3":0}
對於:
[Interface]
PrivateKey = censored
Address = 10.2.0.2/32
DNS = 10.2.0.1
CheckAlive = 1.1.1.1
/readyz
會回應
< HTTP/1.1 200 OK
< Date: Thu, 11 Apr 2024 00:56:21 GMT
< Content-Length: 23
< Content-Type: text/plain; charset=utf-8
<
{"1.1.1.1":1712796979}
如果CheckAlive
未設定任何內容,則回應將是一個帶有 200 的空 JSON 物件。
ICMP ping 封包路由到的對等方取決於為每個對等方設定的AllowedIPs
。