From 2b8e1c698420b19f0c771d796dcbe90b6b66a191 Mon Sep 17 00:00:00 2001 From: Hawshemi Date: Sat, 2 Dec 2023 18:44:10 +0330 Subject: [PATCH 1/6] Update main.go --- main.go | 59 +++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 49 insertions(+), 10 deletions(-) diff --git a/main.go b/main.go index 0f6465c..ccba2b2 100644 --- a/main.go +++ b/main.go @@ -22,6 +22,7 @@ const ( defaultTimeout = 4 outPutDef = true outPutFileName = "results.txt" + domainsFileName = "domains.txt" showFailDef = false numIPsToCheck = 10000 workerPoolSize = 100 @@ -52,6 +53,7 @@ type Scanner struct { mu sync.Mutex ip net.IP logFile *os.File + domainFile *os.File // New file pointer for domains.txt dialer *net.Dialer logChan chan string } @@ -81,9 +83,40 @@ func (s *Scanner) Print(outStr string) { // Create the final log entry with IP alignment logEntry := formattedIP + rest + // Extract the domain from the log entry + domain := extractDomain(logEntry) + + // Save the domain to domains.txt + saveDomain(domain, s.domainFile) + s.logChan <- logEntry } +func extractDomain(logEntry string) string { + // Split the log entry into words + parts := strings.Fields(logEntry) + + // Search for a word that looks like a domain (contains a dot) + for i, part := range parts { + if strings.Contains(part, ".") && !strings.HasPrefix(part, "v") && i > 0 { + // Split the part using ":" and take the first part (domain) + domainParts := strings.Split(part, ":") + return domainParts[0] + } + } + + return "" +} + +func saveDomain(domain string, file *os.File) { + if domain != "" { + _, err := file.WriteString(domain + "\n") + if err != nil { + log.WithError(err).Error("Error writing domain into file") + } + } +} + func main() { addrPtr := flag.String("addr", defaultAddress, "Destination to start scan") portPtr := flag.String("port", defaultPort, "Port to scan") @@ -110,17 +143,23 @@ func main() { log.SetFormatter(&CustomTextFormatter{}) log.SetLevel(logrus.InfoLevel) // Set the desired log level - if *outPutFile { - var err error - s.logFile, err = os.OpenFile(outPutFileName, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0600) - - if err != nil { - log.WithError(err).Error("Failed to open log file") - return - } + // Open results.txt file for writing + var err error + s.logFile, err = os.OpenFile(outPutFileName, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0600) + if err != nil { + log.WithError(err).Error("Failed to open log file") + return + } + defer s.logFile.Close() - defer s.logFile.Close() + // Open domains.txt file for writing + s.domainFile, err = os.OpenFile(domainsFileName, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0600) + if err != nil { + log.WithError(err).Error("Failed to open domains.txt file") + return } + defer s.domainFile.Close() + go s.logWriter() // Create a buffered channel for IPs to scan @@ -246,7 +285,7 @@ func (s *Scanner) Scan(ip net.IP) { numPeriods := strings.Count(certSubject, ".") - if strings.HasPrefix(certSubject, "*") || certSubject == "localhost" || numPeriods != 1 || certSubject == "invalid2.invalid" { + if strings.HasPrefix(certSubject, "*") || certSubject == "localhost" || numPeriods != 1 || certSubject == "invalid2.invalid" || certSubject == "OPNsense.localdomain" { return } From f11dffb9d48f8eb2fb9575321129632b8fecf29e Mon Sep 17 00:00:00 2001 From: Hawshemi Date: Sat, 2 Dec 2023 18:45:19 +0330 Subject: [PATCH 2/6] Update README.md --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 2567afe..e9ba87b 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,11 @@ # SNI Finder +This script will scan all domains that have `TLS 1.3` and `h2` enabled on your VPS IP address range. These domains are useful for SNI in a variety of configurations and tests. + +When you begin the scan, two files are created: `results.txt` contains the output log, while `domains.txt` only contains the domain names. + +It is Recommended to run this scanner locally _(with you residential internet)_. It may cause VPS to be flagged if you run scanner in the cloud. + ## Run @@ -39,6 +45,8 @@ sudo apt install -y wget ``` 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 ``` +##### Reboot is recommended. + #### Then: From 3c4721540b5877f5ac8ed25bb2a7c1c3b212d46d Mon Sep 17 00:00:00 2001 From: Hawshemi Date: Sat, 2 Dec 2023 18:45:38 +0330 Subject: [PATCH 3/6] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e9ba87b..14aed02 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ sudo apt install -y wget ``` 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 ``` -##### Reboot is recommended. +- Reboot is recommended. #### Then: From 94e3414d0979d4d4798d526cb9c33e1721d5a8bb Mon Sep 17 00:00:00 2001 From: Hawshemi Date: Sat, 2 Dec 2023 18:47:18 +0330 Subject: [PATCH 4/6] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 14aed02..4bb6c97 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ It is Recommended to run this scanner locally _(with you residential internet)_. sudo apt install -y wget ``` -#### First run this script to install `Go` & other dependencies: +#### First run this script to install `Go` & other dependencies: _(Debian & Ubuntu)_ ``` 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 ``` From 4c899fdf6e9a85924b403acb52f46b32161b6498 Mon Sep 17 00:00:00 2001 From: Hawshemi Date: Sat, 2 Dec 2023 18:47:40 +0330 Subject: [PATCH 5/6] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4bb6c97..7a171e0 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ It is Recommended to run this scanner locally _(with you residential internet)_. sudo apt install -y wget ``` -#### First run this script to install `Go` & other dependencies: _(Debian & Ubuntu)_ +#### First run this script to install `Go` & other dependencies _(Debian & Ubuntu)_: ``` 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 ``` From c047b672b72b9d944c1f77e8a87e63dadcb7a561 Mon Sep 17 00:00:00 2001 From: Hawshemi Date: Sat, 2 Dec 2023 18:48:39 +0330 Subject: [PATCH 6/6] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7a171e0..3aac502 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ # SNI Finder -This script will scan all domains that have `TLS 1.3` and `h2` enabled on your VPS IP address range. These domains are useful for SNI in a variety of configurations and tests. +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. When you begin the scan, two files are created: `results.txt` contains the output log, while `domains.txt` only contains the domain names. -It is Recommended to run this scanner locally _(with you residential internet)_. It may cause VPS to be flagged if you run scanner in the cloud. +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. ## Run