Install metasploit frame on OS X in 2019.05

0x01 前言

每次需要使用msf的时候,都要打开kali,感觉不是很方便,于是在Mac下装了一个。不过本篇重点讲2019年5月安装时遇到的一些情况

*不需要额外下载PostgreSQL!!!*

0x02 安装&启动

安装

安装有这么几种方式:1,pkg包。2,命令行下载。3,git clone。我尝试过pkg包和命令行下载,git方式这里不提。

  • 命令行下载nightly installer
1
2
3
curl https://raw.githubusercontent.com/rapid7/metasploit-omnibus/master/config/templates/metasploit-framework-wrappers/msfupdate.erb > msfinstall && \
chmod 755 msfinstall && \
./msfinstall

当你看到successful字样,就知道安装成功了

  • pkg包下载

https://osx.metasploit.com/metasploitframework-latest.pkg

下载完点击安装,一路next step就可以了

采用这两种方式安装的msf,被放在/opt/metasploit-frame/路径下

1

配置路径

export PATH="/opt/metasploit-framework/bin:$PATH"添加到你的配置文件中,我的是~/.zshrc,这样就可以在终端中输入msfconsole直接启动了,别忘了source ~/.zshrc

配置PostgreSQL

当前版本(msf5)集成了大量环境依赖,并不需要进行额外的配置。尤其是PostgreSQL,网上很多的教程都需要额外安装它,但实际情况是它已经集成进msf中了。/opt/metasploit-framework/embedded/bin/就是依赖的存放处

2

有一点要注意的是,不连接数据库并不影响msf的使用~

直接使用集成的PostgreSQL命令行工具启动

1
2
/opt/metasploit-framework/embedded/bin/pg_ctl init -D ~/.msf4/db #选择数据库存放路径
/opt/metasploit-framework/embedded/bin/pg_ctl -D /Users/tokyocold/.msf4/db -l logfile start

启动成功,会在~/.msf4/db下生成PostgreSQL运行配置文件
3

通过lsof -i tcp:5433查看5433端口情况
4

msfconsole初始化

在终端输入msfdb init

1
msfdb init #输入用户名和密码

初始化成功之后,会在~/.msf4/下生成database.yml数据库连接配置文件
5

启动msfconsole

在终端输入msfconsole

1
msfconsole

运行成功
6

0x03 trouble shooting

  • 初始化PostgreSQL失败
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
initdb ~/.msf4/db

The files belonging to this database system will be owned by user "$whoami".
This user must also own the server process.

The database cluster will be initialized with locale en_US.UTF-8.
The default database encoding has accordingly been set to UTF8.
The default text search configuration will be set to "english".

creating directory ~/.msf4/db ... ok
creating subdirectories ... ok
selecting default max_connections ... 10
selecting default shared_buffers ... 400kB
creating configuration files ... ok
creating template1 database in ~/.msf4/db/ base/1 ... FATAL: could not create shared memory segment: Cannot allocate memory
DETAIL: Failed system call was shmget(key=1, size=1703936, 03600).
HINT: This error usually means that PostgreSQL's request for a shared memory segment exceeded available memory or swap space, or exceeded your kernel's SHMALL parameter. You can either reduce the request size or reconfigure the kernel with larger SHMALL. To reduce the request size (currently 1703936 bytes), reduce PostgreSQL's shared_buffers parameter (currently 50) and/or its max_connections parameter (currently 14).
The PostgreSQL documentation contains more information about shared memory configuration.
child process exited with exit code 1
initdb: removing data directory "~/.msf4/db"

solution:

  1. 重新启动你的电脑 it’ s annoying but it works

  2. https://benscheirman.com/2011/04/increasing-shared-memory-for-postgres-on-os-x/