Skip to content

Commit 10a5c2a

Browse files
Merge pull request #7 from shadowy-pycoder/colors
Added nice colorization for sniffing output
2 parents 9d9fa10 + 0dbaecb commit 10a5c2a

File tree

9 files changed

+711
-165
lines changed

9 files changed

+711
-165
lines changed

README.md

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
![GitHub Release](https://img.shields.io/github/v/release/shadowy-pycoder/go-http-proxy-to-socks)
88
![GitHub Downloads (all assets, all releases)](https://img.shields.io/github/downloads/shadowy-pycoder/go-http-proxy-to-socks/total)
99

10+
![GoHPTS - Colors example](resources/sniffing_color.png)
11+
1012
## Table of contents
1113

1214
- [Introduction](#introduction)
@@ -19,6 +21,8 @@
1921
- [redirect (via NAT and SO_ORIGINAL_DST)](#redirect-via-nat-and-so_original_dst)
2022
- [tproxy (via MANGLE and IP_TRANSPARENT)](#tproxy-via-mangle-and-ip_transparent)
2123
- [Traffic sniffing](#traffic-sniffing)
24+
- [JSON format](#json-format)
25+
- [Colored format](#colored-format)
2226
- [Links](#links)
2327
- [Contributing](#contributing)
2428
- [License](#license)
@@ -93,7 +97,7 @@ You can download the binary for your platform from [Releases](https://github.com
9397
Example:
9498

9599
```shell
96-
HPTS_RELEASE=v1.7.2; wget -v https://github.com/shadowy-pycoder/go-http-proxy-to-socks/releases/download/$HPTS_RELEASE/gohpts-$HPTS_RELEASE-linux-amd64.tar.gz -O gohpts && tar xvzf gohpts && mv -f gohpts-$HPTS_RELEASE-linux-amd64 gohpts && ./gohpts -h
100+
HPTS_RELEASE=v1.8.0; wget -v https://github.com/shadowy-pycoder/go-http-proxy-to-socks/releases/download/$HPTS_RELEASE/gohpts-$HPTS_RELEASE-linux-amd64.tar.gz -O gohpts && tar xvzf gohpts && mv -f gohpts-$HPTS_RELEASE-linux-amd64 gohpts && ./gohpts -h
97101
```
98102

99103
Alternatively, you can install it using `go install` command (requires Go [1.24](https://go.dev/doc/install) or later):
@@ -139,10 +143,10 @@ Options:
139143
Address of transparent proxy server (no HTTP)
140144
-U string
141145
User for HTTP proxy (basic auth). This flag invokes prompt for password (not echoed to terminal)
146+
-body
147+
Collect request and response body for HTTP sniffing
142148
-c string
143149
Path to certificate PEM encoded file
144-
-color
145-
Enable colored output for logs in stdout (no effect if log file provided or -j flag specified)
146150
-d Show logs in DEBUG mode
147151
-f string
148152
Path to server configuration file in YAML format
@@ -153,6 +157,8 @@ Options:
153157
Address of HTTP proxy server (default "127.0.0.1:8080")
154158
-logfile string
155159
Log file path (Default: stdout)
160+
-nocolor
161+
Disable colored output for logs (no effect if -j flag specified)
156162
-s string
157163
Address of SOCKS5 proxy server (default "127.0.0.1:1080")
158164
-sniff
@@ -430,6 +436,8 @@ ip link del veth1
430436
431437
`GoHPTS` proxy allows one to capture and monitor traffic that goes through the service. This procces is known as `traffic sniffing`, `packet sniffing` or just `sniffing`. In particular, proxy tries to identify whether it is a plain text (HTTP) or TLS traffic, and after identification is done, it parses request/response metadata and writes it to the file or console. In the case of `GoHTPS` proxy a parsed metadata looks like the following (TLS Handshake):
432438
439+
### JSON format
440+
433441
```json
434442
[
435443
{
@@ -551,16 +559,36 @@ And HTTP request with curl:
551559
Usage as simple as specifying `-sniff` flag along with regular flags
552560
553561
```shell
554-
gohpts -d -t 8888 -M redirect -sniff
562+
gohpts -d -t 8888 -M redirect -sniff -j
555563
```
556564
557565
You can also specify a file to which write sniffed traffic:
558566
559567
```shell
560-
gohpts -d -sniff -snifflog ~/sniff.log
568+
gohpts -sniff -snifflog ~/sniff.log -j
569+
```
570+
571+
### Colored format
572+
573+
You can see the example of colored output in the picture at the very top. In this mode, `GoHPTS` tries to highlight import information such as TLS Handshake, HTTP metadata, something that looks line login/passwords or different types of auth and secret tokens. The output is limited comparing to JSON but way easier to read for humans.
574+
575+
To run `GoHPTS` in this mode you use the following flags:
576+
577+
```shell
578+
gohpts -sniff -body
561579
```
562580
563-
Please note that for now sniffing only visible with `-d` flag, it may change in the future.
581+
You can combine sniffing with transparent mode:
582+
583+
```shell
584+
./gohpts -T 8888 -M redirect -sniff -body
585+
```
586+
587+
To disable colors add `-nocolor`:
588+
589+
```shell
590+
gohpts -sniff -body -nocolor
591+
```
564592
565593
## Links
566594

cmd/gohpts/cli.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ const (
1717
addrHTTP string = "127.0.0.1:8080"
1818
tproxyOS string = "linux"
1919
)
20-
const usagePrefix string = `
21-
_____ _ _ _____ _______ _____
20+
const usagePrefix string = ` _____ _ _ _____ _______ _____
2221
/ ____| | | | | __ \__ __/ ____|
2322
| | __ ___ | |__| | |__) | | | | (___
2423
| | |_ |/ _ \| __ | ___/ | | \___ \
@@ -61,7 +60,8 @@ func root(args []string) error {
6160
flags.BoolVar(&conf.Json, "j", false, "Show logs in JSON format")
6261
flags.BoolVar(&conf.Sniff, "sniff", false, "Enable traffic sniffing for HTTP and TLS")
6362
flags.StringVar(&conf.SniffLogFile, "snifflog", "", "Sniffed traffic log file path (Default: the same as -logfile)")
64-
flags.BoolVar(&conf.Color, "color", false, "Enable colored output for logs in stdout (no effect if log file provided or -j flag specified)")
63+
flags.BoolVar(&conf.NoColor, "nocolor", false, "Disable colored output for logs (no effect if -j flag specified)")
64+
flags.BoolVar(&conf.Body, "body", false, "Collect request and response body for HTTP sniffing")
6565
flags.BoolFunc("v", "print version", func(flagValue string) error {
6666
fmt.Printf("%s (built for %s %s with %s)\n", gohpts.Version, runtime.GOOS, runtime.GOARCH, runtime.Version())
6767
os.Exit(0)
@@ -83,7 +83,7 @@ func root(args []string) error {
8383
}
8484
if seen["t"] {
8585
if !seen["M"] {
86-
return fmt.Errorf("Transparent proxy mode is not provided: -M flag")
86+
return fmt.Errorf("transparent proxy mode is not provided: -M flag")
8787
}
8888
}
8989
if seen["T"] {
@@ -93,12 +93,12 @@ func root(args []string) error {
9393
}
9494
}
9595
if !seen["M"] {
96-
return fmt.Errorf("Transparent proxy mode is not provided: -M flag")
96+
return fmt.Errorf("transparent proxy mode is not provided: -M flag")
9797
}
9898
}
9999
if seen["M"] {
100100
if !seen["t"] && !seen["T"] {
101-
return fmt.Errorf("Transparent proxy mode requires -t or -T flag")
101+
return fmt.Errorf("transparent proxy mode requires -t or -T flag")
102102
}
103103
}
104104
if seen["f"] {
@@ -134,16 +134,16 @@ func root(args []string) error {
134134
conf.ServerPass = string(bytepw)
135135
fmt.Print("\033[2K\r")
136136
}
137-
if seen["sniff"] {
138-
if !seen["d"] {
139-
return fmt.Errorf("Traffic sniffing requires debug mode")
140-
}
141-
}
142137
if seen["snifflog"] {
143138
if !seen["sniff"] {
144139
return fmt.Errorf("-snifflog only works with -sniff flag")
145140
}
146141
}
142+
if seen["body"] {
143+
if !seen["sniff"] {
144+
return fmt.Errorf("-body only works with -sniff flag")
145+
}
146+
}
147147

148148
if *daemon {
149149
if os.Getenv("GOHPTS_DAEMON") != "1" {

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ go 1.24.1
44

55
require (
66
github.com/goccy/go-yaml v1.18.0
7+
github.com/google/uuid v1.6.0
78
github.com/rs/zerolog v1.34.0
9+
github.com/shadowy-pycoder/colors v0.0.1
810
github.com/shadowy-pycoder/mshark v0.0.4
911
golang.org/x/net v0.40.0
1012
golang.org/x/sys v0.33.0

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
44
github.com/goccy/go-yaml v1.18.0 h1:8W7wMFS12Pcas7KU+VVkaiCng+kG8QiFeFwzFb+rwuw=
55
github.com/goccy/go-yaml v1.18.0/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA=
66
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
7+
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
8+
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
79
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
810
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
911
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
@@ -15,6 +17,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
1517
github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0=
1618
github.com/rs/zerolog v1.34.0 h1:k43nTLIwcTVQAncfCw4KZ2VY6ukYoZaBPNOE8txlOeY=
1719
github.com/rs/zerolog v1.34.0/go.mod h1:bJsvje4Z08ROH4Nhs5iH600c3IkWhwp44iRc54W6wYQ=
20+
github.com/shadowy-pycoder/colors v0.0.1 h1:weCj/YIOupqy4BSP8KuVzr20fC+cuAv/tArz7bhhkP4=
21+
github.com/shadowy-pycoder/colors v0.0.1/go.mod h1:lkrJS1PY2oVigNLTT6pkbF7B/v0YcU2LD5PZnss1Q4U=
1822
github.com/shadowy-pycoder/mshark v0.0.4 h1:2yw6am1jt6n1GPHdLfFU1oDajv+zQ/23V0l0imFAeJY=
1923
github.com/shadowy-pycoder/mshark v0.0.4/go.mod h1:fRWGQuU4BFjz9pTfrvwIT2AtmWWd99PEvdlgv+24vTE=
2024
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=

0 commit comments

Comments
 (0)