POC is working

This commit is contained in:
Miek Gieben 2012-01-28 13:31:01 +01:00
parent ca0cad0d5d
commit aef1004a9d
2 changed files with 37 additions and 20 deletions

View File

@ -185,8 +185,14 @@ func (f *fingerprint) setString(str string) {
f.CheckingDisabled = s == strings.ToUpper("cd") f.CheckingDisabled = s == strings.ToUpper("cd")
case 12: case 12:
f.Zero = s == strings.ToUpper("z") f.Zero = s == strings.ToUpper("z")
case 13, 14, 15, 16: case 13:
// Can not set lenght of the section in the message f.Question = valueOfString(s)
case 14:
f.Answer = valueOfString(s)
case 15:
f.Ns = valueOfString(s)
case 16:
f.Extra = valueOfString(s)
case 17: case 17:
f.Do = s == strings.ToUpper("do") f.Do = s == strings.ToUpper("do")
case 18: case 18:
@ -226,7 +232,11 @@ func toFingerprint(m *dns.Msg) *fingerprint {
f := new(fingerprint) f := new(fingerprint)
if len(m.Question) > 0 { if len(m.Question) > 0 {
f.Query.Name = m.Question[0].Name if len(m.Question[0].Name) == 0 {
f.Query.Name = "."
} else {
f.Query.Name = m.Question[0].Name
}
f.Query.Qtype = m.Question[0].Qtype f.Query.Qtype = m.Question[0].Qtype
f.Query.Qclass = m.Question[0].Qclass f.Query.Qclass = m.Question[0].Qclass
} }

View File

@ -19,8 +19,9 @@ func q(w dns.RequestWriter, m *dns.Msg) {
func main() { func main() {
port := flag.Int("port", 53, "port number to use") port := flag.Int("port", 53, "port number to use")
report := flag.Bool("report", false, "show fingerprint for unknown server")
flag.Usage = func() { flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage: %s [-port 53] [@server]\n", os.Args[0]) fmt.Fprintf(os.Stderr, "Usage: %s [OPTIONS...] [@server]\n", os.Args[0])
flag.PrintDefaults() flag.PrintDefaults()
} }
@ -38,24 +39,30 @@ func main() {
nameserver = string([]byte(nameserver)[1:]) // chop off @ nameserver = string([]byte(nameserver)[1:]) // chop off @
nameserver += ":" + strconv.Itoa(*port) nameserver += ":" + strconv.Itoa(*port)
c := dns.NewClient() c := dns.NewClient()
prints, _ := fingerPrintFromFile("data/q") prints, _ := fingerPrintFromFile("data/q")
results := make([]*fingerprint, 0) results := make([]*fingerprint, 0)
for _, f := range prints { for _, f := range prints {
f1 := probe(c, nameserver, f) f1 := probe(c, nameserver, f)
results = append(results, f1) results = append(results, f1)
println(f.String(), f1.String()) if *report {
fmt.Printf("%s\n", f1.String())
}
}
if *report {
return
} }
bind9, _ := fingerPrintFromFile("data/Bind9") // For now, just list them:
nsd3, _ := fingerPrintFromFile("data/Nsd3") files := []string{"data/Bind9", "data/Nsd3"}
fmt.Printf("%s\t%s\t%s\t\t\t\t\t\t\t\t%s\n", "Server type", "Diffs", "Received", "Sent")
for i, f := range bind9 { for _, file := range files {
d := f.compare(results[i]) diff := 0
println(d) prints, _ := fingerPrintFromFile(file)
} for i, f := range prints {
d := f.compare(results[i])
for i, f := range nsd3 { diff += d
d := f.compare(results[i]) fmt.Printf("%s\t%d\t%s t%s\n", file, d, f.String(), results[i].String())
println(d) }
} fmt.Printf("\t\t==\nDifferences:\t%d\n\n", diff)
}
} }