-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DNS amplification check (ANY queries) implemented
- Loading branch information
Showing
3 changed files
with
84 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |