request refusal checking, usage changes, cleanup

This commit is contained in:
delorean 2023-12-15 20:31:26 -06:00
parent 82f49eb78e
commit aea4670c9c
2 changed files with 50 additions and 20 deletions

View File

@ -27,9 +27,9 @@ func (m *multiflag) Set(value string) error {
} }
var ( var (
domain = flag.String("t", "", "domain to query") domain = flag.String("t", "", "")
workers = flag.Int("c", 100, "number of workers") workers = flag.Int("c", 100, "")
delay = flag.Int("s", 100, "delay (sleep) between queries in milliseconds") delay = flag.Int("s", 100, "")
nameserver multiflag nameserver multiflag
) )
@ -45,7 +45,6 @@ func message(domain string, reqtype uint16, ra bool) *dns.Msg {
func query(q <-chan Pair, tracker chan<- interface{}) { func query(q <-chan Pair, tracker chan<- interface{}) {
for pair := range q { for pair := range q {
msg := message(pair.Domain, dns.TypeA, false) msg := message(pair.Domain, dns.TypeA, false)
// fmt.Println("Querying ", pair.Domain, " on ", pair.Nameserver)
in, err := dns.Exchange(msg, pair.Nameserver+":53") in, err := dns.Exchange(msg, pair.Nameserver+":53")
if err != nil { if err != nil {
common.Error(err.Error()) common.Error(err.Error())
@ -69,6 +68,18 @@ func testns(ns string) error {
return nil return nil
} }
func testreq() bool {
msg := message("cloudflare.com", dns.TypeA, false)
in, err := dns.Exchange(msg, "1.1.1.1:53")
if err != nil {
return false
}
if len(in.Answer) > 0 {
return true
}
return false
}
func main() { func main() {
flag.Var(&nameserver, "n", "nameserver to query") flag.Var(&nameserver, "n", "nameserver to query")
flag.Usage = common.Usage flag.Usage = common.Usage
@ -95,13 +106,18 @@ func main() {
} }
} }
fmt.Println(nameservers)
} else if len(nameserver) > 0 { } else if len(nameserver) > 0 {
for _, ns := range nameserver { for _, ns := range nameserver {
nameservers = append(nameservers, ns) nameservers = append(nameservers, ns)
} }
} else { } else {
// print usage // print usage
common.Usage()
return
}
if !testreq() {
common.Fatal("non-recursive queries are being refused, are you on a very dirty box or VPN?")
} }
common.Info("aggregating nameservers...") common.Info("aggregating nameservers...")
@ -113,7 +129,7 @@ func main() {
} }
} }
common.Info(fmt.Sprintf("snooping EDR domains from %d resolvers...", len(nameservers))) common.Info(fmt.Sprintf("snooping caches on %d resolvers...", len(nameservers)))
go func() { go func() {
for i := 0; i < *workers; i++ { for i := 0; i < *workers; i++ {

View File

@ -19,17 +19,35 @@ var (
func Banner() { func Banner() {
fmt.Printf(`%s fmt.Printf(`%s
_ __________=__ .------..------..------..------..------..------..------.
\\@([____]_____() |%s%sP%s%s.--. ||%s%sA%s%s.--. ||%s%sT%s%s.--. ||%s%sD%s%s.--. ||%s%sO%s%s.--. ||%s%sW%s%s.--. ||%s%sN%s%s.--. |
_/\|-[____] | :/\: || (\/) || :/\: || :/\: || :/\: || :/\: || :(): |
/ /(( ) ___ __ _____ ___ ___ _ _ _ _ | (__) || :\/: || (__) || (__) || :\/: || :\/: || ()() |
/____|'----' | |_) / /\ | | | | \ / / \ \ \ / | |\ | | '--'P|| '--'A|| '--'T|| '--'D|| '--'O|| '--'W|| '--'N|
\____/ |_| /_/--\ |_| |_|_/ \_\_/ \_\/\/ |_| \| '------''------''------''------''------''------''------'
%s%s
sincerely, %s%s sincerely,
~ delorean%s ~ delorean%s
`, ColorRed, ColorReset, ColorGray, ColorReset) `, ColorRed, ColorReset, ColorGray, ColorReset, ColorRed, ColorReset, ColorGray, ColorReset,
ColorRed, ColorReset, ColorGray, ColorReset, ColorRed, ColorReset, ColorGray, ColorReset,
ColorRed, ColorReset, ColorGray, ColorReset, ColorRed, ColorReset, ColorGray, ColorReset,
ColorRed, ColorReset, ColorGray, ColorReset, ColorRed, ColorReset, ColorGray, ColorReset)
}
func Usage() {
fmt.Fprintf(os.Stderr, `patdown usage:
(%s-t%s) - target domain
(%s-n%s) - specific nameserver to snoop, can be multiple
(%s-c%s) - concurrent threads [%s100%s]
(%s-s%s) - delay between queries, per thread, in milliseconds [%s100%s]
%se.g.%s
patdown -t supernets.org
patdown -n ns1.supernets.org -n ns2.supernets.org
patdown -t supernets.org -c 50 -s 500
`, ColorCyan, ColorReset, ColorCyan, ColorReset, ColorCyan, ColorReset, ColorGray, ColorReset, ColorCyan, ColorReset, ColorGray, ColorReset, ColorCyan, ColorReset)
} }
var Vendors = map[string]string{ var Vendors = map[string]string{
@ -67,7 +85,3 @@ func Fatal(msg string) {
fmt.Printf(" %s~f~%s %s\n", ColorRed, ColorReset, msg) fmt.Printf(" %s~f~%s %s\n", ColorRed, ColorReset, msg)
os.Exit(-1) os.Exit(-1)
} }
func Usage() {
fmt.Printf(" %s~u~%s usage:\npatdown -t <domain>\npatdown -n ns1.target.com -n ns2.target.com", ColorOrange, ColorReset)
}