12 func testSni(ip
string, config
*ScanConfig
, record
*ScanRecord
) bool {
13 tlscfg
:= &tls
.Config
{
14 InsecureSkipVerify
: true,
16 tr
:= &http
.Transport
{
17 TLSClientConfig
: tlscfg
,
18 ResponseHeaderTimeout
: config
.ScanMaxRTT
,
20 httpconn
:= &http
.Client
{
21 CheckRedirect
: func(req
*http
.Request
, via
[]*http
.Request
) error
{
22 return http
.ErrUseLastResponse
30 if len(config
.HTTPVerifyHosts
) == 0 {
33 Host
= config
.HTTPVerifyHosts
[rand
.Intn(len(config
.HTTPVerifyHosts
))]
35 VerifyCN
= config
.VerifyCommonName
36 Code
= config
.ValidStatusCode
37 Path
= config
.HTTPPath
39 for _
, serverName
:= range config
.ServerName
{
41 conn
, err
:= net
.DialTimeout("tcp", net
.JoinHostPort(ip
, "443"), config
.ScanMaxRTT
)
46 tlscfg
.ServerName
= serverName
47 tlsconn
:= tls
.Client(conn
, tlscfg
)
48 tlsconn
.SetDeadline(time
.Now().Add(config
.HandshakeTimeout
))
49 if err
= tlsconn
.Handshake(); err
!= nil {
54 pcs
:= tlsconn
.ConnectionState().PeerCertificates
55 if len(pcs
) == 0 || pcs
[0].Subject
.CommonName
!= VerifyCN
{
56 fmt
.Println("CN:", pcs
[0].Subject
.CommonName
)
62 req
, err
:= http
.NewRequest(http
.MethodHead
, "https://"+ip
+Path
, nil)
66 //fmt.Println("build req error")
69 tlsconn
.SetDeadline(time
.Now().Add(config
.ScanMaxRTT
- time
.Since(start
)))
70 //resp, err := httputil.NewClientConn(tlsconn, nil).Do(req)
71 resp
, err
:= httpconn
.Do(req
)
73 //fmt.Println("httpconn error")
78 // io.Copy(os.Stdout, resp.Body)
79 // if resp.Body != nil {
80 // io.Copy(ioutil.Discard, resp.Body)
83 if resp
.StatusCode
!= Code
{
84 fmt
.Println("Status Code:", resp
.StatusCode
)
91 httpconn
.CloseIdleConnections()
93 rtt
:= time
.Since(start
)
94 if rtt
< config
.ScanMinRTT
{