Wednesday, March 14, 2012

Exporting MSF database content into CSV format

Hello everyone. So you have imported nmap scans into metasploit and created a workspace for every vlan in scope and suddenly the client ask you to give him all nmap scans in CSV format. If that is the case then this post is for you. I assume that you have installed postgres on your system and correctly configured it to be used by metasploit. I also assume the name of the database used by metasploit is msf_database. This value can be found within the database.yml file in your framework-x.x.x/config directory. So let's start then. The following commands are all you need to export addresses, ports and services from workspace whose id equals 2.

sudo su
su postgres 
psql -d msf_database -f /tmp/msf_in.txt -o /tmp/msf_out.txt
cat /tmp/msf_out.txt | tr "|" ";" | cut -d ";" -f "2-4" > myfile.csv


Where the content of msf_in.txt is:

select workspaces.name, hosts.address, services.port,services.name from (services join hosts on services.host_id=hosts.id)join workspaces on hosts.workspace_id=workspaces.id where workspaces.id=2;