From 9b7bd2aa38ab0c33a1216c7d6d96692f7d03e03e Mon Sep 17 00:00:00 2001 From: Borja Date: Wed, 19 Jul 2023 16:57:32 +0200 Subject: [PATCH] Added support for custom port specifications by setting the -p as custom and providing a path to a text file on the -l flag we can read custom lists of ports separated by new lines. This is useful when we are testing against non common http ports or ports that are not in the already existing lists. e.g. $ echo "127.0.0.1" | ./httprobe -p custom -l ./ports.txt -prefer-https http://127.0.0.1:8443 http://127.0.0.1:8442 http://127.0.0.1 Where ports.txt is a file with different ports , one on every line: 80 81 82 83 8440 8441 8442 8443 8444 --- main.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/main.go b/main.go index 60e5004..a44933a 100644 --- a/main.go +++ b/main.go @@ -10,6 +10,7 @@ import ( "net" "net/http" "os" + "log" "strings" "sync" "time" @@ -36,6 +37,10 @@ func main() { var probes probeArgs flag.Var(&probes, "p", "add additional probe (proto:port)") + // custom probe location flag + var customPath string + flag.StringVar(&customPath, "l", "" ,"Path to the custom port list file") + // skip default probes flag var skipDefault bool flag.BoolVar(&skipDefault, "s", false, "skip the default probes (http:80 and https:443)") @@ -177,6 +182,29 @@ func main() { for _, port := range large { httpsURLs <- fmt.Sprintf("%s:%s", domain, port) } + case "custom": + if customPath != "" { + if _, err := os.Stat(customPath); err == nil { + file, err := os.Open(customPath) + if err != nil { + log.Printf("Error opening file: %s , did you provide a file path on the -l flag?", err) + break + } + defer file.Close() + scanner := bufio.NewScanner(file) + for scanner.Scan() { + port := scanner.Text() + httpsURLs <- fmt.Sprintf("%s:%s", domain, port) + } + if err := scanner.Err(); err != nil { + log.Printf("Error reading file: %s", err) + } + } else { + log.Printf("Custom file %s not found.", customPath) + } + } else { + log.Println("Custom file path is not provided.") + } default: pair := strings.SplitN(p, ":", 2) if len(pair) != 2 {