前言
为Metasploit渗透测试指南的补充。
一、启动数据库——PostgreSQL(metasploit默认数据库)
Metasploit支持MySQL、PostSQL和SQLite3数据库,默认使用PostgreSQL数据库。
可以使用三种方式来启动数据库(不仅仅是数据库)。
┌──(root㉿kali)-[/home/kali]
└─# /etc/init.d/postgresql start
┌──(root㉿kali)-[/home/kali]
└─# service postgresql start
┌──(kali㉿kali)-[~]
└─$ systemctl start postgresql
init 是最初的进程管理方式——老掉牙
service 是init 的另一种实现——不是所有的linux都支持
systemd 则是一种取代 initd 的解决方案——推荐的最新方案
二、连接到数据库——新版本的一般都会自动连接了
最坑爹的是一开始一直显示连接失败,搞半天发现是数据库都没启动成功(一定要去看日志文件)。研究发现是配置文件中有些设置的编码方式当前系统不认。
链接: 简直是救命恩人
//msfdb status显示数据库的详细状态
msf6 > msfdb status
[*] exec: msfdb status
● postgresql.service - PostgreSQL RDBMS
Loaded: loaded (/lib/systemd/system/postgresql.service; disabled; preset: disabled)
Active: active (exited) since Sun 2023-10-01 09:20:46 EDT; 52min ago
Process: 2140 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
Main PID: 2140 (code=exited, status=0/SUCCESS)
CPU: 1ms
10月 01 09:20:46 kali systemd[1]: Starting postgresql.service - PostgreSQL RDBMS...
10月 01 09:20:46 kali systemd[1]: Finished postgresql.service - PostgreSQL RDBMS.
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
postgres 2106 postgres 5u IPv6 23935 0t0 TCP localhost:5432 (LISTEN)
postgres 2106 postgres 6u IPv4 23936 0t0 TCP localhost:5432 (LISTEN)
UID PID PPID C STIME TTY STAT TIME CMD
postgres 2106 1 0 09:20 ? Ss 0:00 /usr/lib/postgresql/15/bin/postgres -D /var/lib/postgresql/15/main -c config_file=/etc/post
[+] Detected configuration file (/usr/share/metasploit-framework/config/database.yml)
//db_status显示数据库的连接状态
msf6 > db_status
[*] Connected to msf. Connection type: postgresql.
显示成功连接到数据库,如果没有,那么连接到数据库
msf6 > db_connect postgres:toor@127.0.0.1/msfbook
[-] Connection already established. Only one connection is allowed at a time.
[-] Run db_disconnect first if you wish to connect to a different data service.
Current connection information:
[*] Connected to msf. Connection type: postgresql.
三、将Nmap的扫描结果导入到数据库中
//-oX选项会将扫描的结果生成一个xml报告(需要在后面指定报告的名字)
┌──(root㉿kali)-[/home/kali]
└─# nmap -Pn -sS -A -oX Subnet1 192.168.111.134
//书上说导入名字为Subnet1.xml,但是实际导入时发现不能加xml,因为使用“ls”命令发现生成的文件本身是不带xml格式后缀的
msf6 > db_import Subne1
//db_hosts命令会显示数据库中所有已保存的主机信息
msf6 > db_hosts -c address