Loading

metasploit + python打造批量漏洞检测工具

 

metasploit是一款大家都十分熟悉的漏洞利用工具,其中集成了大量的漏洞利用程序,如果我们能够搜寻大量的符合一定条件的主机并使用metasploit进行检测是不是会很有意思呢?想一想就有点小激动呢。。。

本文中利用metasploit的api接口对其进行操作,使用censys、zoomeye以及shodan批量搜寻主机,然后使用metasploit对找到的主机进行检测。不过关于metasploit的api接口并没有找到详细的说明文档,我通过翻阅其代码在一行行注释中将其所有的api函数整理出来放在这里(http://s0m30ne.com/2016/01/21/metasploit-API/),有兴趣的可以看一下。

关于详细的实现过程这里就不说了,具体的大家可以直接去代码里看,代码链接下面会给出,这里只贴出一些利用方法以及应用举例。

==============================
|--\ \  / |\  /|  /----  |----
|--/  \/  | \/ |  |---\  |----
|     ||  |    |  ____|  |
==============================
               made by s0m30ne
------------------------------

Usage: python msf_python.py [options] 

Options:  
    -h, --help            show this help message and exit  
    -n, --normal          normal mode  
    -s SEARCH, --search=SEARCH  
                          chose a search engine, for example: censys, zoomeye or shodan  
    -f FILE_NAME, --file=FILE_NAME  
                          the poc file you want to run  
    -t THREAD_NUM, --threads=THREAD_NUM  
                          set the thread num

##准备工作:
(1)安装Python的msgpack类库,MSF官方文档中的数据序列化标准就是参照msgpack。

root@kali:~# apt-get install python-setuptools
root@kali:~# easy_install msgpack-python

(2)创建createdb_sql.txt:

create database msf;
create user msf with password 'msf123';
grant all privileges on database msf to msf;

(3)在PostgreSQL 执行上述文件:

root@kali:~# /etc/init.d/postgresql start
root@kali:~# sudo -u postgres /usr/bin/psql < createdb_sql.txt

(4)创建setup.rc文件

db_connect msf:msf123@127.0.0.1/msf
load msgrpc User=msf Pass='abc123'

(5)启动MSF并执行载入文件

root@kali:~# msfconsole -r setup.rc
*SNIP*
[*] Processing setup.rc for ERB directives.
resource (setup.rc)> db_connect msf:msf123@127.0.0.1/msf
[*] Rebuilding the module cache in the background...
resource (setup.rc)> load msgrpc User=msf Pass='abc123'
[*] MSGRPC Service: 127.0.0.1:55552
[*] MSGRPC Username: msf
[*] MSGRPC Password: abc123
[*] Successfully loaded plugin: msgrpc

(6)安装msfrpc

root@kali:~# git clone git://github.com/SpiderLabs/msfrpc.git msfrpc
root@kali:~# cd msfrpc/python-msfrpc
root@kali:~# python setup.py install

(7)在config.txt中配置你的token信息

后面每次使用时都需要先使用msfconsole -r setup.rc启动msf

##使用方法
使用python msf_python.py -n或者直接使用python msf_python.py进入普通模式,使用python msf_python.py -s [censys,shodan,zoomeye]选择相应的搜索引擎,默认选择的是censys

启动脚本后的使用方式和msf基本相同,支持msf的所有命令,不同之处在于你没必要设置RHOST或者RHOSTS,后面的扫描过程中程序会自己进行设置。额外需要你设置的是QUERYPAGE选项,QUERY是你选择的搜索引擎下的搜索条件,PAGE则是你想要搜索的页数(默认为10)。

通过python msf_python.py -c COMMAND命令用户可以使用自定义的命令,比如执行python、ruby等poc文件或者ping等系统命令,但是注意命令中通过%s留出IP接口,比如你可以通过下面的形式执行特定的poc文件:python msf_python.py -c "python poc.py %s"

通过-c参数指定要执行的命令后,设置好QUERYPAGE参数就可以通过exploit命令执行了。

你可以通过-t参数指定线程数。

##测试样例
首先,我演示一下使用该工具检测ssh弱密码的过程。

检测过程如下图所示:

另外,也可以使用-f参数指定poc进行检测,在此贴出使用该工具批量测试jenkins反序列化的过程。

指定搜索条件和搜索页数,并使用exploit启动程序

检测过程如下图所示:

 

posted @ 2016-11-06 18:15  ssooking  阅读(2201)  评论(0编辑  收藏  举报