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

  1. description = [[
  2. Attempts to extract system information from the point-to-point tunneling protocol (PPTP) service.
  3. ]]
  4. -- rev 0.2 (11-14-2007)
  5.  
  6. author = "Thomas Buchanan <tbuchanan@thecompassgrp.net>"
  7.  
  8. license = "Same as Nmap--See http://nmap.org/book/man-legal.html"
  9.  
  10. categories = {"version"}
  11.  
  12. require "comm"
  13. require "shortport"
  14.  
  15. portrule = shortport.portnumber(1723)
  16.  
  17. action = function(host, port)
  18.     -- build a PPTP Start-Control-Connection-Request packet
  19.     -- copied from packet capture of pptp exchange
  20.     -- for details of packet structure, see http://www.ietf.org/rfc/rfc2637.txt
  21.     local payload = "\000\156\000\001\026\043\060\077" .. -- length=156, Message type=control, cookie
  22.     "\000\001\000\000\001\000\000\000" .. -- Control type=Start-Control-Connection-Request, Reserved, Protocol=1.0, Reserverd
  23.     "\000\000\000\001\000\000\000\001" .. -- Framing Capabilities, Bearer Capabilities
  24.     "\255\255\000\001" .. "none" .. -- Maximum channels, firmware version, hostname
  25.     "\000\000\000\000\000\000\000\000" .. -- padding for hostname
  26.     "\000\000\000\000\000\000\000\000" .. -- padding for hostname
  27.     "\000\000\000\000\000\000\000\000" .. -- padding for hostname
  28.     "\000\000\000\000\000\000\000\000" .. -- padding for hostname
  29.     "\000\000\000\000\000\000\000\000" .. -- padding for hostname
  30.     "\000\000\000\000\000\000\000\000" .. -- padding for hostname
  31.     "\000\000\000\000\000\000\000\000" .. -- padding for hostname
  32.     "\000\000\000\000" .. "nmap" .. -- padding for hostname, vendor name
  33.     "\000\000\000\000\000\000\000\000" .. -- padding for vendor name
  34.     "\000\000\000\000\000\000\000\000" .. -- padding for vendor name
  35.     "\000\000\000\000\000\000\000\000" .. -- padding for vendor name
  36.     "\000\000\000\000\000\000\000\000" .. -- padding for vendor name
  37.     "\000\000\000\000\000\000\000\000" .. -- padding for vendor name
  38.     "\000\000\000\000\000\000\000\000" .. -- padding for vendor name
  39.     "\000\000\000\000\000\000\000\000" .. -- padding for vendor name
  40.     "\000\000\000\000"; -- padding for vendor name
  41.  
  42.     local try = nmap.new_try()
  43.     local response = try(comm.exchange(host, port, payload, {timeout=5000}))
  44.  
  45.     local result
  46.         
  47.     -- check to see if the packet we got back matches the beginning of a PPTP Start-Control-Connection-Reply packet
  48.     result = string.match(response, "%z\156%z\001\026\043(.*)")
  49.     local output
  50.     
  51.     if result ~= nil then
  52.         local firmware
  53.         local hostname
  54.         local vendor
  55.         
  56.         -- get the firmware version (2 octets) 
  57.         local s1,s2
  58.         s1,s2 = string.byte(result, 22, 23)
  59.         firmware = s1 * 256 + s2
  60.  
  61.         -- get the hostname (64 octets)
  62.         local s3
  63.         s3 = string.sub(result, 24, 87)
  64.         hostname = string.match(s3, "(.-)%z")
  65.  
  66.         -- get the vendor (should be 64 octets, but capture to end of the string to be safe)
  67.         local s4, length
  68.         length = string.len(result)
  69.         s4 = string.sub(result, 88, length)
  70.         vendor = string.match(s4, "(.-)%z")
  71.     
  72.         port.version.name = "pptp"
  73.         port.version.name_confidence = 10
  74.         if vendor ~= nil then port.version.product = vendor end
  75.         if firmware ~= 0 then port.version.version = "(Firmware: " .. firmware .. ")" end
  76.         if hostname ~= nil then port.version.hostname = hostname end
  77.         
  78.         port.version.service_tunnel = "none"
  79.         nmap.set_port_version(host, port, "hardmatched")
  80.     end
  81.  
  82. end
  83.