Skip to content

Commit

Permalink
#5 - implemented dnssec check
Browse files Browse the repository at this point in the history
  • Loading branch information
5amu committed Jul 6, 2022
1 parent b07b90b commit 470b83c
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 4 deletions.
9 changes: 5 additions & 4 deletions internal/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ type Check interface {
}

var CheckList = []Check{
new(dnschecks.SOACheck),
new(dnschecks.GLUECheck),
new(dnschecks.ANYCheck),
new(dnschecks.AXFRCheck),
//new(dnschecks.SOACheck),
//new(dnschecks.GLUECheck),
//new(dnschecks.ANYCheck),
//new(dnschecks.AXFRCheck),
new(dnschecks.DNSSECCheck),
}
76 changes: 76 additions & 0 deletions internal/dnschecks/dnssec.go
Original file line number Diff line number Diff line change
@@ -1 +1,77 @@
package dnschecks

import (
"fmt"
"net"

"github.com/5amu/dnshunter/internal/common"
"github.com/5amu/dnshunter/internal/output"
"github.com/miekg/dns"
)

type DNSSECCheck struct {
client *dns.Client
output *output.CheckOutput
}

func (c *DNSSECCheck) Init(client *dns.Client) error {
c.client = client
return nil
}

func (c *DNSSECCheck) Start(domain string, nameservers *common.Nameservers) error {

m := new(dns.Msg)
m.SetQuestion(dns.Fqdn(domain), dns.TypeDNSKEY)
m.RecursionDesired = true

var isVuln bool
var message string

message += "\nDNSSEC is a suite of extensions aimed to guarantee secure data\n"
message += "exchange between the name server and the client. It guarantees data\n"
message += "integrity and denial of exitence. Its mean is to avoid zone\n"
message += "enumeration and prevent from manipulated answers and cache poisoning\n\n"

for _, ns := range nameservers.IPs {

fqdn, err := nameservers.IPv4ToFQDN(ns.String())
if err != nil {
return err
}

r, _, err := c.client.Exchange(m, net.JoinHostPort(ns.String(), "53"))
if err != nil {
return err
}

if r.Rcode != dns.RcodeSuccess {
return fmt.Errorf("invalid answer from %v after KEY query for %v", fqdn, domain)
}

if len(r.Answer) == 0 {
isVuln = true
}

if isVuln {
message += common.Warn(fmt.Sprintf("nameserver %v does not provide DNSSEC key\n", fqdn))
} else {
// TODO: implement key signature verification
message += fmt.Sprintf("nameserver %v provides DNSSEC key!\n", fqdn)
}
}

c.output = &output.CheckOutput{
Name: "DNS amplification",
Domain: domain,
Nameservers: nameservers.ToFQDNs(),
Vulnerable: isVuln,
Message: message,
}

return nil
}

func (c *DNSSECCheck) Results() *output.CheckOutput {
return c.output
}

0 comments on commit 470b83c

Please sign in to comment.