Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write Keylog File - TLS Debugging #265

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions hey.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ var (
authHeader = flag.String("a", "", "")
hostHeader = flag.String("host", "", "")
userAgent = flag.String("U", "", "")
keyLogFile = flag.String("k", "", "")

output = flag.String("o", "", "")

Expand Down Expand Up @@ -92,6 +93,7 @@ Options:
-a Basic authentication, username:password.
-x HTTP Proxy address as host:port.
-h2 Enable HTTP/2.
-k Enable keylog writer for decrypting TLS in a network traffic capture. INSECURE; only used for debugging. Example: -k <file>

-host HTTP Host header.

Expand Down Expand Up @@ -232,6 +234,7 @@ func main() {
DisableKeepAlives: *disableKeepAlives,
DisableRedirects: *disableRedirects,
H2: *h2,
KeyLogFile: *keyLogFile,
ProxyAddr: proxyURL,
Output: *output,
}
Expand Down
19 changes: 19 additions & 0 deletions requester/requester.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"crypto/tls"
"io"
"io/ioutil"
"log"
"net/http"
"net/http/httptrace"
"net/url"
Expand Down Expand Up @@ -66,6 +67,9 @@ type Work struct {
// H2 is an option to make HTTP/2 requests
H2 bool

// Log to a keylog file to allow the user to decrypt TLS traffic in a network packet capture
KeyLogFile string

// Timeout in seconds.
Timeout int

Expand Down Expand Up @@ -235,10 +239,25 @@ func (b *Work) runWorkers() {
var wg sync.WaitGroup
wg.Add(b.C)

var keyLogWriter io.Writer
if b.KeyLogFile != "" {
log.Printf("!!!!! WARNING !!!!! Logging TLS secrets to %v. Your TLS traffic can be decrypted with this file.", b.KeyLogFile)

var err error
// Append so that you can run `hey` multiple times and still log to a single keyfile
keyLogWriter, err = os.OpenFile(b.KeyLogFile, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0600)

if err != nil {
log.Fatalf("Failed to open keylog file for writing: %v", err)
os.Exit(1)
}
}

tr := &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
ServerName: b.Request.Host,
KeyLogWriter: keyLogWriter,
},
MaxIdleConnsPerHost: min(b.C, maxIdleConn),
DisableCompression: b.DisableCompression,
Expand Down