Installing Metasploit on WSL

https://mirrors.tuna.tsinghua.edu.cn/help/debian/清华的debian国内镜像

将系统语言改为中文

1
2
3
sudo dpkg-reconfigure locales
#勾上zh_CN GB2312 zh_CN.GBK GBK zh_CN.UTF-8 UTF-8
#重启生效

安装metasploit-framework

1
2
3
sudo nano /etc/apt/sources.list
#加入下面这一行
deb http://mirrors.aliyun.com/kali kali-rolling main non-free contrib
1
2
3
sudo wget -q -O - https://archive.kali.org/archive-key.asc | sudo apt-key add
sudo apt update
sudo apt install metasploit-framework

连接数据库

WSL中metasploit链接数据库有点麻烦,如果按照正常操作会报下面这个错误。

1
2
3
4
5
msfconsole
>db_status
postgresql selected,no connect
>msfdb init
System has not been booted with systemd as init system (PID 1). Can't operate.

原理是wsl启动的时候没systemd。

解决方法

启动数据库服务

1
2
3
msfdb init
sudo service postgresql start
sudo service postgresql status

手动建立数据库用户,数据库

1
2
3
4
5
6
7
# 
cd /etc/postgresql/13/main
sudo -u postgres psql
alter user postgres password 'root';
create user msf with password 'metasploit' createdb;
create database msf with owner=msf;
quit

在metasploit中链接

1
2
3
4
msfconsole
#db_connect 数据库用户名:数据库密码@数据库ip[:数据库端口]/数据库名
db_connect msf:metasploit@127.0.0.1:5958/msf
db_status

设置自动连接

1
sudo nano /usr/share/metasploit-framework/config/database.yml

将里面username,password改成自己设置的。

https://mirrors.tuna.tsinghua.edu.cn/help/debian/ Tsinghua’s Debian domestic mirror

Change System Language to Chinese

1
2
3
sudo dpkg-reconfigure locales
# Select zh_CN GB2312, zh_CN.GBK GBK, zh_CN.UTF-8 UTF-8
# Reboot to take effect

Install metasploit-framework

1
2
3
sudo nano /etc/apt/sources.list
# Add the following line
deb http://mirrors.aliyun.com/kali kali-rolling main non-free contrib
1
2
3
sudo wget -q -O - https://archive.kali.org/archive-key.asc | sudo apt-key add
sudo apt update
sudo apt install metasploit-framework

Connect to Database

Connecting Metasploit to the database in WSL can be a bit tricky. Following the normal procedure might result in the following error:

1
2
3
4
5
msfconsole
> db_status
postgresql selected,no connect
> msfdb init
System has not been booted with systemd as init system (PID 1). Can't operate.

The reason is that WSL does not start with systemd.

Solution

Start the database service

1
2
3
msfdb init
sudo service postgresql start
sudo service postgresql status

Manually create the database user and database

1
2
3
4
5
6
7
# 
cd /etc/postgresql/13/main
sudo -u postgres psql
alter user postgres password 'root';
create user msf with password 'metasploit' createdb;
create database msf with owner=msf;
quit

Connect within Metasploit

1
2
3
4
msfconsole
# db_connect database_username:database_password@database_ip[:database_port]/database_name
db_connect msf:metasploit@127.0.0.1:5958/msf
db_status

Set up automatic connection

1
sudo nano /usr/share/metasploit-framework/config/database.yml

Change the username and password inside to the ones you have set.


Installing Metasploit on WSL
https://tokisaki.top/blog/wsl-metasploit-config/
作者
Tokisaki Galaxy
发布于
2020年10月25日
许可协议