Files
dependabot[bot] f973821811 chore(deps): bump the modules group with 7 updates (#2216)
* chore(deps): bump the modules group with 7 updates

Bumps the modules group with 7 updates:

| Package | From | To |
| --- | --- | --- |
| [github.com/projectdiscovery/cdncheck](https://github.com/projectdiscovery/cdncheck) | `1.1.27` | `1.1.28` |
| [github.com/projectdiscovery/fastdialer](https://github.com/projectdiscovery/fastdialer) | `0.4.1` | `0.4.2` |
| [github.com/projectdiscovery/networkpolicy](https://github.com/projectdiscovery/networkpolicy) | `0.1.17` | `0.1.18` |
| [github.com/projectdiscovery/retryablehttp-go](https://github.com/projectdiscovery/retryablehttp-go) | `1.0.117` | `1.0.118` |
| [github.com/projectdiscovery/tlsx](https://github.com/projectdiscovery/tlsx) | `1.1.9` | `1.2.0` |
| [github.com/projectdiscovery/utils](https://github.com/projectdiscovery/utils) | `0.4.21` | `0.4.22` |
| [github.com/projectdiscovery/wappalyzergo](https://github.com/projectdiscovery/wappalyzergo) | `0.2.37` | `0.2.38` |


Updates `github.com/projectdiscovery/cdncheck` from 1.1.27 to 1.1.28
- [Release notes](https://github.com/projectdiscovery/cdncheck/releases)
- [Changelog](https://github.com/projectdiscovery/cdncheck/blob/main/.goreleaser.yaml)
- [Commits](https://github.com/projectdiscovery/cdncheck/compare/v1.1.27...v1.1.28)

Updates `github.com/projectdiscovery/fastdialer` from 0.4.1 to 0.4.2
- [Release notes](https://github.com/projectdiscovery/fastdialer/releases)
- [Commits](https://github.com/projectdiscovery/fastdialer/compare/v0.4.1...v0.4.2)

Updates `github.com/projectdiscovery/networkpolicy` from 0.1.17 to 0.1.18
- [Release notes](https://github.com/projectdiscovery/networkpolicy/releases)
- [Commits](https://github.com/projectdiscovery/networkpolicy/compare/v0.1.17...v0.1.18)

Updates `github.com/projectdiscovery/retryablehttp-go` from 1.0.117 to 1.0.118
- [Release notes](https://github.com/projectdiscovery/retryablehttp-go/releases)
- [Commits](https://github.com/projectdiscovery/retryablehttp-go/compare/v1.0.117...v1.0.118)

Updates `github.com/projectdiscovery/tlsx` from 1.1.9 to 1.2.0
- [Release notes](https://github.com/projectdiscovery/tlsx/releases)
- [Changelog](https://github.com/projectdiscovery/tlsx/blob/main/.goreleaser.yml)
- [Commits](https://github.com/projectdiscovery/tlsx/compare/v1.1.9...v1.2.0)

Updates `github.com/projectdiscovery/utils` from 0.4.21 to 0.4.22
- [Release notes](https://github.com/projectdiscovery/utils/releases)
- [Changelog](https://github.com/projectdiscovery/utils/blob/main/CHANGELOG.md)
- [Commits](https://github.com/projectdiscovery/utils/compare/v0.4.21...v0.4.22)

Updates `github.com/projectdiscovery/wappalyzergo` from 0.2.37 to 0.2.38
- [Release notes](https://github.com/projectdiscovery/wappalyzergo/releases)
- [Commits](https://github.com/projectdiscovery/wappalyzergo/compare/v0.2.37...v0.2.38)

---
updated-dependencies:
- dependency-name: github.com/projectdiscovery/cdncheck
  dependency-version: 1.1.28
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: modules
- dependency-name: github.com/projectdiscovery/fastdialer
  dependency-version: 0.4.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: modules
- dependency-name: github.com/projectdiscovery/networkpolicy
  dependency-version: 0.1.18
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: modules
- dependency-name: github.com/projectdiscovery/retryablehttp-go
  dependency-version: 1.0.118
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: modules
- dependency-name: github.com/projectdiscovery/tlsx
  dependency-version: 1.2.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: modules
- dependency-name: github.com/projectdiscovery/utils
  dependency-version: 0.4.22
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: modules
- dependency-name: github.com/projectdiscovery/wappalyzergo
  dependency-version: 0.2.38
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: modules
...

Signed-off-by: dependabot[bot] <support@github.com>

* lint

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Mzack9999 <mzack9999@protonmail.com>
2025-07-22 13:27:25 +05:30

118 lines
3.6 KiB
Go

package httpx
import (
"context"
"crypto/tls"
"crypto/x509"
"fmt"
"net"
"net/http"
"github.com/projectdiscovery/tlsx/pkg/tlsx/clients"
"github.com/projectdiscovery/tlsx/pkg/tlsx/ztls"
zmaptls "github.com/zmap/zcrypto/tls"
)
// versionToTLSVersionString converts tls version to version string
var versionToTLSVersionString = map[uint16]string{
tls.VersionTLS10: "tls10",
tls.VersionTLS11: "tls11",
tls.VersionTLS12: "tls12",
tls.VersionTLS13: "tls13",
}
// TLSGrab fills the TLSData
func (h *HTTPX) TLSGrab(r *http.Response) *clients.Response {
if r.TLS == nil || len(r.TLS.PeerCertificates) == 0 {
return nil
}
host := r.Request.URL.Host
hostname, port, _ := net.SplitHostPort(host)
if hostname == "" {
hostname = host
}
if port == "" {
port = "443"
}
tlsVersion := versionToTLSVersionString[r.TLS.Version]
tlsCipher := tls.CipherSuiteName(r.TLS.CipherSuite)
leafCertificate := r.TLS.PeerCertificates[0]
response := &clients.Response{
Host: hostname,
ProbeStatus: true,
Port: port,
Version: tlsVersion,
Cipher: tlsCipher,
TLSConnection: "ctls",
CertificateResponse: convertCertificateToResponse(hostname, leafCertificate),
ServerName: r.TLS.ServerName,
}
return response
}
func (h *HTTPX) ZTLSGrab(r *http.Response) *clients.Response {
host := r.Request.URL.Host
hostname, port, _ := net.SplitHostPort(host)
if hostname == "" {
hostname = host
}
if port == "" {
port = "443"
}
// canonical net concatenation
host = net.JoinHostPort(hostname, fmt.Sprint(port))
ctx, cancel := context.WithTimeout(context.Background(), h.Options.Timeout)
defer cancel()
tlsConn, err := h.Dialer.DialTLS(ctx, "tcp", host)
if err != nil {
return nil
}
ztlsConn, ok := (tlsConn).(*zmaptls.Conn)
if !ok {
return nil
}
ztlsState := ztlsConn.ConnectionState()
if len(ztlsState.PeerCertificates) == 0 {
return nil
}
response := &clients.Response{
Host: hostname,
ProbeStatus: true,
Port: port,
Version: versionToTLSVersionString[ztlsState.Version],
Cipher: tls.CipherSuiteName(ztlsState.CipherSuite),
TLSConnection: "ztls",
CertificateResponse: ztls.ConvertCertificateToResponse(&clients.Options{}, hostname, ztlsState.PeerCertificates[0]),
ServerName: ztlsState.ServerName,
}
return response
}
func convertCertificateToResponse(hostname string, cert *x509.Certificate) *clients.CertificateResponse {
response := &clients.CertificateResponse{
SubjectAN: cert.DNSNames,
Emails: cert.EmailAddresses,
NotBefore: cert.NotBefore,
NotAfter: cert.NotAfter,
Expired: clients.IsExpired(cert.NotAfter),
SelfSigned: clients.IsSelfSigned(cert.AuthorityKeyId, cert.SubjectKeyId, cert.DNSNames),
MisMatched: clients.IsMisMatchedCert(hostname, append(cert.DNSNames, cert.Subject.CommonName)),
WildCardCert: clients.IsWildCardCert(append(cert.DNSNames, cert.Subject.CommonName)),
IssuerCN: cert.Issuer.CommonName,
IssuerOrg: cert.Issuer.Organization,
SubjectCN: cert.Subject.CommonName,
SubjectOrg: cert.Subject.Organization,
FingerprintHash: clients.CertificateResponseFingerprintHash{
MD5: clients.MD5Fingerprint(cert.Raw),
SHA1: clients.SHA1Fingerprint(cert.Raw),
SHA256: clients.SHA256Fingerprint(cert.Raw),
},
Serial: clients.FormatToSerialNumber(cert.SerialNumber),
}
response.IssuerDN = clients.ParseASN1DNSequenceWithZpkixOrDefault(cert.RawIssuer, cert.Issuer.String())
response.SubjectDN = clients.ParseASN1DNSequenceWithZpkixOrDefault(cert.RawSubject, cert.Subject.String())
return response
}