13 func testSni(ip
string, config
*ScanConfig
, record
*ScanRecord
) bool {
14 tlscfg
:= &tls
.Config
{
15 InsecureSkipVerify
: true,
19 if len(config
.HTTPVerifyHosts
) == 0 {
22 Host
= config
.HTTPVerifyHosts
[rand
.Intn(len(config
.HTTPVerifyHosts
))]
24 if len(config
.VerifyCommonName
) == 0 {
25 VerifyCN
= randomHost()
27 VerifyCN
= config
.VerifyCommonName
[rand
.Intn(len(config
.VerifyCommonName
))]
29 for _
, serverName
:= range config
.ServerName
{
31 conn
, err
:= net
.DialTimeout("tcp", net
.JoinHostPort(ip
, "443"), config
.ScanMaxRTT
)
36 tlscfg
.ServerName
= serverName
37 tlsconn
:= tls
.Client(conn
, tlscfg
)
38 tlsconn
.SetDeadline(time
.Now().Add(config
.HandshakeTimeout
))
39 if err
= tlsconn
.Handshake(); err
!= nil {
44 pcs
:= tlsconn
.ConnectionState().PeerCertificates
45 if len(pcs
) == 0 || pcs
[0].Subject
.CommonName
!= VerifyCN
{
46 fmt
.Println("CN: %s", pcs
[0].Subject
.CommonName
)
52 req
, err
:= http
.NewRequest(http
.MethodHead
, "https://"+serverName
, nil)
53 req
.Header
.Add("Host", Host
)
58 tlsconn
.SetDeadline(time
.Now().Add(config
.ScanMaxRTT
- time
.Since(start
)))
59 resp
, err
:= httputil
.NewClientConn(tlsconn
, nil).Do(req
)
64 // io.Copy(os.Stdout, resp.Body)
65 // if resp.Body != nil {
66 // io.Copy(ioutil.Discard, resp.Body)
69 if resp
.StatusCode
!= 404 {
77 rtt
:= time
.Since(start
)
78 if rtt
< config
.ScanMinRTT
{