Skip to content

Commit ca68a16

Browse files
juzeonyuhan6665
authored andcommitted
add origin host field
1 parent a4b6ded commit ca68a16

File tree

4 files changed

+63
-36
lines changed

4 files changed

+63
-36
lines changed

README.md

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,16 @@ Example stdout:
5656
Example output file:
5757

5858
```csv
59-
IP,DOMAIN,CERTIFICATE
60-
85.158.4.237,mirror.scaleuptech.com,"Let's Encrypt"
61-
193.224.218.31,mirror-r2z1.einfra.hu,"Sectigo Limited"
62-
103.77.111.8,repos.del.extreme-ix.org,"Let's Encrypt"
63-
103.56.39.228,*.nxtgen.com,"DigiCert Inc"
64-
103.77.111.8,repos.del.extreme-ix.org,"Let's Encrypt"
65-
45.125.0.6,xtom.com.hk,"ZeroSSL"
66-
196.200.160.70,mirror.marwan.ma,"Let's Encrypt"
67-
202.70.64.2,*.ntc.net.np,"GlobalSign nv-sa"
68-
5.79.108.33,mirror.leaseweb.com,"Let's Encrypt"
69-
78.142.193.130,xtom.nl,"ZeroSSL"
70-
194.127.172.131,nl.mirrors.clouvider.net,"Let's Encrypt"
71-
103.194.167.213,*.cdn.i3d.net,"Sectigo Limited"
72-
202.36.220.86,mirror.2degrees.nz,"Let's Encrypt"
59+
IP,ORIGIN,CERT_DOMAIN,CERT_ISSUER
60+
52.140.219.235,www.cherryservers.com,*.cherryservers.com,"GlobalSign nv-sa"
61+
172.66.40.234,veesp.com,veesp.com,"Cloudflare, Inc."
62+
172.66.43.22,veesp.com,veesp.com,"Cloudflare, Inc."
63+
193.1.193.205,www.heanet.ie,www.heanet.ie,"GEANT Vereniging"
64+
185.242.104.18,mirror.veesp.com,mirror.veesp.com,"Let's Encrypt"
65+
79.98.24.240,www.serveriai.lt,*.serveriai.lt,"Sectigo Limited"
66+
91.211.244.3,www.vpsnet.com,*.vpsnet.com,"Sectigo Limited"
67+
31.131.0.101,www.ihost.md,ihost.md,"Sectigo Limited"
68+
194.127.172.131,nl.mirrors.clouvider.net,nl.mirrors.clouvider.net,"Let's Encrypt"
69+
31.131.0.222,mirror.ihost.md,mirror.ihost.md,"Let's Encrypt"
7370
```
7471

