File: dns-recursion.nse

package info (click to toggle)
nmap 7.40-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 50,080 kB
  • ctags: 26,777
  • sloc: ansic: 98,862; cpp: 64,063; python: 17,751; sh: 14,584; xml: 11,448; makefile: 2,635; perl: 2,585; yacc: 660; lex: 457; asm: 372; java: 45; objc: 43
file content (59 lines) | stat: -rw-r--r-- 1,498 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
local bit = require "bit"
local comm = require "comm"
local nmap = require "nmap"
local shortport = require "shortport"
local string = require "string"

description = [[
Checks if a DNS server allows queries for third-party names. It is
expected that recursion will be enabled on your own internal
nameservers.
]]

---
-- @usage
-- nmap -sU -p 53 --script=dns-recursion <target>
-- @output
-- PORT   STATE SERVICE REASON
-- 53/udp open  domain  udp-response
-- |_dns-recursion: Recursion appears to be enabled

author = "Felix Groebert"

license = "Same as Nmap--See https://nmap.org/book/man-legal.html"

categories = {"default", "safe"}


portrule = shortport.portnumber(53, "udp")

action = function(host, port)

    -- generate dns query
    local request = "\xde\xad" -- Transaction-ID 0xdead
    .. "\x01\x00" -- flags (recursion desired)
    .. "\x00\x01" -- 1 question
    .. "\x00\x00" -- 0 answers
    .. "\x00\x00" -- 0 authority
    .. "\x00\x00" -- 0 additional
    .. "\x03www\x09wikipedia\x03org\x00" -- www.wikipedia.org.
    .. "\x00\x01" -- type A
    .. "\x00\x01" -- class IN

    local status, result = comm.exchange(host, port, request, {proto="udp"})

    if not status then
        return
    end

    nmap.set_port_state(host, port, "open")

    -- parse response for dns flags
    if (bit.band(string.byte(result,3), 0x80) == 0x80
        and bit.band(string.byte(result,4), 0x85) == 0x80)
    then
        return "Recursion appears to be enabled"
    end

    return
end