欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Metasploit 安装与部署

程序员文章站 2022-03-24 09:08:40
...

前言

Metasploit是一款开源的安全漏洞检测工具,可以帮助安全和IT专业人士识别安全性问题,验证漏洞的缓解措施,并管理专家驱动的安全性进行评估,提供真正的安全风险情报。这些功能包括智能开发,代码审计,Web应用程序扫描,社会工程。团队合作,在Metasploit和综合报告提出了他们的发现。(来自百度百科)

总之是一款非常优秀的开源渗透测试框架。

 

 

 

安装Metasploit

本文只讨论在Linux系统下的安装,  包括Ubuntu、Centos、Deepin等,  读者可以直接安装Kali操作系统,  上面集成了许多工具,  就不用一个个去安装了。

安装方式两种:

1.  一键安装

这也是官方推荐的安装方法,  基本上一步到位:

curl https://raw.githubusercontent.com/rapid7/metasploit-omnibus/master/config/templates/metasploit-framework-wrappers/msfupdate.erb > msfinstall && \
  chmod 755 msfinstall && \
  ./msfinstall

我这边的速度非常慢...所以我就使用第二种安装方法:

2.  源码编译安装

先安装依赖:

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

接着从github上clone项目到本地目录:

git clone aaa@qq.com:rapid7/metasploit-framework.git

 由于msf是基于Ruby开发的,  所以还需要安装Ruby和Gem。

Ruby 是一种语言,是某些软件包代码的执行环境。而Gem是管理这些基于Ruby程序的程序。 

进入刚刚clone下来的项目中,  并查看Ruby版本:

cd metasploit-framework-5.0.74/

cat .ruby-version 

我的系统自带了Ruby和Gem,  安装过程就不再赘述了。

紧接着,  安装 Bundler 来打包安装源代码:

Bundler 能够跟踪并安装所需的特定版本的 gem,以此来为 Ruby 项目提供一致的运行环境。

Bundler 是 Ruby 依赖管理的一根救命稻草,它可以保证你所要依赖的 gem 如你所愿地出现 在开发、测试和生产环境中。 利用 Bundler 启动项目简单到只用一条命令:bundle install

安装Bundle:

sudo gem install bunlder

# sudo apt-get install bundler  (非必须)

然后在源代码目录下执行即可: (之后是需要一个漫长的安装时间)

bundle install

 bundle命令需要有Gemfile来引导执行,  可以在项目目录下看到Gemfile文件。

Metasploit 安装与部署

Metasploit 安装与部署

 

 

 

过程中遇到的问题

说一下我这里遇到的坑,  在执行bundle install命令的时候,  报出了如下错误:

Metasploit 安装与部署

关键错误如下: 

Traceback (most recent call last):
	1: from /usr/local/bin/bundle:23:in `<main>'
/usr/local/bin/bundle:23:in `load': cannot load such file -- /usr/share/rubygems-integration/all/gems/bundler-1.17.3/exe/bundle (LoadError)

看起来是bundler文件损坏导致的不能正确执行, 

Google了一下得到两种解决方法:

  •  Gem版本过旧

Metasploit 安装与部署

于是升级了一下,  还是出现同样的错误。

  •  bundle损坏

用命令: gem uninstall  bundle 来卸载并重新安装bundle。

发现还是没有解决,  可能是bundle没有复原成功,  更新后的gem未与bundle完成整合。

于是再用:

gem update --system

gem pristine bundle

即可完成复原bundle为初始状态,  这样就可以对应上gem update后的system了。

 

 

 

安装postgresql

安装postgresql数据库:

sudo apt-get install postgresql

安装数据库的时候会自动创建系统用户postgres,数据库用户postgres,数据库postgres 

然后再启动它

sudo systemctl start postgresql

切换到postgres用户(需要root),  登陆postgresql数据库,首次登陆没有密码

sudo su - postgres  # 切换用户

psql -h localhost -p 5432 -U postgres -W

修改数据库用户postgres的密码为postgres: 

\password postgres

然后创建一个metasploit专用的数据库msf:

CREATE DATABASE msf;  # 创建数据库msf

\l;  # 查看所有数据库

Metasploit 安装与部署 

 

 

 

配置及启动

然后退出postgres用户,  到metasploit目录下配置文件 database.yml:

development: &pgsql
  adapter: postgresql
  database: msf 
  username: postgres
  password: postgres
  host: localhost
  port: 5432
  pool: 200
  timeout: 5

然后启动metasploit:

msfconsole

Metasploit 安装与部署

相关标签: Metasploit