IVRE簡介
IVRE(又名DRUNK)是一款開源的網(wǎng)絡(luò)偵查框架工具,IVRE使用Nmap、Zmap進行主動網(wǎng)絡(luò)探測、使用Bro、P0f等進行網(wǎng)絡(luò)流量被動分析,探測結(jié)果存入數(shù)據(jù)庫中,方便數(shù)據(jù)的查詢、分類匯總統(tǒng)計。
網(wǎng)上已有部分文章對IVRE的使用做介紹,由于文章時間較早,IVRE的安裝、命令執(zhí)行等均有所改變,本文使用最新版IVRE做講解,并增加部分其它文章未提及的Nmap模板參數(shù)設(shè)置、Web界面搜索使用等內(nèi)容。
IVRE官方網(wǎng)站:https://ivre.rocks
GitHub:https://github.com/cea-sec/ivre
IVRE安裝
使用Docker方式安裝
$ mkdir ivre
$ cd ivre
//拉取Docker鏡像
$ mkdir -m 1777 var_{lib,log}_{mongodb,neo4j} ivre-share
$ wget -q https://ivre.rocks/Vagrantfile
//啟動Docker
$ vagrant up --no-parallel
//進入Docker - ivreclient shell
$ docker exec -it ivreclient bash
root@e809cb41cb9a:/#
//查看ivre命令幫助
root@e809cb41cb9a:/#ivre --help
安裝腳本會在ivre目錄中創(chuàng)建幾個新的文件夾,這些文件夾用于掛載到Docker容器中存放數(shù)據(jù)庫等信息。ivre-share會掛載容器ivreclient的根目錄下,之后的掃描操作我們也在這個目錄下執(zhí)行,方便主機和容器間的文件交互。
數(shù)據(jù)庫初始化
第一次使用時,對4個數(shù)據(jù)庫進行初始化操作(使用過程中,如需完全重新導(dǎo)入數(shù)據(jù),也要對相應(yīng)數(shù)據(jù)庫做初始化設(shè)置):
$ ivre scancli --init
$ ivre ipinfo --init
$ ivre ipdata --init
$ ivre runscansagentdb --init
獲取IP位置數(shù)據(jù)
ipdata數(shù)據(jù)包含了IP對應(yīng)的地理位置信息。
$ ivre ipdata --download
$ ivre ipdata --import-all --no-update-passive-db
安裝缺失Python模塊
執(zhí)行ivre命令后,提示部分Python模塊缺失,下面進行這部分模塊的安裝:
apt-get update
apt-get install python-pip
//Python module PIL: 4.3.0: missing
pip install Pillow
//Python module krbV: missing
apt-get install libkrb5-dev
pip install python-krbv
//Python module MySQLdb: missing
apt-get install python-mysqldb
//安裝VIM,方便編輯文件
apt-get install vim
IVRE使用
被動偵查
IVRE可以使用Bro和p0f對流量分析,并將結(jié)果導(dǎo)入到數(shù)據(jù)庫中。
個人感覺網(wǎng)絡(luò)流量分析這部分,IVRE所能提供的功能并不實用,略過,感興趣的同學(xué),請參考官方文檔。
需對流量實時或回放分析,Windows平臺下推薦使用成都本土科技公司科來的科來網(wǎng)絡(luò)分析系統(tǒng),技術(shù)交流版免費使用。
Flow analysis
網(wǎng)絡(luò)數(shù)據(jù)流的圖形展示,這個比較炫酷,簡單介紹下。先在主機上使用Wireshark抓一段時間包,數(shù)據(jù)包保存為pcap格式,命名為test.pcap,放入IVRE的共享文件夾ivre-share中,執(zhí)行命令處理數(shù)據(jù)包:
$ cd /ivre-share
//使用Bro對數(shù)據(jù)包進行處理,完成后再當(dāng)前文件夾生成.log文件
$ bro -r test.cap
//初始化flowcli數(shù)據(jù)庫
$ ivre flowcli --init
//將.log文件導(dǎo)入數(shù)據(jù)庫
$ ivre bro2db *.log
查看導(dǎo)入的流量統(tǒng)計數(shù)據(jù)
$ ivre flowcli --count
585 clients
1259 servers
3629 flows
打開瀏覽器,輸入http://your-host-ip/flow.html 查看網(wǎng)絡(luò)流量動畫。

