Skip to content

Commit a409255

Browse files
Added basic logic for http body hadnling and logging colorizarion
1 parent 9d9fa10 commit a409255

File tree

6 files changed

+324
-71
lines changed

6 files changed

+324
-71
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ You can download the binary for your platform from [Releases](https://github.com
9393
Example:
9494

9595
```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
96+
HPTS_RELEASE=v1.7.3; 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
9797
```
9898

9999
Alternatively, you can install it using `go install` command (requires Go [1.24](https://go.dev/doc/install) or later):
@@ -139,10 +139,10 @@ Options:
139139
Address of transparent proxy server (no HTTP)
140140
-U string
141141
User for HTTP proxy (basic auth). This flag invokes prompt for password (not echoed to terminal)
142+
-body
143+
Collect request and response body for HTTP sniffing
142144
-c string
143145
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)
146146
-d Show logs in DEBUG mode
147147
-f string
148148
Path to server configuration file in YAML format
@@ -153,6 +153,8 @@ Options:
153153
Address of HTTP proxy server (default "127.0.0.1:8080")
154154
-logfile string
155155
Log file path (Default: stdout)
156+
-nocolor
157+
Disable colored output for logs in stdout (no effect if log file provided or -j flag specified)
156158
-s string
157159
Address of SOCKS5 proxy server (default "127.0.0.1:1080")
158160
-sniff
@@ -560,8 +562,6 @@ You can also specify a file to which write sniffed traffic:
560562
gohpts -d -sniff -snifflog ~/sniff.log
561563
```
562564
563-
Please note that for now sniffing only visible with `-d` flag, it may change in the future.
564-
565565
## Links
566566
567567
[[Back]](#table-of-contents)

cmd/gohpts/cli.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ func root(args []string) error {
6161
flags.BoolVar(&conf.Json, "j", false, "Show logs in JSON format")
6262
flags.BoolVar(&conf.Sniff, "sniff", false, "Enable traffic sniffing for HTTP and TLS")
6363
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)")
64+
flags.BoolVar(&conf.NoColor, "nocolor", false, "Disable colored output for logs in stdout (no effect if log file provided or -j flag specified)")
65+
flags.BoolVar(&conf.Body, "body", false, "Collect request and response body for HTTP sniffing")
6566
flags.BoolFunc("v", "print version", func(flagValue string) error {
6667
fmt.Printf("%s (built for %s %s with %s)\n", gohpts.Version, runtime.GOOS, runtime.GOARCH, runtime.Version())
6768
os.Exit(0)
@@ -134,16 +135,16 @@ func root(args []string) error {
134135
conf.ServerPass = string(bytepw)
135136
fmt.Print("\033[2K\r")
136137
}
137-
if seen["sniff"] {
138-
if !seen["d"] {
139-
return fmt.Errorf("Traffic sniffing requires debug mode")
140-
}
141-
}
142138
if seen["snifflog"] {
143139
if !seen["sniff"] {
144140
return fmt.Errorf("-snifflog only works with -sniff flag")
145141
}
146142
}
143+
if seen["body"] {
144+
if !seen["sniff"] {
145+
return fmt.Errorf("-body only works with -sniff flag")
146+
}
147+
}
147148

148149
if *daemon {
149150
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)