From 47beef5d4507ca5b6dedb2237fa53bdabec43810 Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Tue, 20 Sep 2011 15:56:51 +0200 Subject: [PATCH] Add some more functions --- TODO.markdown | 2 +- _examples/q/dns.go | 30 ++++++++++++++++++++++++++---- _examples/q/fp.go | 2 ++ _examples/q/lex.go | 13 +++++++++---- 4 files changed, 38 insertions(+), 9 deletions(-) diff --git a/TODO.markdown b/TODO.markdown index a4deacb9..61893d07 100644 --- a/TODO.markdown +++ b/TODO.markdown @@ -3,7 +3,7 @@ Must of the stuff is working, but there is a list of smaller things that need to be fixed. -* Use the Exchange structure to deal with errors when resolving +* Use the Exchange structure to deal with errors when resolving, esp. Timeout * encoding NSEC3/NSEC bitmaps, DEcoding works; * add functions to operate on []byte messages (raw packets) see rawmsg.go * HIP RR (needs list of domain names, need slice for that); diff --git a/_examples/q/dns.go b/_examples/q/dns.go index 32ddd2b6..a30eac5f 100644 --- a/_examples/q/dns.go +++ b/_examples/q/dns.go @@ -22,15 +22,37 @@ func dnsAlive(l *lexer) stateFn { // Check if the server returns the DO-bit when set in the request. func dnsDoBitMirror(l *lexer) stateFn { l.verbose("DoBitMirror") - // The important part here is that the DO bit is on in the reply l.setString("QUERY,NOERROR,qr,aa,tc,RD,ra,ad,cd,z,1,0,0,0,DO,0") l.setQuestion(".", dns.TypeNS, dns.ClassINET) f := l.probe() - if !f.Do { + // NSD doesn't set the DO bit, but does set the UDPMsg size to 4096. + if !f.Do && f.UDPSize == 4096 { l.emit(&item{itemSoftware, NSD}) - return nil + return dnsEDNS0Mangler } - l.emit(&item{itemSoftware, BIND}) + return dnsEDNS0Mangler +} + +func dnsEDNS0Mangler(l *lexer) stateFn { + l.verbose("EDNS0Mangler") + l.setString("NOTIFY,NOERROR,qr,aa,tc,RD,ra,ad,cd,z,1,0,0,0,do,0") + l.setQuestion("012345678901234567890123456789012345678901234567890123456789012.012345678901234567890123456789012345678901234567890123456789012.012345678901234567890123456789012345678901234567890123456789012.0123456789012345678901234567890123456789012345678901234567890.", dns.TypeA, dns.ClassINET) + f := l.probe() + // MaraDNS does not set the QR bit in the reply... but only with this question is seems + // QUERY,NOERROR,qr,aa,t + if !f.Response && f.Opcode == dns.OpcodeQuery && f.Rcode == dns.RcodeSuccess { + l.emit(&item{itemSoftware, MARADNS}) + } + return dnsTcEnable +} + +func dnsTcEnable(l *lexer) stateFn { + l.verbose("TcEnable") + l.setString("QUERY,NOERROR,qr,aa,TC,rd,ra,ad,cd,z,1,0,0,0,do,0") + l.setQuestion(".", dns.TypeNS, dns.ClassINET) + + f := l.probe() + f = f return nil } diff --git a/_examples/q/fp.go b/_examples/q/fp.go index 1a0aacac..9285e4d3 100644 --- a/_examples/q/fp.go +++ b/_examples/q/fp.go @@ -13,9 +13,11 @@ const ( // Detected software types NSD = "NSD" BIND = "BIND" + MARADNS = "MaraDNS" // Vendors ISC = "ISC" + MARA = "MaraDNS.org" // check NLNETLABS = "NLnet Labs" MICROSOFT = "Microsoft" ) diff --git a/_examples/q/lex.go b/_examples/q/lex.go index 73d2fbd4..699b919a 100644 --- a/_examples/q/lex.go +++ b/_examples/q/lex.go @@ -18,8 +18,8 @@ type item struct { const ( itemError itemType = iota - itemVender // software vendor itemSoftware // the name of the DNS server software + itemVendor // vendor of the DNS software itemVersionMin // the minimum version of the software (empty if not determined) itemVersionMax // the maximum version of the software (empty if not determined) ) @@ -40,7 +40,7 @@ type lexer struct { func (l *lexer) probe() *fingerprint { f := sendProbe(l.client, l.addr, l.fp, l.q) if l.debug { - fmt.Printf(" QR fp: %s\n", f) + fmt.Printf(" QR fp: %s\n", f) } return f } @@ -52,12 +52,15 @@ func (l *lexer) emit(i *item) { func (l *lexer) setString(s string) { l.fp.setString(s) if l.debug { - fmt.Printf(" Q fp: %s\n", s) + fmt.Printf(" Q fp: %s\n", s) } } func (l *lexer) setQuestion(name string, t uint16, c uint16) { l.q = dns.Question{name, t, c} +// if l.debug { +// fmt.Printf(" Question: %v\n", l.q) +// } } func (l *lexer) run() { @@ -70,5 +73,7 @@ func (l *lexer) run() { } func (l *lexer) verbose(s string) { - fmt.Printf("running: dns%s\n", s) + if l.debug { + fmt.Printf("running: dns%s\n", s) + } }