Skip to content

Commit bd423ea

Browse files
authored
Update.
Update.
2 parents 189a519 + c047b67 commit bd423ea

File tree

2 files changed

+58
-11
lines changed

2 files changed

+58
-11
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# SNI Finder
22

3+
This script will scan all domains with `TLS 1.3` and `h2` enabled on your VPS IP address range. These domains are useful for SNI domain names in various configurations and tests.
4+
5+
When you begin the scan, two files are created: `results.txt` contains the output log, while `domains.txt` only contains the domain names.
6+
7+
It is recommended to run this scanner locally _(with your residential internet)_. It may cause VPS to be flagged if you run a scanner in the cloud.
8+
39

410
## Run
511

@@ -35,10 +41,12 @@
3541
sudo apt install -y wget
3642
```
3743
38-
#### First run this script to install `Go` & other dependencies:
44+
#### First run this script to install `Go` & other dependencies _(Debian & Ubuntu)_:
3945
```
4046
wget "https://raw.githubusercontent.com/hawshemi/SNI-Finder/main/install-go.sh" -O install-go.sh && chmod +x install-go.sh && bash install-go.sh
4147
```
48+
- Reboot is recommended.
49+
4250
4351
#### Then:
4452

main.go

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const (
2222
defaultTimeout = 4
2323
outPutDef = true
2424
outPutFileName = "results.txt"
25+
domainsFileName = "domains.txt"
2526
showFailDef = false
2627
numIPsToCheck = 10000
2728
workerPoolSize = 100
@@ -52,6 +53,7 @@ type Scanner struct {
5253
mu sync.Mutex
5354
ip net.IP
5455
logFile *os.File
56+
domainFile *os.File // New file pointer for domains.txt
5557
dialer *net.Dialer
5658
logChan chan string
5759
}
@@ -81,9 +83,40 @@ func (s *Scanner) Print(outStr string) {
8183
// Create the final log entry with IP alignment
8284
logEntry := formattedIP + rest
8385

86+
// Extract the domain from the log entry
87+
domain := extractDomain(logEntry)
88+
89+
// Save the domain to domains.txt
90+
saveDomain(domain, s.domainFile)
91+
8492
s.logChan <- logEntry
8593
}
8694

95+
func extractDomain(logEntry string) string {
96+
// Split the log entry into words
97+
parts := strings.Fields(logEntry)
98+
99+
// Search for a word that looks like a domain (contains a dot)
100+
for i, part := range parts {
101+
if strings.Contains(part, ".") && !strings.HasPrefix(part, "v") && i > 0 {
102+
// Split the part using ":" and take the first part (domain)
103+
domainParts := strings.Split(part, ":")
104+
return domainParts[0]
105+
}
106+
}
107+
108+
return ""
109+
}
110+
111+
func saveDomain(domain string, file *os.File) {
112+
if domain != "" {
113+
_, err := file.WriteString(domain + "\n")
114+
if err != nil {
115+
log.WithError(err).Error("Error writing domain into file")
116+
}
117+
}
118+
}
119+
87120
func main() {
88121
addrPtr := flag.String("addr", defaultAddress, "Destination to start scan")
89122
portPtr := flag.String("port", defaultPort, "Port to scan")
@@ -110,17 +143,23 @@ func main() {
110143
log.SetFormatter(&CustomTextFormatter{})
111144
log.SetLevel(logrus.InfoLevel) // Set the desired log level
112145

113-
if *outPutFile {
114-
var err error
115-
s.logFile, err = os.OpenFile(outPutFileName, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0600)
116-
117-
if err != nil {
118-
log.WithError(err).Error("Failed to open log file")
119-
return
120-
}
146+
// Open results.txt file for writing
147+
var err error
148+
s.logFile, err = os.OpenFile(outPutFileName, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0600)
149+
if err != nil {
150+
log.WithError(err).Error("Failed to open log file")
151+
return
152+
}
153+
defer s.logFile.Close()
121154

122-
defer s.logFile.Close()
155+
// Open domains.txt file for writing
156+
s.domainFile, err = os.OpenFile(domainsFileName, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0600)
157+
if err != nil {
158+
log.WithError(err).Error("Failed to open domains.txt file")
159+
return
123160
}
161+
defer s.domainFile.Close()
162+
124163
go s.logWriter()
125164

126165
// Create a buffered channel for IPs to scan
@@ -246,7 +285,7 @@ func (s *Scanner) Scan(ip net.IP) {
246285

247286
numPeriods := strings.Count(certSubject, ".")
248287

249-
if strings.HasPrefix(certSubject, "*") || certSubject == "localhost" || numPeriods != 1 || certSubject == "invalid2.invalid" {
288+
if strings.HasPrefix(certSubject, "*") || certSubject == "localhost" || numPeriods != 1 || certSubject == "invalid2.invalid" || certSubject == "OPNsense.localdomain" {
250289
return
251290
}
252291

0 commit comments

Comments
 (0)