home *** CD-ROM | disk | FTP | other *** search
/ Hackers Magazine 57 / CdHackersMagazineNr57.iso / Software / Networking / nmap-5.00-setup.exe / scripts / dns-recursion.nse < prev    next >
Text File  |  2009-07-06  |  1KB  |  40 lines

  1.  
  2. description = [[
  3. Checks if a DNS server allows queries for third-party names.
  4.  
  5. It is expected that recursion will be enabled on your own internal nameservers.
  6. ]]
  7.  
  8. author = "Felix Groebert <felix@groebert.org>"
  9.  
  10. license = "Same as Nmap--See http://nmap.org/book/man-legal.html"
  11.  
  12. categories = {"default", "intrusive"}
  13.  
  14. require "bit"
  15. require "comm"
  16. require "shortport"
  17.  
  18. portrule = shortport.portnumber(53, "udp")
  19.  
  20. action = function(host, port)
  21.  
  22.     -- generate dns query, Transaction-ID 0xdead, www.wikipedia.org (type A, class IN)
  23.     local request = string.char(0xde, 0xad, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03) ..  "www" .. string.char(0x09) .. "wikipedia" .. string.char(0x03) ..  "org" .. string.char(0x00, 0x00, 0x01, 0x00, 0x01)
  24.  
  25.     local status, result = comm.exchange(host, port, request, {proto="udp"})
  26.  
  27.     if not status then
  28.         return
  29.     end
  30.  
  31.     -- parse response for dns flags
  32.     if (bit.band(string.byte(result,3), 0x80) == 0x80
  33.     and bit.band(string.byte(result,4), 0x85) == 0x80)
  34.     then
  35.         return "Recursion appears to be enabled"
  36.     end
  37.  
  38.     return
  39. end
  40.