├── go.mod ├── README.md ├── .gitignore └── hakfindinternaldomains.go /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/hakluke/hakfindinternaldomains 2 | 3 | go 1.16 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # hakfindinternaldomains 2 | Feed it a list of subdomains, it will resolve them and tell you which ones are internal 3 | 4 | # Installation 5 | 6 | ``` 7 | go install github.com/hakluke/hakfindinternaldomains 8 | ``` 9 | 10 | # Usage 11 | 12 | ``` 13 | cat subdomains.txt | hakfindinternaldomains -t 50 14 | ``` 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries for programs and plugins 2 | *.exe 3 | *.exe~ 4 | *.dll 5 | *.so 6 | *.dylib 7 | 8 | # Test binary, built with `go test -c` 9 | *.test 10 | 11 | # Output of the go coverage tool, specifically when used with LiteIDE 12 | *.out 13 | 14 | # Dependency directories (remove the comment below to include it) 15 | # vendor/ 16 | -------------------------------------------------------------------------------- /hakfindinternaldomains.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bufio" 5 | "flag" 6 | "fmt" 7 | "log" 8 | "net" 9 | "os" 10 | "sync" 11 | ) 12 | 13 | func main() { 14 | concurrencyPtr := flag.Int("t", 8, "Number of threads to utilise. Default is 8.") 15 | flag.Parse() 16 | // Taken from https://datatracker.ietf.org/doc/html/rfc5735 17 | cidr_strings := []string{ 18 | "0.0.0.0/8", // "This" Network RFC 1122, Section 3.2.1.3 19 | "10.0.0.0/8", // Private-Use Networks RFC 1918 20 | "127.0.0.0/8", // Loopback RFC 1122, Section 3.2.1.3 21 | "169.254.0.0/16", // Link Local RFC 3927 22 | "172.16.0.0/12", // Private-Use Networks RFC 1918 23 | "192.0.0.0/24", // IETF Protocol Assignments RFC 5736 24 | "192.0.2.0/24", // TEST-NET-1 RFC 5737 25 | "192.88.99.0/24", // 6to4 Relay Anycast RFC 3068 26 | "192.168.0.0/16", // Private-Use Networks RFC 1918 27 | "198.18.0.0/15", // Network Interconnect 28 | "198.51.100.0/24", // TEST-NET-2 RFC 5737 29 | "203.0.113.0/24", // TEST-NET-3 RFC 5737 30 | "224.0.0.0/4", // Multicast RFC 3171 31 | "240.0.0.0/4", // Reserved for Future Use RFC 1112, Section 4 32 | "255.255.255.255/32", // Limited Broadcast RFC 919, Section 7 33 | } 34 | cidrs := make([]net.IPNet, 15) 35 | for _, cidr_str := range cidr_strings { 36 | _, cidr, _ := net.ParseCIDR(cidr_str) 37 | cidrs = append(cidrs, *cidr) 38 | } 39 | 40 | work := make(chan string) 41 | go func() { 42 | s := bufio.NewScanner(os.Stdin) 43 | for s.Scan() { 44 | work <- s.Text() 45 | } 46 | close(work) 47 | }() 48 | 49 | wg := &sync.WaitGroup{} 50 | 51 | for i := 0; i < *concurrencyPtr; i++ { 52 | wg.Add(1) 53 | 54 | go doWork(work, wg, cidrs) 55 | } 56 | wg.Wait() 57 | } 58 | 59 | func doWork(work chan string, wg *sync.WaitGroup, cidrs []net.IPNet) { 60 | defer wg.Done() 61 | for text := range work { 62 | ip, err := net.LookupIP(text) 63 | if err != nil { 64 | log.Println("DNS resolve failed:", err) 65 | } 66 | for _, cidr := range cidrs { 67 | if len(ip) == 0 { 68 | continue 69 | } 70 | if cidr.Contains(ip[0]) { 71 | fmt.Println(text, ip) 72 | } 73 | } 74 | } 75 | } 76 | --------------------------------------------------------------------------------