Skip to content

Commit

Permalink
Update.
Browse files Browse the repository at this point in the history
Update.
  • Loading branch information
hawshemi authored Dec 2, 2023
2 parents 189a519 + c047b67 commit bd423ea
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 11 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# SNI Finder

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 your residential internet)_. It may cause VPS to be flagged if you run a scanner in the cloud.


## Run

Expand Down Expand Up @@ -35,10 +41,12 @@
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
```
- Reboot is recommended.
#### Then:
Expand Down
59 changes: 49 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const (
defaultTimeout = 4
outPutDef = true
outPutFileName = "results.txt"
domainsFileName = "domains.txt"
showFailDef = false
numIPsToCheck = 10000
workerPoolSize = 100
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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")
Expand All @@ -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
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit bd423ea

Please sign in to comment.