metasploit使用外部數據庫(TODO)

metasploit不能使用外部的pgsql數據庫搞得一直很蛋疼,這篇小記只是記錄下如何一步步讓metasploit使用外部的pgsql,本篇文章中使用pgsql的docker

安裝ruby

此處使用 rbenv 安裝 ruby

克隆rbenv倉庫

git clone --depth=1 https://github.com/rbenv/rbenv.git ~/.rbenv

編譯bash擴展加速rbenv,可選

cd ~/.rbenv && src/configure && make -C src

把rbenv加到環境變量

echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

rbenv設置

rbenv init # 跟隨命令的輸出設置rbenv shell

安裝ruby-build插件,爲了支持rbenv install 命令

git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build

如果是國內用戶,可以加上rbenv cache鏡像

git clone https://github.com/andorchen/rbenv-china-mirror.git "$(rbenv root)"/plugins/rbenv-china-mirror

查看 metasploit 官方開發使用版本,https://github.com/rapid7/metasploit-framework/blob/master/.ruby-version

我這裏看到的是 2.6.6,就安裝這個版本

rbenv install 2.6.6
rbenv local 2.6.6

如果你是國內用戶,可以設置一些鏡像

gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/

安裝bundler並設置鏡像

gem install bundler

bundle config mirror.https://rubygems.org https://gems.ruby-china.com

安裝 metasploit

詳細可參見 https://github.com/rapid7/metasploit-framework/wiki/Setting-Up-a-Metasploit-Development-Environment

我們已經安裝了ruby,緊接着安裝依賴

sudo apt update && sudo apt install -y git autoconf build-essential libpcap-dev libpq-dev zlib1g-dev libsqlite3-dev

克隆 metasploit

git clone --depth=1 https://github.com/rapid7/metasploit-framework.git

安裝metasploit運行所需的ruby庫

cd metasploit-framework && bundler install

至此,metasplot 已經可以使用

./msfconsole

如果進入了 msf console 證明已經正確安裝,並且運行後會在你的創建一個 ~/.msf4 文件夾,這個我們後面會用到

設置metasploit使用外部數據庫

啓動pgsql

首先啓動一個postgresql docker

參見 https://hub.docker.com/_/postgres

這裏我直接使用官方提供的命令

docker run -d -p 5432:5432\
    --name some-postgres \
    -e POSTGRES_PASSWORD=mysecretpassword \
    -e PGDATA=/var/lib/postgresql/data/pgdata \
    -v /custom/mount:/var/lib/postgresql/data \
    postgres

或者你可以使用 docker-compose,但是記得改掉密碼和掛載目錄

然後我們創建兩個數據庫 msf 和 msftest,具體怎麼創建這裏不展開,可以使用數據庫管理工具

配置 msf 數據庫連接

在 ~/.msf4 文件夾下面創建一個文件 database.yml,即 ~/.msf4/database.yml

development: &pgsql
  adapter: postgresql
  database: msf
  username: postgres
  password: mysecretpassword
  host: 127.0.0.1
  port: 5432
  pool: 200

production: &production
  <<: *pgsql

test:
  <<: *pgsql
  database: msftest
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章