From c28cd4c2177e56252c7c2d4a0b6705cac7b77882 Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Sun, 15 Jan 2012 16:45:18 +0100 Subject: [PATCH] Like this? --- _examples/q/dns.go | 46 +++++++++++++++++++++++----------------------- _examples/q/fp.go | 2 +- _examples/q/lex.go | 40 +++++++++++++++------------------------- 3 files changed, 39 insertions(+), 49 deletions(-) diff --git a/_examples/q/dns.go b/_examples/q/dns.go index 917149af..b996d948 100644 --- a/_examples/q/dns.go +++ b/_examples/q/dns.go @@ -12,7 +12,7 @@ const ( // Check if the server responds at all func dnsAlive(l *lexer) stateFn { - l.debug("Alive") + l.verbose("Alive") l.setString(QUERY_NOERROR) l.setQuestion(".", dns.TypeNS, dns.ClassINET) @@ -27,7 +27,7 @@ func dnsAlive(l *lexer) stateFn { // This is the starting test. Perform a bunch of queries, get the // fingerprint a go into a general direction. NsdLike, BindLike, WindowsLike, MaraLike func dnsServer(l *lexer) stateFn { - l.debug("Server") + l.verbose("Server") // Set the DO bit l.setString("QUERY,NOERROR,qr,aa,tc,RD,ra,ad,cd,z,0,0,0,0,DO,4097,NSID") @@ -76,7 +76,7 @@ func dnsServer(l *lexer) stateFn { } func dnsNsdLike(l *lexer) stateFn { - l.debug("NsdLike") + l.verbose("NsdLike") l.setString(QUERY_NOERROR) l.setQuestion("authors.bind.", dns.TypeTXT, dns.ClassCHAOS) l.probe() @@ -85,7 +85,7 @@ func dnsNsdLike(l *lexer) stateFn { } func dnsBindLike(l *lexer) stateFn { - l.debug("BindLike") + l.verbose("BindLike") l.emit(&item{itemSoftware, BIND}) @@ -142,24 +142,24 @@ func dnsBindLike(l *lexer) stateFn { } func dnsWindowsLike(l *lexer) stateFn { - l.debug("WindowsLike") + l.verbose("WindowsLike") return nil } func dnsMaraLike(l *lexer) stateFn { - l.debug("MaraLike") + l.verbose("MaraLike") return nil } func dnsPowerdnsLike(l *lexer) stateFn { - l.debug("PowerdnsLike") + l.verbose("PowerdnsLike") return nil } func dnsYadifaLike(l *lexer) stateFn { - l.debug("YadifaLike") + l.verbose("YadifaLike") l.setString(".,CLASS0,TYPE0,QUERY,NOERROR,QR,aa,tc,rd,ra,ad,cd,z,0,0,0,0,do,0,nsid") l.probe() l.setString(".,CLASS42,TXT,QUERY,NOERROR,qr,aa,tc,rd,ra,ad,cd,z,0,0,0,0,do,0,nsid") @@ -168,8 +168,8 @@ func dnsYadifaLike(l *lexer) stateFn { } func dnsNeustarLike(l *lexer) stateFn { - l.debug("NeustarLike") - l.debug("UltraDNS") + l.verbose("NeustarLike") + l.verbose("UltraDNS") l.setString(".,CLASS42,TXT,QUERY,NOERROR,qr,aa,tc,rd,ra,ad,cd,z,0,0,0,0,do,0,nsid") l.probe() @@ -177,14 +177,14 @@ func dnsNeustarLike(l *lexer) stateFn { } func dnsAtlasLike(l *lexer) stateFn { - l.debug("AtlasLike") + l.verbose("AtlasLike") return nil } // Check if the server returns the DO-bit when set in the request. func dnsDoBitMirror(l *lexer) stateFn { - l.debug("DoBitMirror") + l.verbose("DoBitMirror") l.setString("QUERY,NOERROR,qr,aa,tc,RD,ra,ad,cd,z,0,0,0,0,DO,0,NSID") l.setQuestion(".", dns.TypeNS, dns.ClassINET) @@ -199,7 +199,7 @@ func dnsDoBitMirror(l *lexer) stateFn { } func dnsEDNS0Mangler(l *lexer) stateFn { - l.debug("EDNS0Mangler") + l.verbose("EDNS0Mangler") l.setString("NOTIFY,NOERROR,qr,aa,tc,RD,ra,ad,cd,z,0,0,0,0,do,0,nsid") l.setQuestion("012345678901234567890123456789012345678901234567890123456789012.012345678901234567890123456789012345678901234567890123456789012.012345678901234567890123456789012345678901234567890123456789012.0123456789012345678901234567890123456789012345678901234567890.", dns.TypeA, dns.ClassINET) f, _ := l.probe() @@ -212,7 +212,7 @@ func dnsEDNS0Mangler(l *lexer) stateFn { } func dnsTcEnable(l *lexer) stateFn { - l.debug("TcEnable") + l.verbose("TcEnable") l.setString("QUERY,NOERROR,qr,aa,TC,rd,ra,ad,cd,z,0,0,0,0,do,0,nsid") l.setQuestion(".", dns.TypeNS, dns.ClassINET) l.probe() @@ -220,7 +220,7 @@ func dnsTcEnable(l *lexer) stateFn { } func dnsUDPSize(l *lexer) stateFn { - l.debug("UDPSize") + l.verbose("UDPSize") l.setString("QUERY,NOERROR,qr,aa,tc,rd,ra,ad,cd,z,0,0,0,0,DO,4097,nsid") l.setQuestion(".", dns.TypeNS, dns.ClassINET) l.probe() @@ -228,7 +228,7 @@ func dnsUDPSize(l *lexer) stateFn { } func dnsZero(l *lexer) stateFn { - l.debug("Zero") + l.verbose("Zero") l.setQuestion(".", dns.TypeNS, dns.ClassINET) l.setString("QUERY,NOERROR,qr,aa,tc,rd,ra,ad,cd,Z,0,0,0,0,do,0,nsid") l.probe() @@ -236,7 +236,7 @@ func dnsZero(l *lexer) stateFn { } func dnsAll(l *lexer) stateFn { - l.debug("All") + l.verbose("All") l.setString("QUERY,NOERROR,qr,AA,TC,RD,RA,AD,CD,Z,0,0,0,0,DO,8192,nsid") l.setQuestion(".", dns.TypeNS, dns.ClassINET) l.probe() @@ -244,7 +244,7 @@ func dnsAll(l *lexer) stateFn { } func dnsIquery(l *lexer) stateFn { - l.debug("Iquery") + l.verbose("Iquery") l.setString("IQUERY,NOERROR,qr,aa,tc,rd,ra,ad,cd,Z,0,0,0,0,do,0,nsid") l.setQuestion(".", dns.TypeNS, dns.ClassINET) l.probe() @@ -252,7 +252,7 @@ func dnsIquery(l *lexer) stateFn { } func dnsUpdate(l *lexer) stateFn { - l.debug("Update") + l.verbose("Update") l.setString("UPDATE,NOERROR,qr,aa,tc,rd,ra,ad,cd,Z,0,0,0,0,do,0,nsid") l.setQuestion(".", dns.TypeNS, dns.ClassINET) l.probe() @@ -260,7 +260,7 @@ func dnsUpdate(l *lexer) stateFn { } func dnsStatus(l *lexer) stateFn { - l.debug("Status") + l.verbose("Status") l.setString("STATUS,NOERROR,qr,aa,tc,rd,ra,ad,cd,Z,0,0,0,0,do,0,nsid") l.setQuestion(".", dns.TypeNS, dns.ClassINET) l.probe() @@ -268,7 +268,7 @@ func dnsStatus(l *lexer) stateFn { } func dnsOpcodeWhacky(l *lexer) stateFn { - l.debug("OpcodeWhacky") + l.verbose("OpcodeWhacky") l.setString("12,NOERROR,qr,aa,tc,rd,ra,ad,cd,Z,0,0,0,0,do,0,nsid") l.setQuestion(".", dns.TypeNS, dns.ClassINET) l.probe() @@ -276,7 +276,7 @@ func dnsOpcodeWhacky(l *lexer) stateFn { } func dnsRcodeWhacky(l *lexer) stateFn { - l.debug("RcodeWhacky") + l.verbose("RcodeWhacky") l.setString("QUERY,31,qr,aa,tc,rd,ra,ad,cd,Z,0,0,0,0,do,0,nsid") l.setQuestion(".", dns.TypeNS, dns.ClassINET) l.probe() @@ -284,7 +284,7 @@ func dnsRcodeWhacky(l *lexer) stateFn { } func dnsRcodeNotZone(l *lexer) stateFn { - l.debug("RcodeNotZone") + l.verbose("RcodeNotZone") l.setString("QUERY,NOTZONE,qr,aa,tc,rd,ra,ad,cd,z,0,0,0,0,do,0,nsid") l.setQuestion(".", dns.TypeNS, dns.ClassINET) l.probe() diff --git a/_examples/q/fp.go b/_examples/q/fp.go index 62e1b397..6e279ddb 100644 --- a/_examples/q/fp.go +++ b/_examples/q/fp.go @@ -39,7 +39,7 @@ func startParse(addr string) { fp: new(fingerprint), items: make(chan item), state: dnsAlive, - debugging: true, + debug: true, } l.run() diff --git a/_examples/q/lex.go b/_examples/q/lex.go index 8f78dbb1..69529b7b 100644 --- a/_examples/q/lex.go +++ b/_examples/q/lex.go @@ -38,23 +38,20 @@ var itemString = map[itemType]string{ type stateFn func(*lexer) stateFn type lexer struct { - client *dns.Client // client used. - addr string // addr of the server being scanned. - fp *fingerprint // fingerprint to test. - q dns.Question // question to ask. - items chan item // channel of scanned items. - state stateFn // the next function to enter. - verbose bool // if true, the fingerprints are printed. - debugging bool // If true, print the function names. + client *dns.Client // client used. + addr string // addr of the server being scanned. + fp *fingerprint // fingerprint to test. + items chan item // channel of scanned items. + state stateFn // the next function to enter. + debug bool // if true, the fingerprints are printed. } -func (l *lexer) probe() (*fingerprint, dns.Question) { - f, q := sendProbe(l.client, l.addr, l.fp, l.q) - if l.verbose { - fmt.Printf("QR : %s\t-", f) - fmt.Printf(" (%s)\n", q.String()) +func (l *lexer) probe() *fingerprint { + f := sendProbe(l.client, l.addr, l.fp) + if l.debug { + fmt.Printf(" QR fp: %s\n", f) } - return f, q + return f } func (l *lexer) emit(i *item) { @@ -63,15 +60,8 @@ func (l *lexer) emit(i *item) { func (l *lexer) setString(s string) { l.fp.setString(s) - if l.verbose { - fmt.Printf("Q : %s\t-", s) - } -} - -func (l *lexer) setQuestion(name string, t uint16, c uint16) { - l.q = dns.Question{name, t, c} - if l.verbose { - fmt.Printf(" (%s)\n", l.q.String()) + if l.debug { + fmt.Printf(" Q fp: %s\n", s) } } @@ -84,8 +74,8 @@ func (l *lexer) run() { }() } -func (l *lexer) debug(s string) { - if l.debugging { +func (l *lexer) verbose(s string) { + if l.debug { fmt.Printf(" dns%s\n", s) } }