此工具将不再由我维护。Rapid7 自身提供了更好的替代方案,如下所述: 如何远程运行 Metasploit
示例:
要使 msf 命令在 metasploit-framework 目录之外也可用,请设置 GEM_HOME 变量。 要找到必要的路径,请 cd 进入 metasploit-framework 目录并执行:
$ rvm gemdir
/usr/local/rvm/gems/ruby-2.5.1@metasploit-framework
$ rvm use 2.5.1@metasploit-framework
要将 Metasploit 作为守护进程启动,你需要运行 msfd 工具,默认情况下它监听 55554 端口。
$ ./msfd -a 127.0.0.1
要连接到守护进程,请使用 netcat,如下例所示:
$ nc 127.0.0.1 5554
一个用 Python 2.7 编写的远程 msfconsole,用于连接 Metasploit 的 msfrcpd 服务器。 此工具使您能够像 autopwn2 一样将模块作为守护进程永久加载到您的服务器上。 尽管它可以远程使用 msfrpcd 服务器,但建议在本地通过 SSH 或 Mosh shell 使用,因为未启用证书验证。
[*] Connecting to server:
Host => myDomain.com,
Port => 55553,
User => msf,
Pwd => ***,
SSL => True
[+] Successfully connected
[*] Console id: 19
, ,
/ \
((__---,,,---__))
(_) O O (_)_________
\ _ / |\
o_o \ M S F | \
\ _____ | *
||| WW|||
||| |||
=[ metasploit v4.12.22-dev-52b81f3 ]
+ -- --=[ 1577 exploits - 906 auxiliary - 272 post ]
+ -- --=[ 455 payloads - 39 encoders - 8 nops ]
+ -- --=[ Free Metasploit Pro trial: http://r-7.co/trymsp ]
msf >
Usage: Main.py [options]
Options:
-h, --help 显示此帮助信息并退出
-r RESOURCE, --resource=RESOURCE
资源文件的路径
-u USERNAME, --user=USERNAME
msfrpcd 上指定的用户名
-p PASSWORD, --pass=PASSWORD
msfrpcd 上指定的密码
-s, --ssl 启用 SSL
-P PORT, --port=PORT 要连接的端口
-H HOST, --host=HOST 服务器 IP
-c, --credentials 使用硬编码的凭据
-e, --exit 执行资源脚本后退出
使用 -c 选项可以使用 Main.py 中硬编码的凭据,你可以随意更改它们,这样就不必每次都使用凭据参数。
使用 -r 选项可以指定要从计算机加载到控制台的资源脚本。
这将加载一个资源脚本并使用硬编码的凭据:
python Main.py -c -r /root/resource/handler/allHandlers.rc
这将通过命令行参数登录到 msfrpcd 服务器:
python Main.py --ssl --port 55553 --host 127.0.0.1 --user msf --pass msf
首先,您必须已安装 Metasploit。如果您因没有图形环境等原因无法使用安装程序,请使用 Rapid7 的此指南:Nightly installers。 这将安装所有必要的依赖项:
curl https://raw.githubusercontent.com/rapid7/metasploit-omnibus/master/config/templates/metasploit-framework-wrappers/msfupdate.erb > msfinstall && \
chmod 755 msfinstall && \
./msfinstall
git clone https://github.com/allfro/pymetasploit.git pymetasploit
cd pymetasploit && sudo python setup.py install
另外,不要忘记启动您的 msfrpcd 服务器:
cd metasploit-framework/
ruby msfrpcd -U msf -P msf -p 55553
并且最好启动并连接到 PostgreSQL 数据库: 顺便说一下,请更改 echo 行中的密码。
sudo update-rc.d postgresql enable
sudo service postgresql start
echo "create database msf;create user msf with password 'password';grant all privileges on database msf to msf;" > createdb_sql.txt
sudo -u postgres /usr/bin/psql < /home/postgres/createdb_sql.txt
在 Metasploit 中:
db_connect msf:[email protected]/msf