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

  1. description = [[
  2. Pulls back information about the remote system from the registry. Getting all
  3. of the information requires an administrative account, although a user account
  4. will still get a lot of it. Guest probably won't get any, nor will anonymous. 
  5. This goes for all operating systems, including Windows 2000. 
  6.  
  7. Windows Vista disables remote registry access by default, so unless itw as enabled, 
  8. this script won't work.
  9.  
  10. If you know of more information stored in the Windows registry that could be interesting, 
  11. post a message to the nmap-dev mailing list and I (Ron Bowes) will add it to my todo list. 
  12. Adding new checks to this is extremely easy. 
  13.  
  14. WARNING: I have experienced crashes in regsvc.exe while making registry calls
  15. against a fully patched Windows 2000 system; I've fixed the issue that caused it,
  16. but there's no guarantee that it (or a similar vuln in the same code) won't show
  17. up again. Since the process automatically restarts, it doesn't negatively impact
  18. the system, besides showing a message box to the user.
  19. ]]
  20.  
  21. ---
  22. -- @usage
  23. -- nmap --script smb-system-info.nse -p445 <host>
  24. -- sudo nmap -sU -sS --script smb-system-info.nse -p U:137,T:139 <host>
  25. --
  26. -- @output
  27. -- Host script results:
  28. -- |  smb-system-info:
  29. -- |  OS Details
  30. -- |  |_ Microsoft Windows Server 2003 Service Pack 2 (ServerNT 5.2 build 3790)
  31. -- |  |_ Installed on 2007-11-26 23:40:40
  32. -- |  |_ Registered to Ron Bowes (organization: MYCOMPANY)
  33. -- |  |_ Path: %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\Microsoft SQL Server\90\Tools\binn\;C:\Program Files\IBM\Rational AppScan\
  34. -- |  |_ Systemroot: C:\WINDOWS
  35. -- |  |_ Page files: C:\pagefile.sys 2046 4092 (cleared at shutdown => 0)
  36. -- |  Hardware
  37. -- |  |_ CPU 0: Intel(R) Xeon(TM) CPU 2.80GHz [2780mhz GenuineIntel]
  38. -- |  |_ Identifier 0: x86 Family 15 Model 2 Stepping 9
  39. -- |  |_ CPU 1: Intel(R) Xeon(TM) CPU 2.80GHz [2780mhz GenuineIntel]
  40. -- |  |_ Identifier 1: x86 Family 15 Model 2 Stepping 9
  41. -- |  |_ CPU 2: Intel(R) Xeon(TM) CPU 2.80GHz [2780mhz GenuineIntel]
  42. -- |  |_ Identifier 2: x86 Family 15 Model 2 Stepping 9
  43. -- |  |_ CPU 3: Intel(R) Xeon(TM) CPU 2.80GHz [2780mhz GenuineIntel]
  44. -- |  |_ Identifier 3: x86 Family 15 Model 2 Stepping 9
  45. -- |  |_ Video driver: RAGE XL PCI Family (Microsoft Corporation)
  46. -- |  Browsers
  47. -- |  |_ Internet Explorer 7.0000
  48. -- |_ |_ Firefox 3.0.3 (en-US)
  49. -----------------------------------------------------------------------
  50.  
  51.  
  52.  
  53. author = "Ron Bowes"
  54. copyright = "Ron Bowes"
  55. license = "Same as Nmap--See http://nmap.org/book/man-legal.html"
  56. categories = {"discovery","intrusive"}
  57.  
  58. require 'msrpc'
  59. require 'smb'
  60. require 'stdnse'
  61.  
  62. hostrule = function(host)
  63.     return smb.get_port(host) ~= nil
  64. end
  65.  
  66. ---Retrieves the requested value from the registry. 
  67. --@param smbstate The SMB table we're using, bound to the WINREG service. 
  68. --@param handle   The handle to the hive (HKLM or HKU, for example).
  69. --@param key      The full path of the key to retrieve (like <code>"SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment"</code>).
  70. --@param value    The value to retrieve (like <code>"NUMBER_OF_PROCESSORS"</code>).
  71. --@return Status (true or false).
  72. --@return The value (if status is true) or an error string (if status is false).
  73. local function reg_get_value(smbstate, handle, key, value)
  74.  
  75.     -- Open the key
  76.     status, openkey_result = msrpc.winreg_openkey(smbstate, handle, key)
  77.     if(status == false) then
  78.         return false, openkey_result
  79.     end
  80.  
  81.     -- Query the value
  82.     status, queryvalue_result = msrpc.winreg_queryvalue(smbstate, openkey_result['handle'], value)
  83.     if(status == false) then
  84.         return false, queryvalue_result
  85.     end
  86.  
  87.     -- Close the key
  88.     status, closekey_result = msrpc.winreg_closekey(smbstate, openkey_result['handle'], value)
  89.     if(status == false) then
  90.         return false, closekey_result
  91.     end
  92.  
  93.     return true, queryvalue_result['value']
  94. end
  95.  
  96. local function get_info_registry(host)
  97.  
  98.     local result = {}
  99.  
  100.     -- Create the SMB session
  101.     status, smbstate = msrpc.start_smb(host, msrpc.WINREG_PATH)
  102.     if(status == false) then
  103.         return false, smbstate
  104.     end
  105.  
  106.     -- Bind to WINREG service
  107.     status, bind_result = msrpc.bind(smbstate, msrpc.WINREG_UUID, msrpc.WINREG_VERSION, nil)
  108.     if(status == false) then
  109.         msrpc.stop_smb(smbstate)
  110.         return false, bind_result
  111.     end
  112.  
  113.     -- Open HKEY_LOCAL_MACHINE
  114.     status, openhklm_result = msrpc.winreg_openhklm(smbstate)
  115.     if(status == false) then
  116.         msrpc.stop_smb(smbstate)
  117.         return false, openhklm_result
  118.     end
  119.  
  120.     -- Processor information
  121.     result['status-number_of_processors'], result['number_of_processors']   = reg_get_value(smbstate, openhklm_result['handle'], "SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment", "NUMBER_OF_PROCESSORS")
  122.     if(status == false) then
  123.         result['number_of_processors'] = 0
  124.     end
  125.     result['status-os'], result['os']                                         = reg_get_value(smbstate, openhklm_result['handle'], "SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment", "OS")
  126.     result['status-path'], result['path']                                     = reg_get_value(smbstate, openhklm_result['handle'], "SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment", "Path")
  127.     result['status-processor_architecture'], result['processor_architecture'] = reg_get_value(smbstate, openhklm_result['handle'], "SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment", "PROCESSOR_ARCHITECTURE")
  128.     result['status-processor_identifier'], result['processor_identifier']     = reg_get_value(smbstate, openhklm_result['handle'], "SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment", "PROCESSOR_IDENTIFIER")
  129.     result['status-processor_level'], result['processor_level']               = reg_get_value(smbstate, openhklm_result['handle'], "SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment", "PROCESSOR_LEVEL")
  130.     result['status-processor_revision'], result['processor_revision']         = reg_get_value(smbstate, openhklm_result['handle'], "SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment", "PROCESSOR_REVISION")
  131.  
  132.     for i = 0, result['number_of_processors'] - 1, 1 do
  133.         result['status-~mhz'..i], result['~mhz' .. i]                               = reg_get_value(smbstate, openhklm_result['handle'], "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\" .. i, "~MHz")
  134.         result['status-identifier'..i], result['identifier' .. i]                   = reg_get_value(smbstate, openhklm_result['handle'], "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\" .. i, "Identifier")
  135.         result['status-processornamestring'..i], result['processornamestring' .. i] = reg_get_value(smbstate, openhklm_result['handle'], "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\" .. i, "ProcessorNameString")
  136.         result['status-vendoridentifier'..i], result['vendoridentifier' .. i]       = reg_get_value(smbstate, openhklm_result['handle'], "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\" .. i, "VendorIdentifier")
  137.     end
  138. --    status, result['physicalmemory']   = reg_get_value(smbstate, openhklm_result['handle'], "HARDWARE\\ResourceMap\\System Resources\\Physical Memory", ".Translated")
  139.  
  140.     -- TODO: Known DLLs?
  141.  
  142.     -- Paging file
  143.     result['status-pagingfiles'], result['pagingfiles']                         = reg_get_value(smbstate, openhklm_result['handle'], "SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Memory Management", "PagingFiles")
  144.     result['status-clearpagefileatshutdown'], result['clearpagefileatshutdown'] = reg_get_value(smbstate, openhklm_result['handle'], "SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Memory Management", "ClearPageFileAtShutdown")
  145.  
  146.     -- OS Information
  147.     result['status-csdversion'], result['csdversion']              = reg_get_value(smbstate, openhklm_result['handle'], "Software\\Microsoft\\Windows NT\\CurrentVersion", "CSDVersion")
  148.     if(result['status-csdversion'] == false) then
  149.         result['csdversion'] = "(no service packs)"
  150.     end
  151.     result['status-currentbuildnumber'], result['currentbuildnumber']  = reg_get_value(smbstate, openhklm_result['handle'], "Software\\Microsoft\\Windows NT\\CurrentVersion", "CurrentBuildNumber")
  152.     result['status-currenttype'], result['currenttype']                = reg_get_value(smbstate, openhklm_result['handle'], "Software\\Microsoft\\Windows NT\\CurrentVersion", "CurrentType")
  153.     result['status-currentversion'], result['currentversion']          = reg_get_value(smbstate, openhklm_result['handle'], "Software\\Microsoft\\Windows NT\\CurrentVersion", "CurrentVersion")
  154.     result['status-installdate'], result['installdate']                = reg_get_value(smbstate, openhklm_result['handle'], "Software\\Microsoft\\Windows NT\\CurrentVersion", "InstallDate")
  155.     if(result['status-installdate'] ~= false) then
  156.         result['installdate'] = os.date("%Y-%m-%d %H:%M:%S", result['installdate'])
  157.     end
  158.  
  159.     result['status-productname'], result['productname']                        = reg_get_value(smbstate, openhklm_result['handle'], "Software\\Microsoft\\Windows NT\\CurrentVersion", "Productname")
  160.     result['status-registeredowner'], result['registeredowner']                = reg_get_value(smbstate, openhklm_result['handle'], "Software\\Microsoft\\Windows NT\\CurrentVersion", "RegisteredOwner")
  161.     result['status-registeredorganization'], result['registeredorganization']  = reg_get_value(smbstate, openhklm_result['handle'], "Software\\Microsoft\\Windows NT\\CurrentVersion", "RegisteredOrganization")
  162.     result['status-systemroot'], result['systemroot']                          = reg_get_value(smbstate, openhklm_result['handle'], "Software\\Microsoft\\Windows NT\\CurrentVersion", "SystemRoot")
  163.     result['status-producttype'], result['producttype']                        = reg_get_value(smbstate, openhklm_result['handle'], "System\\CurrentControlSet\\Control\\ProductOptions", "ProductType")
  164.     result['status-productsuite'], result['productsuite']                      = reg_get_value(smbstate, openhklm_result['handle'], "System\\CurrentControlSet\\Control\\ProductOptions", "ProductSuite")
  165.  
  166.     -- Driver information
  167.     result['status-video_driverdesc'], result['video_driverdesc']        = reg_get_value(smbstate, openhklm_result['handle'], "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E968-E325-11CE-BFC1-08002BE10318}\\0000", "DriverDesc")
  168.  
  169.     -- Software versions
  170.     result['status-ie_version'], result['ie_version']              = reg_get_value(smbstate, openhklm_result['handle'], "Software\\Microsoft\\Internet Explorer\\Version Vector", "IE")
  171.     result['status-ff_version'], result['ff_version']              = reg_get_value(smbstate, openhklm_result['handle'], "Software\\Mozilla\\Mozilla Firefox", "CurrentVersion")
  172.     if(result['status-ff_version'] == false) then
  173.         result['ff_version'] = "<not installed>"
  174.     end
  175.  
  176.     msrpc.stop_smb(smbstate)
  177.     
  178.     return true, result
  179. end
  180.  
  181. action = function(host)
  182.  
  183.     status, result = get_info_registry(host)
  184.  
  185.     if(status == false) then
  186.         if(nmap.debugging() > 0) then
  187.             return "ERROR: " .. result
  188.         else
  189.             return nil
  190.         end
  191.     else
  192.  
  193.         local response = " \n"
  194.  
  195.         if(result['status-os'] == true) then
  196.             response = response .. string.format("OS Details\n")
  197.             response = response .. string.format("|_ %s %s (%s %s build %s)\n",                   result['productname'], result['csdversion'], result['producttype'], result['currentversion'], result['currentbuildnumber'])
  198.             response = response .. string.format("|_ Installed on %s\n",                          result['installdate'])
  199.             response = response .. string.format("|_ Registered to %s (organization: %s)\n",      result['registeredowner'], result['registeredorganization'])
  200.             response = response .. string.format("|_ Path: %s\n",                                 result['path'])
  201.             response = response .. string.format("|_ Systemroot: %s\n",                           result['systemroot'])
  202.             response = response .. string.format("|_ Page files: %s (cleared at shutdown => %s)\n", result['pagingfiles'], result['clearpagefileatshutdown'])
  203.     
  204.             response = response .. string.format("Hardware\n")
  205.             for i = 0, result['number_of_processors'] - 1, 1 do
  206.                 if(result['status-processornamestring'..i] == false) then
  207.                     result['status-processornamestring'..i] = "Unknown"
  208.                 end
  209.  
  210.                 response = response .. string.format("|_ CPU %d: %s [%dmhz %s]\n", i, result['processornamestring'..i], result['~mhz'..i], result['vendoridentifier'..i])
  211.                 response = response .. string.format("|_ Identifier %d: %s\n",  i, result['identifier'..i])
  212.             end
  213.             response = response .. string.format("|_ Video driver: %s\n", result['video_driverdesc'])
  214.  
  215.             response = response .. string.format("Browsers\n")
  216.             response = response .. string.format("|_ Internet Explorer %s\n", result['ie_version'])
  217.             if(result['status-ff_version']) then
  218.                 response = response .. string.format("|_ Firefox %s\n", result['ff_version'])
  219.             end
  220.         elseif(result['status-productname'] == true) then
  221.             if(nmap.debugging() > 0) then
  222.                 response = response .. string.format("|_ Access was denied for certain values; try an administrative account for more complete information\n")
  223.             end
  224.             response = response .. string.format("OS Details\n")
  225.             response = response .. string.format("|_ %s %s (%s %s build %s)\n",                   result['productname'], result['csdversion'], result['producttype'], result['currentversion'], result['currentbuildnumber'])
  226.             response = response .. string.format("|_ Installed on %s\n",                          result['installdate'])
  227.             response = response .. string.format("|_ Registered to %s (organization: %s)\n",      result['registeredowner'], result['registeredorganization'])
  228.             response = response .. string.format("|_ Systemroot: %s\n",                           result['systemroot'])
  229.         else
  230.             if(nmap.debugging() > 0) then
  231.                 response = string.format("|_ Account being used was unable to probe for information, try using an administrative account\n")
  232.             else
  233.                 response = nil
  234.             end
  235.         end
  236.  
  237.         return response
  238.     end
  239. end
  240.  
  241.  
  242.