From 9b9dcc58895e9007253caad16b032c9396c23d15 Mon Sep 17 00:00:00 2001 From: Mzack9999 Date: Thu, 23 Jul 2020 14:17:19 +0200 Subject: [PATCH] automatic tls data extraction for https protocol --- cmd/httpx/httpx.go | 22 +++++++++++++++++----- common/httpx/httpx.go | 3 +++ common/httpx/response.go | 1 + common/httpx/tls.go | 30 ++++++++++++++++++++++++++++++ 4 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 common/httpx/tls.go diff --git a/cmd/httpx/httpx.go b/cmd/httpx/httpx.go index 5ed0d35..57de7cd 100644 --- a/cmd/httpx/httpx.go +++ b/cmd/httpx/httpx.go @@ -316,7 +316,18 @@ retry: } } - output <- Result{URL: fullURL, ContentLength: resp.ContentLength, StatusCode: resp.StatusCode, Title: title, str: builder.String(), VHost: isvhost, WebServer: serverHeader, Response: serverResponseRaw, WebSocket: isWebSocket} + output <- Result{ + URL: fullURL, + ContentLength: resp.ContentLength, + StatusCode: resp.StatusCode, + Title: title, + str: builder.String(), + VHost: isvhost, + WebServer: serverHeader, + Response: serverResponseRaw, + WebSocket: isWebSocket, + TlsData: resp.TlsData, + } } // Result of a scan @@ -327,10 +338,11 @@ type Result struct { Title string `json:"title"` str string err error - VHost bool `json:"vhost"` - WebServer string `json:"webserver"` - Response string `json:"serverResponse,omitempty"` - WebSocket bool `json:"websocket,omitempty"` + VHost bool `json:"vhost"` + WebServer string `json:"webserver"` + Response string `json:"serverResponse,omitempty"` + WebSocket bool `json:"websocket,omitempty"` + TlsData *httpx.TlsData `json:"tls,omitempty"` } // JSON the result diff --git a/common/httpx/httpx.go b/common/httpx/httpx.go index e81b2fb..002d31c 100644 --- a/common/httpx/httpx.go +++ b/common/httpx/httpx.go @@ -134,6 +134,9 @@ func (h *HTTPX) Do(req *retryablehttp.Request) (*Response, error) { // number of lines resp.Lines = len(strings.Split(respbodystr, "\n")) + // extracts TLS data if any + resp.TlsData = h.TlsGrab(httpresp) + return &resp, nil } diff --git a/common/httpx/response.go b/common/httpx/response.go index 819542b..bb7f358 100644 --- a/common/httpx/response.go +++ b/common/httpx/response.go @@ -13,6 +13,7 @@ type Response struct { Raw string Words int Lines int + TlsData *TlsData } // GetHeader value diff --git a/common/httpx/tls.go b/common/httpx/tls.go new file mode 100644 index 0000000..a67ef6c --- /dev/null +++ b/common/httpx/tls.go @@ -0,0 +1,30 @@ +package httpx + +import ( + "net/http" +) + +type TlsData struct { + DNSNames []string `json:"dns_names,omitempty"` + Emails []string `json:"emails,omitempty"` + CommonName []string `json:"common_name,omitempty"` + Organization []string `json:"organization,omitempty"` + IssuerCommonName []string `json:"issuer_common_name,omitempty"` + IssuerOrg []string `json:"issuer_organization,omitempty"` +} + +func (h *HTTPX) TlsGrab(r *http.Response) *TlsData { + if r.TLS != nil { + var tlsdata TlsData + for _, certificate := range r.TLS.PeerCertificates { + tlsdata.DNSNames = append(tlsdata.DNSNames, certificate.DNSNames...) + tlsdata.Emails = append(tlsdata.Emails, certificate.EmailAddresses...) + tlsdata.CommonName = append(tlsdata.CommonName, certificate.Subject.CommonName) + tlsdata.Organization = append(tlsdata.Organization, certificate.Subject.Organization...) + tlsdata.IssuerOrg = append(tlsdata.IssuerOrg, certificate.Issuer.Organization...) + tlsdata.IssuerCommonName = append(tlsdata.IssuerCommonName, certificate.Issuer.CommonName) + } + return &tlsdata + } + return nil +}