Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ sudo ./gotproxy [flags]
| **--p-pid** | The process ID of the proxy. If not provided, the program will automatically start a forwarding proxy. |
| **--p-port** | The proxy port. |
| **--socks5** | The SOCKS5 proxy Server network address. If configured, SOCKS5 proxying will be used. |
| **--socks5-user** | SOCKS5 username (RFC1929). Must be set together with `--socks5-pass`. |
| **--socks5-pass** | SOCKS5 password (RFC1929). Must be set together with `--socks5-user`. |
| **--proto** | Proxy protocol selection: `both` (default) / `tcp` / `udp`. When set to `tcp`, only TCP traffic will be redirected; when set to `udp`, only UDP traffic will be redirected. |

Features Under Development:
Expand All @@ -57,6 +59,12 @@ sudo ./gotproxy --socks5 192.168.1.2:1080
```
Where '192.168.1.2:1080' is the IP and port of the SOCKS5 proxy server.

SOCKS5 with username/password:

```bash
sudo ./gotproxy --socks5 192.168.1.2:1080 --socks5-user alice --socks5-pass 'secret'
```

3. TCP-only proxy:
```bash
sudo ./gotproxy --proto tcp
Expand Down
8 changes: 8 additions & 0 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ sudo ./gotproxy [flags]
| **--p-pid** | 代理程序的进程id. 会自动过滤不代理该进程的网络通信,以免网络循环。如果没有配置, 本程序会自动启动一个转发代理服务. |
| **--p-port** | 代理服务监听的端口。 |
| **--socks5** | socks5代理的服务端地址,如果配置,会进行socks5代理. |
| **--socks5-user** | socks5 账号(RFC1929)。需要同时设置 `--socks5-pass`。 |
| **--socks5-pass** | socks5 密码(RFC1929)。需要同时设置 `--socks5-user`。 |
| **--proto** | 代理协议选择:`both`(默认)/ `tcp` / `udp`。当设置为 `tcp` 时只重定向 TCP 流量;设置为 `udp` 时只重定向 UDP 流量。 |


Expand All @@ -62,6 +64,12 @@ sudo ./gotproxy --socks5 192.168.1.2:1080
```
其中‘192.168.1.2:1080’是socks5代理服务器的ip和端口

也支持带账号密码的 socks5 上游:

```bash
sudo ./gotproxy --socks5 192.168.1.2:1080 --socks5-user alice --socks5-pass 'secret'
```

3. 仅代理 TCP:
```bash
sudo ./gotproxy --proto tcp
Expand Down
8 changes: 8 additions & 0 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,19 @@
pids []string
ipStr string
socks5ProxyAddr string
socks5User string
socks5Pass string
proto string
)

var rootCmd = &cobra.Command{
Use: "gotproxy",
Short: "A simple tcp transparent proxy tool for Linux",
Run: func(cmd *cobra.Command, args []string) {
if err := validateSocks5UpstreamConfig(); err != nil {

Check failure on line 29 in cmd/cmd.go

View workflow job for this annotation

GitHub Actions / build (amd64)

undefined: validateSocks5UpstreamConfig

Check failure on line 29 in cmd/cmd.go

View workflow job for this annotation

GitHub Actions / build (arm64)

undefined: validateSocks5UpstreamConfig
log.Fatal(err)
}

var enableTCP, enableUDP bool
switch proto {
case "both":
Expand Down Expand Up @@ -89,5 +95,7 @@
rootCmd.PersistentFlags().StringSliceVar(&pids, "pids", []string{}, "The pid to be proxied, seperate by ','")
rootCmd.PersistentFlags().StringVar(&ipStr, "ip", "", "The ip to be proxied,only support ipv4")
rootCmd.PersistentFlags().StringVar(&socks5ProxyAddr, "socks5", "", "The socks5 proxyAddr.")
rootCmd.PersistentFlags().StringVar(&socks5User, "socks5-user", "", "The SOCKS5 username. Requires --socks5-pass.")
rootCmd.PersistentFlags().StringVar(&socks5Pass, "socks5-pass", "", "The SOCKS5 password. Requires --socks5-user.")
rootCmd.PersistentFlags().StringVar(&proto, "proto", "both", "Proxy protocol: both|tcp|udp")
}
7 changes: 6 additions & 1 deletion cmd/tcpProxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,12 @@
return targetConn, nil
}

dialer, err := proxy.SOCKS5("tcp", socks5ProxyAddr, nil, proxy.Direct)
auth, err := socks5AuthOrNil()

Check failure on line 119 in cmd/tcpProxy.go

View workflow job for this annotation

GitHub Actions / build (amd64)

undefined: socks5AuthOrNil

Check failure on line 119 in cmd/tcpProxy.go

View workflow job for this annotation

GitHub Actions / build (arm64)

undefined: socks5AuthOrNil
if err != nil {
return nil, err
}

dialer, err := proxy.SOCKS5("tcp", socks5ProxyAddr, auth, proxy.Direct)
if err != nil {
return nil, fmt.Errorf("cannot create SOCKS5 dialer: %w", err)
}
Expand Down
6 changes: 5 additions & 1 deletion cmd/udpProxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@

func dialUDPViaSOCKS5(targetAddr string) (net.Conn, error) {

client, err := socks5.NewClient(socks5ProxyAddr, "", "", 0, 0)
if err := validateSocks5UpstreamConfig(); err != nil {

Check failure on line 111 in cmd/udpProxy.go

View workflow job for this annotation

GitHub Actions / build (amd64)

undefined: validateSocks5UpstreamConfig

Check failure on line 111 in cmd/udpProxy.go

View workflow job for this annotation

GitHub Actions / build (arm64)

undefined: validateSocks5UpstreamConfig
return nil, err
}

client, err := socks5.NewClient(socks5ProxyAddr, socks5User, socks5Pass, 0, 0)
if err != nil {
return nil, fmt.Errorf("SOCKS5 client: %w", err)
}
Expand Down
Loading