Skip to content

Commit 67dcd36

Browse files
Merge pull request #19 from shadowy-pycoder/ipv6
Experimental support for IPv6
2 parents 298c855 + 81d69f9 commit 67dcd36

10 files changed

Lines changed: 718 additions & 182 deletions

File tree

README.md

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
- [ARP spoofing](#arp-spoofing)
2525
- [UDP support](#udp-support)
2626
- [Android support](#android-support)
27+
- [IPv6 support](#ipv6-support)
2728
- [Traffic sniffing](#traffic-sniffing)
2829
- [JSON format](#json-format)
2930
- [Colored format](#colored-format)
@@ -107,10 +108,10 @@ You can download the binary for your platform from [Releases](https://github.com
107108
Example:
108109

109110
```shell
110-
GOHPTS_RELEASE=v1.11.2; wget -v https://github.com/shadowy-pycoder/go-http-proxy-to-socks/releases/download/$GOHPTS_RELEASE/gohpts-$GOHPTS_RELEASE-linux-amd64.tar.gz -O gohpts && tar xvzf gohpts && mv -f gohpts-$GOHPTS_RELEASE-linux-amd64 gohpts && ./gohpts -h
111+
GOHPTS_RELEASE=v1.12.0; wget -v https://github.com/shadowy-pycoder/go-http-proxy-to-socks/releases/download/$GOHPTS_RELEASE/gohpts-$GOHPTS_RELEASE-linux-amd64.tar.gz -O gohpts && tar xvzf gohpts && mv -f gohpts-$GOHPTS_RELEASE-linux-amd64 gohpts && ./gohpts -h
111112
```
112113

113-
Alternatively, you can install it using `go install` command (requires Go [1.24](https://go.dev/doc/install) or later):
114+
Alternatively, you can install it using `go install` command (requires Go [1.26](https://go.dev/doc/install) or later):
114115

115116
```shell
116117
CGO_ENABLED=0 go install -ldflags "-s -w" -trimpath github.com/shadowy-pycoder/go-http-proxy-to-socks/cmd/gohpts@latest
@@ -160,6 +161,7 @@ OPTIONS:
160161
-u User for SOCKS5 proxy authentication. This flag invokes prompt for password (not echoed to terminal)
161162
-i Bind proxy to specific network interface (either by interface name or index)
162163
-f Path to server configuration file in YAML format (overrides proxy flags above)
164+
-6 Enable IPv6 support for TCP and UDP
163165

164166
Logs:
165167
-d Show logs in DEBUG mode
@@ -578,6 +580,40 @@ GOHPTS_RELEASE=v1.10.2; wget -v https://github.com/shadowy-pycoder/go-http-proxy
578580
sudo ./gohpts -s remote -t 8888 -Tu :8989 -M tproxy -sniff -body -auto -mark 100 -d -arpspoof "fullduplex true;debug false"
579581
```
580582
583+
### IPv6 support
584+
585+
To enable IPv6 handling just add `-6` flag, for example when using with transparent proxy:
586+
587+
```shell
588+
sudo ./gohpts -T 8888 -M redirect -sniff -body -auto -mark 100 -d -6
589+
```
590+
591+
For this to work, your ISP and remote socks5 proxy should have active IPv6 support, you can visit [https://test-ipv6.com/](https://test-ipv6.com/) to find out you can access IPv6 addresses.
592+
To test proxy in IPv6 mode you can use any Linux VM:
593+
594+
1. On your virtual machine:
595+
596+
```shell
597+
# add your host machine as gateway for VM
598+
export GATEWAY="<host IPv4 address>"
599+
ip route add 0.0.0.0/1 via "$GATEWAY"
600+
ip route add 128.0.0.0/1 via "$GATEWAY"
601+
602+
# add your host machine as gateway IPv6 for VM
603+
export GATEWAY6="<host IPv6 address>"
604+
ip -6 route add ::/1 via "$GATEWAY6" dev eth0
605+
ip -6 route add 8000::/1 via "$GATEWAY6" dev eth0
606+
```
607+
608+
2. On your host:
609+
610+
```shell
611+
# run proxy on your host
612+
sudo ./gohpts -T 8888 -Tu 8889 -M tproxy -sniff -body -auto -d -6
613+
```
614+
615+
3. Visit any website on your virtual machine and see traffic in proxy logs
616+
581617
## Traffic sniffing
582618
583619
[[Back]](#table-of-contents)

cmd/gohpts/cli.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ OPTIONS:
4545
-u User for SOCKS5 proxy authentication. This flag invokes prompt for password (not echoed to terminal)
4646
-i Bind proxy to specific network interface (either by interface name or index)
4747
-f Path to server configuration file in YAML format (overrides proxy flags above)
48+
-6 Enable IPv6 support for TCP and UDP
4849
4950
Logs:
5051
-d Show logs in DEBUG mode
@@ -98,6 +99,7 @@ func root(args []string) error {
9899
"",
99100
"Path to server configuration file in YAML format (overrides other proxy flags)",
100101
)
102+
flags.BoolVar(&conf.IPv6Enabled, "6", false, "Enable IPv6 support for TCP and UDP")
101103
flags.StringVar(&conf.Interface, "i", "", "Bind proxy to specific network interface")
102104
flags.BoolFunc("I", "Display list of network interfaces and exit", func(flagValue string) error {
103105
if err := network.DisplayInterfaces(false); err != nil {

colorize.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818

1919
var (
2020
ipPortPattern = regexp.MustCompile(
21-
`(?:\[(?:[0-9a-fA-F:.]+)\]|(?:\d{1,3}\.){3}\d{1,3})(?::(6553[0-5]|655[0-2]\d|65[0-4]\d{2}|6[0-4]\d{3}|[1-5]?\d{1,4}))?`,
21+
`(?:\[(?:[0-9a-fA-F:.]+(?:%[a-zA-Z0-9_.-]+)?)\]|(?:\d{1,3}\.){3}\d{1,3})(?::(6553[0-5]|655[0-2]\d|65[0-4]\d{2}|6[0-4]\d{3}|[1-5]?\d{1,4}))?`,
2222
)
2323
domainPattern = regexp.MustCompile(
2424
`\b(?:[a-zA-Z0-9-]{1,63}\.)+(?:com|net|org|io|co|uk|ru|de|edu|gov|info|biz|dev|app|ai|tv)(?::(6553[0-5]|655[0-2]\d|65[0-4]\d{2}|6[0-4]\d{3}|[1-5]?\d{1,4}))?\b`,
@@ -167,7 +167,7 @@ func colorizeHTTP(
167167
if body && len(*reqBodySaved) > 0 {
168168
b := colorizeBody(reqBodySaved, nocolor)
169169
if b != "" {
170-
sb.WriteString("\n")
170+
sb.WriteString("\033[K\n")
171171
fmt.Fprintf(&sb, "%s ", colorizeTimestamp(time.Now(), nocolor))
172172
sb.WriteString(id)
173173
sb.WriteString(colors.RedBgDark(" req_body: ").String())
@@ -177,13 +177,14 @@ func colorizeHTTP(
177177
if body && len(*respBodySaved) > 0 {
178178
b := colorizeBody(respBodySaved, nocolor)
179179
if b != "" {
180-
sb.WriteString("\n")
180+
sb.WriteString("\033[K\n")
181181
fmt.Fprintf(&sb, "%s ", colorizeTimestamp(time.Now(), nocolor))
182182
sb.WriteString(id)
183183
sb.WriteString(colors.RedBgDark(" resp_body: ").String())
184184
sb.WriteString(b)
185185
}
186186
}
187+
sb.WriteString("\033[K")
187188
}
188189
return sb.String()
189190
}
@@ -241,7 +242,7 @@ func colorizeTLS(req *layers.TLSClientHello, resp *layers.TLSServerHello, id str
241242
sb.WriteString(colors.BlueBg(fmt.Sprintf(" ALPN: %v", req.ALPN)).String())
242243
}
243244
sb.WriteString(colors.MagentaBg(" → ").String())
244-
sb.WriteString("\n")
245+
sb.WriteString("\033[K\n")
245246
fmt.Fprintf(&sb, "%s ", colorizeTimestamp(time.Now(), nocolor))
246247
sb.WriteString(id)
247248
sb.WriteString(colors.LightBlue(fmt.Sprintf(" %s ", resp.TypeDesc)).Bold())
@@ -260,6 +261,7 @@ func colorizeTLS(req *layers.TLSClientHello, resp *layers.TLSServerHello, id str
260261
if resp.ExtensionLength > 0 {
261262
sb.WriteString(colors.BeigeBg(fmt.Sprintf(" ExtLen: %d", resp.ExtensionLength)).String())
262263
}
264+
sb.WriteString("\033[K")
263265
}
264266
return sb.String()
265267
}
@@ -335,7 +337,7 @@ func colorizeDNS(req, resp *layers.DNSMessage, id string, nocolor bool) string {
335337
for _, rec := range req.AdditionalRRs {
336338
sb.WriteString(colorizeRData(rec))
337339
}
338-
sb.WriteString("\n")
340+
sb.WriteString("\033[K\n")
339341
fmt.Fprintf(&sb, "%s ", colorizeTimestamp(time.Now(), nocolor))
340342
sb.WriteString(id)
341343
sb.WriteString(colors.Blue(fmt.Sprintf(" DNS %s (%s)", resp.Flags.OPCodeDesc, resp.Flags.QRDesc)).Bold())
@@ -352,6 +354,7 @@ func colorizeDNS(req, resp *layers.DNSMessage, id string, nocolor bool) string {
352354
for _, rec := range resp.AdditionalRRs {
353355
sb.WriteString(colorizeRData(rec))
354356
}
357+
sb.WriteString("\033[K")
355358
}
356359
return sb.String()
357360
}
@@ -457,12 +460,13 @@ func colorizeConnections(srcRemote, srcLocal, dstRemote, dstLocal net.Addr, id s
457460
sb.WriteString(colors.Green(fmt.Sprintf(" Src: %s→ %s", srcRemote, srcLocal)).String())
458461
sb.WriteString(colors.Magenta(" → ").String())
459462
sb.WriteString(colors.Blue(fmt.Sprintf("Dst: %s→ %s", dstLocal, dstRemote)).String())
460-
sb.WriteString("\n")
463+
sb.WriteString("\033[K\n")
461464
fmt.Fprintf(&sb, "%s ", colorizeTimestamp(time.Now(), nocolor))
462465
sb.WriteString(id)
463466
sb.WriteString(colors.Gray(fmt.Sprintf(" %s ", r.Method)).String())
464467
sb.WriteString(colors.YellowBg(fmt.Sprintf("%s ", r.Host)).String())
465468
sb.WriteString(colors.BlueBg(fmt.Sprintf("%s ", r.Proto)).String())
469+
sb.WriteString("\033[K")
466470
}
467471
return sb.String()
468472
}
@@ -489,6 +493,7 @@ func colorizeConnectionsTransparent(
489493
sb.WriteString(colors.Magenta(" → ").String())
490494
sb.WriteString(colors.Blue(fmt.Sprintf("Dst: %s→ %s ", dstLocal, dstRemote)).String())
491495
sb.WriteString(colors.BeigeBg(fmt.Sprintf("Orig Dst: %s", dst)).String())
496+
sb.WriteString("\033[K")
492497
}
493498
return sb.String()
494499
}

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
module github.com/shadowy-pycoder/go-http-proxy-to-socks
22

3-
go 1.25.7
3+
go 1.26.0
44

55
require (
66
github.com/goccy/go-yaml v1.18.0
77
github.com/google/uuid v1.6.0
88
github.com/rs/zerolog v1.34.0
99
github.com/shadowy-pycoder/arpspoof v0.0.1
1010
github.com/shadowy-pycoder/colors v0.0.1
11-
github.com/shadowy-pycoder/mshark v0.0.18
11+
github.com/shadowy-pycoder/mshark v0.0.20
1212
github.com/wzshiming/socks5 v0.5.2
1313
golang.org/x/sys v0.33.0
1414
golang.org/x/term v0.32.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ github.com/shadowy-pycoder/arpspoof v0.0.1 h1:K5D+cVGc3SCTI4VxSB6oE2x8SJgxRjE72E
3636
github.com/shadowy-pycoder/arpspoof v0.0.1/go.mod h1:dsVZh4gbbQFA4BQLEmL2qpsjtytKwxaf4oA2tRmvCW8=
3737
github.com/shadowy-pycoder/colors v0.0.1 h1:weCj/YIOupqy4BSP8KuVzr20fC+cuAv/tArz7bhhkP4=
3838
github.com/shadowy-pycoder/colors v0.0.1/go.mod h1:lkrJS1PY2oVigNLTT6pkbF7B/v0YcU2LD5PZnss1Q4U=
39-
github.com/shadowy-pycoder/mshark v0.0.18 h1:SaNsl7U2N1LaDc8ZGfdOclRI0UsyiDE/39NjxU2dHnQ=
40-
github.com/shadowy-pycoder/mshark v0.0.18/go.mod h1:Txx0p8JxYOGd+0V+6N9MeCUGtGdfHAATWE8KB1nd7H0=
39+
github.com/shadowy-pycoder/mshark v0.0.20 h1:xZTvrh3nFHIagPsv756P4gNEz1IOj3Fc4+fRc0feWhc=
40+
github.com/shadowy-pycoder/mshark v0.0.20/go.mod h1:1XgkjUmooSY3p9ygd0iInTrijsYbcKMQ7RXJLNP0Ygs=
4141
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
4242
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
4343
github.com/wzshiming/socks5 v0.5.2 h1:LtoowVNwAmkIQSkP1r1Wg435xUmC+tfRxorNW30KtnM=

0 commit comments

Comments
 (0)