main.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"flag"
55
"io"
66
"log/slog"
7-
"net"
87
"net/http"
98
"os"
109
"regexp"
@@ -62,20 +61,20 @@ func main() {
6261
return
6362
}
6463
defer f.Close()
65-
_, _ = f.WriteString("IP,DOMAIN,CERTIFICATE\n")
64+
_, _ = f.WriteString("IP,ORIGIN,CERT_DOMAIN,CERT_ISSUER\n")
6665
outWriter = f
6766
}
68-
var ipChan <-chan net.IP
67+
var hostChan <-chan Host
6968
if addr != "" {
70-
ipChan = Iterate(strings.NewReader(addr))
69+
hostChan = Iterate(strings.NewReader(addr))
7170
} else if in != "" {
7271
f, err := os.Open(in)
7372
if err != nil {
7473
slog.Error("Error reading file", "path", in)
7574
return
7675
}
7776
defer f.Close()
78-
ipChan = Iterate(f)
77+
hostChan = Iterate(f)
7978
} else {
8079
slog.Info("Fetching url...")
8180
resp, err := http.Get(url)
@@ -96,15 +95,15 @@ func main() {
9695
}
9796
domains = RemoveDuplicateStr(domains)
9897
slog.Info("Parsed domains", "count", len(domains))
99-
ipChan = Iterate(strings.NewReader(strings.Join(domains, "\n")))
98+
hostChan = Iterate(strings.NewReader(strings.Join(domains, "\n")))
10099
}
101100
outCh := OutWriter(outWriter)
102101
defer close(outCh)
103102
var wg sync.WaitGroup
104103
wg.Add(thread)
105104
for i := 0; i < thread; i++ {
106105
go func() {
107-
for ip := range ipChan {
106+
for ip := range hostChan {
108107
ScanTLS(ip, outCh)
109108
}
110109
wg.Done()

scanner.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ var TLSDictionary = map[uint16]string{
1616
0x0304: "1.3",
1717
}
1818

19-
func ScanTLS(ip net.IP, out chan<- string) {
20-
hostPort := net.JoinHostPort(ip.String(), strconv.Itoa(port))
19+
func ScanTLS(host Host, out chan<- string) {
20+
hostPort := net.JoinHostPort(host.IP.String(), strconv.Itoa(port))
2121
conn, err := net.DialTimeout("tcp", hostPort, time.Duration(timeout)*time.Second)
2222
if err != nil {
2323
slog.Debug("Cannot dial", "target", hostPort)
@@ -29,11 +29,15 @@ func ScanTLS(ip net.IP, out chan<- string) {
2929
slog.Error("Error setting deadline", "err", err)
3030
return
3131
}
32-
c := tls.Client(conn, &tls.Config{
32+
tlsCfg := &tls.Config{
3333
InsecureSkipVerify: true,
3434
NextProtos: []string{"h2", "http/1.1"},
3535
CurvePreferences: []tls.CurveID{tls.X25519},
36-
})
36+
}
37+
if host.Type == HostTypeDomain {
38+
tlsCfg.ServerName = host.Origin
39+
}
40+
c := tls.Client(conn, tlsCfg)
3741
err = c.Handshake()
3842
if err != nil {
3943
slog.Debug("TLS handshake failed", "target", hostPort)
@@ -50,9 +54,9 @@ func ScanTLS(ip net.IP, out chan<- string) {
5054
log = slog.Debug
5155
feasible = false
5256
} else {
53-
out <- strings.Join([]string{ip.String(), domain, "\"" + issuers + "\""}, ",") + "\n"
57+
out <- strings.Join([]string{host.IP.String(), host.Origin, domain, "\"" + issuers + "\""}, ",") + "\n"
5458
}
55-
log("Connected to target", "feasible", feasible, "host", ip.String(),
56-
"tls", TLSDictionary[state.Version],
57-
"alpn", alpn, "domain", domain, "issuer", issuers)
59+
log("Connected to target", "feasible", feasible, "ip", host.IP.String(),
60+
"origin", host.Origin,
61+
"tls", TLSDictionary[state.Version], "alpn", alpn, "cert-domain", domain, "cert-issuer", issuers)
5862
}

utils.go

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,26 @@ import (
1010
"strings"
1111
)
1212

13-
func Iterate(reader io.Reader) <-chan net.IP {
13+
const (
14+
_ = iota
15+
HostTypeIP
16+
HostTypeCIDR
17+
HostTypeDomain
18+
)
19+
20+
type HostType int
21+
22+
type Host struct {
23+
IP net.IP
24+
Origin string
25+
Type HostType
26+
}
27+
28+
func Iterate(reader io.Reader) <-chan Host {
1429
scanner := bufio.NewScanner(reader)
15-
ipChan := make(chan net.IP)
30+
hostChan := make(chan Host)
1631
go func() {
17-
defer close(ipChan)
32+
defer close(hostChan)
1833
for scanner.Scan() {
1934
line := strings.TrimSpace(scanner.Text())
2035
if line == "" {
@@ -23,7 +38,11 @@ func Iterate(reader io.Reader) <-chan net.IP {
2338
ip := net.ParseIP(line)
2439
if ip != nil && (ip.To4() != nil || enableIPv6) {
2540
// ip address
26-
ipChan <- ip
41+
hostChan <- Host{
42+
IP: ip,
43+
Origin: line,
44+
Type: HostTypeIP,
45+
}
2746
continue
2847
}
2948
_, _, err := net.ParseCIDR(line)
@@ -44,7 +63,11 @@ func Iterate(reader io.Reader) <-chan net.IP {
4463
}
4564
ip = net.ParseIP(addr.String())
4665
if ip != nil {
47-
ipChan <- ip
66+
hostChan <- Host{
67+
IP: ip,
68+
Origin: line,
69+
Type: HostTypeCIDR,
70+
}
4871
}
4972
addr = addr.Next()
5073
}
@@ -55,7 +78,11 @@ func Iterate(reader io.Reader) <-chan net.IP {
5578
// domain
5679
for _, ip = range ips {
5780
if ip.To4() != nil || enableIPv6 {
58-
ipChan <- ip
81+
hostChan <- Host{
82+
IP: ip,
83+
Origin: line,
84+
Type: HostTypeDomain,
85+
}
5986
}
6087
}
6188
continue
@@ -66,7 +93,7 @@ func Iterate(reader io.Reader) <-chan net.IP {
6693
slog.Error("Read file error", "err", err)
6794
}
6895
}()
69-
return ipChan
96+
return hostChan
7097
}
7198
func ExistOnlyOne(arr []string) bool {
7299
exist := false

0 commit comments

Comments
 (0)