Skip to content

Commit

Permalink
DNS amplification check (ANY queries) implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
5amu committed Jul 6, 2022
1 parent 97d260f commit 1991fbc
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 2 deletions.
1 change: 1 addition & 0 deletions internal/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ type Check interface {
var CheckList = []Check{
new(dnschecks.SOACheck),
new(dnschecks.GLUECheck),
new(dnschecks.ANYCheck),
}
9 changes: 7 additions & 2 deletions internal/common/constants.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
package common

const DNSHunterVersion = "0.1"
const DefaultNameserver = "8.8.8.8"
const (
DNSHunterVersion = "0.1"
DefaultNameserver = "8.8.8.8"
// DNSAmplificationThreshold is an arbitrary number that the programmer
// considered to be enough for "response considerably larger than request"
DNSAmplificationThreshold = 5
)
76 changes: 76 additions & 0 deletions internal/dnschecks/anyquery.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 ANYCheck struct {
client *dns.Client
output *output.CheckOutput
}

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

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

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

var isVuln bool
var message string

message += "\nAnswering to ANY queries might get the nameserver to suffer from\n"
message += "DNS Amplification Attacks, basically ddos attacks based on the fact\n"
message += "that the answer given by the DNS is much larger that the request\n"
message += "made by the host. More information on the severity here:\n"
message += "https://www.cisa.gov/uscert/ncas/alerts/TA13-088A\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 A query for %v", fqdn, domain)
}

if len(r.Answer) > common.DNSAmplificationThreshold {
isVuln = true
}

if isVuln {
message += common.Warn(fmt.Sprintf("nameserver %v is vulnerable to DNS amplification\n", fqdn))
} else {
message += fmt.Sprintf("nameserver %v isn't vulnerable to DNS amplification\n", fqdn)
}
}

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

return nil
}

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

0 comments on commit 1991fbc

Please sign in to comment.