在继续之前,有必要更新一下Ruby,Kali自带的版本为ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]。这个已经很老了,不修改的话后面bundle install会出现一个问题导致无法继续安装,我也不知道为啥,就是说有一个库对ruby的版本要求在2.1或者2.1以上。参照GitHub关于更新Ruby的命令。具体链接为https://github.com/rapid7/metasploit-framework/wiki/Setting-Up-a-Metasploit-Development-Environment。我就不在这里累赘了。
首先,从github上下载一份Metasploit的源码,并保持在msf文件夹中,命令如下:
git clone https://github.com/rapid7/metasploit-framework.git metasploit-framework |
然后打开RubyMine IDE,选择Open,定为到我们之前下的msf文件夹,选择一个可以执行的rb脚本,在这里我选择msfconsole为例。如下图所示:
在介绍下一步之前,插播一点小知识——Ruby Gem介绍。
Gem是一个管理Ruby库和程序的标准包,它通过Ruby Gem(如https://rubygems.org/)源来查找、安装、升级和卸载软件包,非常的便捷。由于国内网络原因(你懂的),导致 rubygems.org 存放在 Amazon S3 上面的资源文件间歇性连接失败。所以,推荐使用使用http://ruby.taobao.org/来代替系统默认的Gem源。来看一下系统默认的Gem源,命令如下:
gem source |
得到结果如下所示:
接下来,我就把它默认的Gem源给删掉,然后添加淘宝的Gem源.命令如下:
gem sources --remove http://rubygems.org/ gem sources -a https://ruby.taobao.org/ gem sources -l |
可以看到,结果如下:
介绍一些Gem的命令吧.
更新源cache,命令如下:
gem source -u |
查看源里面有哪些软件,命令如下:
gem query -r -a |
也可以使用正则表达式查看指定的内容,假如查找metasploit相关的,命令如下:
gem query -r -n 'metasploit' |
得到如下图所示:
其他gem的命令可以使用help查看:
gem help commands |
得到如下图所示:
好了,关于gem暂时介绍到这里了。继续前面的话题。加载msfconsole的Ruby脚本之后,我们选择工具栏Run下的Run运行msfconsole Ruby脚本。
接下来的一部分内容出现了问题,可以跳过!!!
单击运行后,得到如下图所示的结果,包含很多错误:
因为没有安装相关的gem库,所有运行出现错误,那现在就在RubyMine里面安装相关的库吧。在工具栏中选择File下面的Settings,在Language&Frameworks下选择Ruby SDK and Gems,然后在右边的框中选择加号进行添加。截个图吧:
这里有一点需要主要的地方,点击加号之后,我们需要把Manage gem repositories改为淘宝的Gem库,RubyMine默认的库访问不了。截个图:
接下来,就是选择报错的库进行安装了,这又是一个漫长的过程,每次安装完一个相应的库之后,运行肯定又会出错,提示需要安装其他的库。不断的重复,直到最后运行不出错了,才算所以需要的库都安装好了。在此就不重复该过程了。
注意,在安装pg相关库时,可能会出现如下错误:
Following gems were not installed: pg (0.18.1): Error installing pg: ERROR: Failed to build gem native extension. /usr/bin/ruby1.9.1 extconf.rb checking for pg_config... yes Using config values from /usr/bin/pg_config You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application. You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application. checking for libpq-fe.h... no Can't find the 'libpq-fe.h header *** extconf.rb failed *** Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers. Check the mkmf.log file for more details. You may need configuration options. Provided configuration options: --with-opt-dir --without-opt-dir --with-opt-include --without-opt-include=${opt-dir}/include --with-opt-lib --without-opt-lib=${opt-dir}/lib --with-make-prog --without-make-prog --srcdir=. --curdir --ruby=/usr/bin/ruby1.9.1 --with-pg --without-pg --enable-windows-cross --disable-windows-cross --with-pg-config --without-pg-config --with-pg_config --without-pg_config --with-pg-dir --without-pg-dir --with-pg-include --without-pg-include=${pg-dir}/include --with-pg-lib --without-pg-lib=${pg-dir}/lib Gem files will remain installed in /root/.gem/ruby/1.9.1/gems/pg-0.18.1 for inspection. Results logged to /root/.gem/ruby/1.9.1/gems/pg-0.18.1/ext/gem_make.out |
上文内容不用于商业目的,如涉及知识产权问题,请权利人联系博为峰小编(021-64471599-8017),我们将立即处理。