主動偵查
主動偵查部分是重點介紹的內(nèi)容,通常環(huán)境下,企業(yè)內(nèi)網(wǎng)環(huán)境的網(wǎng)絡(luò)流量不可能完全經(jīng)過安全測試服務(wù)器,需要了解內(nèi)網(wǎng)全部服務(wù)器的端口、服務(wù)情況,需要使用Nmap、Masscan等工具進行主動探測掃描。
使用Nmap掃描
隨機掃描1000個IP
進入Docker – ivreclient shell后,執(zhí)行:
$ cd /ivre-share
$ ivre runscans --routable --limit 1000 --country CN --output=XMLFork
這條命令會執(zhí)行一個隨機掃描,掃描1000個中國地區(qū)的IP,默認開啟30個Nmap并行進程。使用ivre help runscans查看掃描相關(guān)的詳細幫助內(nèi)容。掃描后在/ivre-share目錄下生成掃描結(jié)果文件,包含端口開放、服務(wù)信息、網(wǎng)頁截圖等。
掃描后清理緩存文件:
rm -fr /ivre-share/scans/COUNTRY-CN/ current/
導(dǎo)入掃描結(jié)果
掃描完成后,將掃描結(jié)果導(dǎo)入數(shù)據(jù)庫:
$ cd /ivre-share
$ ivre scan2db -c ROUTABLE-CN-001 -s Parrot -r /ivre-share/scans/COUNTRY-CN/up/
這里ROUTABLE-CN-001是這次掃描結(jié)果的分類名稱,MySource是掃描來源名稱,方便指揮對掃描結(jié)果的分類搜索。
除了在本地執(zhí)行掃描工作外,IVRE還可以設(shè)置多個掃描在代理服務(wù)器,在主服務(wù)器上執(zhí)行ivre {runscansagent|runscansagentdb}命令進行代理服務(wù)器的掃描任務(wù)下發(fā)和結(jié)果導(dǎo)入。
命令執(zhí)行后提示xxx results imported,則導(dǎo)入成功。
指定掃描IP目標(biāo)
通過ivre help runscans命令查看IVRE的幫助文檔,找到兩個指定掃描IP的參數(shù),--range和--network,--range指定掃描IP的起止范圍,--network參數(shù)可指定一個網(wǎng)段。例:
$ ivre runscans --network 45.32.14.0/24 --output=XMLFork
使用--output=CommandLine 參數(shù)來看下當(dāng)前執(zhí)行的完整命令:
root@67d2aa11797f:/ivre-share# ivre runscans --network 45.32.14.0/24 --output CommandLine
Command line to run a scan with template default
nmap -A -PS -PE -sS -vv --host-timeout 15m --script-timeout 2m --script '(default or discovery or auth) and not (broadcast or brute or dos or exploit or external or fuzzer or intrusive)'
使用Nmap模板掃描
--nmap-template參數(shù)可指定Nmap掃描模板,在/etc/ivre.conf中添加模板。
Nmap模板參考:
vi /etc/ivre.conf
//創(chuàng)建一個掃描1-65535端口,名稱為`full-port`的Nmap掃描模板,在文件中添加以下內(nèi)容(復(fù)制default模板并修改部分參數(shù))
NMAP_SCAN_TEMPLATES["full-ports"] = NMAP_SCAN_TEMPLATES["default"].copy()
NMAP_SCAN_TEMPLATES["full-ports"]["ports"] = "1-65535"
NMAP_SCAN_TEMPLATES["full-ports"]["scripts_categories"] = ['(default or discovery or auth) and not (broadcast or brute or dos or exploit or external or fuzzer or intrusive)']
NMAP_SCAN_TEMPLATES["full-ports"]["scripts_exclude"] = []
添加模板參數(shù)后后再看看掃描命令:
root@67d2aa11797f:/ivre-share# ivre runscans --network 45.32.14.0/24 --output CommandLine --nmap-template full-port
Command line to run a scan with template full-port
nmap -A -PS -PE -sS -vv -p 1-65535 --host-timeout 15m --script-timeout 2m --script '(default or discovery or auth) and not (broadcast or brute or dos or exploit or external or fuzzer or intrusive)'
相比之前的命令,增加了-p 1-65535參數(shù),執(zhí)行全端口掃描。
模板中可以設(shè)置的其它參數(shù),我在網(wǎng)上沒找到詳細的官方介紹文檔,可以在IVRE的python文件中查找:/usr/local/lib/python2.7/dist-packages/ivre/nmapopt.py通過模板,你可以定制你的特定掃描需求。
掃描結(jié)果使用
執(zhí)行掃描并導(dǎo)入數(shù)據(jù)庫后,有三種方式使用這些內(nèi)容:
ivre scancli命令行工具
- Python模塊ivre.db
- IVRE Web界面
- CLI: ivre scancli
例:使用命令行查看所有開放了22端口的主機:
$ ivre scancli --port 22
See the output of .
使用ivre help scancli查看詳細的幫助信息。
Python 模塊
例:
$ python
>>> from ivre.db import db
>>> db.nmap.get(db.nmap.flt_empty)[0]
在Python shell執(zhí)行help(db.nmap)查看模塊的幫助信息。
Web界面
瀏覽器輸入http://your-host-ip訪問IVRE Web界面,
結(jié)語
在復(fù)雜的企業(yè)內(nèi)網(wǎng),定期使用IVRE對內(nèi)網(wǎng)的端口掃描探測并保存結(jié)果,便于安全工作人員及時掌握內(nèi)網(wǎng)的服務(wù)開放、是否存在弱口令等情況。
日常的滲透測試工作中,小規(guī)模的IP掃描,建議使用另一款工具——斯巴達(SPARTA,Kali自帶,Github鏈接),輸入IP,自動進行Nmap掃描,根據(jù)服務(wù)探測結(jié)果調(diào)用相關(guān)工具(如Hydra、Dibuster等)進行下一步的測試。