作者:tanheyi@知道創宇404實驗室
日期:2021年3月23日
0x01 前言
不知道大家是否還記得 Heige 的這篇文章 《使用 ZoomEye 尋找 APT 攻擊的蛛絲馬跡》,Heige 在文章中闡述利用 ZoomEye 開放的歷史數據 API 接口嘗試追蹤 APT 的案例。那篇文章雖然過去很久了,但是仍然具有參考價值。為了讓廣大的安全研究者能夠更簡單、更方便的實現這些類似的操作,于是在 ZoomEye-python v2.0.4.2 中新增了 history和clear 命令。
0x02 更新內容
值得注意的是,由于本工具依賴于 ZoomEye 提供的 API ,所以僅支持高級用戶和 VIP 用戶使用 history 命令。
1. Search
本次更新在 search 命令新增了對掃描時間的展示和篩選, 通過 -filter 參數對掃描時間展示篩選,篩選的語法同樣是 -filter "key" / -filter "key=value" (支持正則表達式)。
例如展示掃描時間,例如:
zoomeye search "cidr:118.*.*.15/24" -filter "time"
ip time
118.*.*.9 2021-03-23 02:34:34
118.*.*.9 2021-03-22 18:12:37
118.*.*.11 2021-03-20 22:19:47
118.*.*.3 2021-03-20 19:58:58
118.*.*.5 2021-03-18 10:58:47
118.*.*.29 2021-03-16 09:32:15
118.*.*.11 2021-03-13 15:59:35
118.*.*.12 2021-03-13 15:11:42
118.*.*.37 2021-03-10 04:28:43
118.*.*.36 2021-03-08 22:02:40
118.*.*.9 2021-03-08 18:48:42
118.*.*.48 2021-03-08 18:48:32
118.*.*.24 2021-03-08 18:48:31
118.*.*.27 2021-03-08 18:48:27
118.*.*.11 2021-03-08 18:48:26
118.*.*.8 2021-03-08 00:08:51
118.*.*.29 2021-03-08 00:08:31
118.*.*.41 2021-03-05 23:47:51
118.*.*.23 2021-02-26 20:08:28
118.*.*.8 2021-02-25 09:01:39
對掃描時間進行篩選:
zoomeye search "cidr:118.*.*.15/24" -filter "time=^2021-03" -num 3
ip time
118.*.*.9 2021-03-23 02:34:34
118.*.*.9 2021-03-22 18:12:37
118.*.*.11 2021-03-20 22:19:47
在實際工作中有時候需要從 ZoomEye 獲取實時數據,因此在本次更新中為 search 命令添加了 force 參數,可以繞過本地緩存數據,直接從 ZoomEye 獲取數據,讓獲取數據的方式更加靈活。
2. 管道符
ZoomEye-python 能夠配合 sed/awk/grep 對輸出在屏幕上的內容進行二次操作,這里以 awk 為例做一個演示:
# 正常的輸出
$ zoomeye search "cidr:118.*.*.15/24"
ip:port service country app banner
118.*.*.9:22 ssh China OpenSSH SSH-2.0-OpenSSH_8.4p1-hpn14v22...
118.*.*.9:443 https China nginx HTTP/1.1 403 Forbidden\r\nServ...
118.*.*.11:443 https China nginx HTTP/1.1 403 Forbidden\r\nServ...
118.*.*.3:80 http China HTTP/1.1 403 Forbidden\nConte...
118.*.*.5:22 ssh China OpenSSH SSH-2.0-OpenSSH_8.4p1-hpn14v22...
118.*.*.29:80 http China HTTP/1.0 404 Not Found\r\nCont...
118.*.*.11:22 ssh China OpenSSH SSH-2.0-OpenSSH_8.4p1-hpn14v22...
......
total: 20
# awk 篩選后輸出
$ zoomeye search "cidr:118.*.*.15/24"|awk '/403 Forbidden/{print}'
118.*.*.9:443 https China nginx HTTP/1.1 403 Forbidden\r\nServ...
118.*.*.11:443 https China nginx HTTP/1.1 403 Forbidden\r\nServ...
118.*.*.3:80 http China HTTP/1.1 403 Forbidden\nConte...
118.*.*.37:80 http China HTTP/1.1 403 Forbidden\r\nServ...
118.*.*.9:80 http China nginx HTTP/1.1 403 Forbidden\r\nServ...
......
在上述案例中通過 awk 為 ZoomEye-python 的輸出進行了篩選,篩選出了 banner 含有 403 Forbidden 的內容,當還可以支持其他的一些操作,大家可以在日常使用中去發現。
3. 清理數據
在新版本的 ZoomEye-python 中添加了清理用戶數據和緩存數據命令 clear,為了防止緩存數據越用越多,占用存儲空間以及防止在公共設備上使用導致用戶數據泄漏。使用方式如下:
$zoomeye clear -h
usage: zoomeye clear [-h] [-setting] [-cache]
optional arguments:
-h, --help show this help message and exit
-setting clear user api key and access token
-cache clear local cache file
對 clear 命令的參數解釋:
1.setting 清理用戶的 API KEY 和 ACCESS TOKEN
2.cache 清理本地緩存的數據
4. 歷史數據查詢
ZoomEye 在去年一月開放了歷史數據查詢,在 ZoomEye 提供的歷史數據中不管你覆蓋不覆蓋都可以查詢出每次掃描得到的 banner 數據,但是目前提供的 ZoomEye 歷史 API 只能通過 IP 去查詢,而不能通過關鍵詞匹配搜索。在 history 命令中同樣如此,舉個例子:
$zoomeye history 108.*.*.65 -num 3
108.*.*.65
Hostnames: [unknown]
Country: United States
City: San Jose
Organization: [unknown]
Lastupdated: 2021-02-25T01:09:26
Number of open ports: 2
Number of historical probes: 3
timestamp port/service app raw_data
2021-02-25 01:09:26 21/ftp Pure-FTPd 220---------- Welcome to Pure-...
2021-02-11 14:36:21 80/http nginx HTTP/1.1 200 OK\r\nServer: ngi...
2021-02-10 19:31:11 80/http nginx HTTP/1.1 200 OK\r\nServer: ngi...
在上述案例中我們使用 zoomeye history 搜索了 IP 是 108.*.*.65 的歷史數據,-num 3 限定展示了數據展示的數量為 3 。展示了我們認為比較重要的五個字段,分別是:
1.tiemstamp 掃描的時間
2.port 開放的端口
3.service 運行的服務
4.app 運行的應用
5.raw_data 每次掃描的 banner
現階段 history 展示的結果只有這個五個字段,后續將根據需求添加相應字段。
$zoomeye history [-h] [-filter filed=regexp] [-force] [-num value] ip
positional arguments:
ip search historical device IP
optional arguments:
-h, --help show this help message and exit
-filter filed=regexp filter data and print raw data detail. field:
[time,port,service,country,raw,*]
-force ignore the local cache and force the data to be
obtained from the API
-num value the number of search results that should be returned
在 history 命令中提供了一下參數:
1.filter 對歷史數據進行篩選,可以指定字段 (key) 也可以指定字段和值 (key=value)
2.force 強制從 API 獲取數據
3.num 限定展示數據的數量
history 命令篩選功能和 search 命令的篩選功能類似,支持單獨的 key 也支持 key=value 的方式,同時也是支持正則表達式的。看個例子:
$zoomeye history 108.*.*.65 -filter "time=^2020-10,port,service"
108.*.*.65
Hostnames: [unknown]
Country: United States
City: San Jose
Organization: [unknown]
Lastupdated: 2020-10-30T02:18:01
Number of open ports: 3
Number of historical probes: 5
time port service
2020-10-30 02:18:01 80 http
2020-10-12 07:17:26 80 http
2020-10-07 21:33:03 80 http
2020-10-06 06:59:48 443 https
2020-10-05 06:42:30 21 ftp
注意:history 在查詢 IP 的歷史數據時會消耗用戶的配額,有多少條數據就會扣除多少配額,因此我對 history 也做了緩存設置,失效日期為 5 天。
如果你需要從 API 獲取實時的數據請使用 -force 參數,-force 會強制從 ZoomEye API 獲取數據,同時消耗用戶配額。
0x03 項目地址
ZoomEye-python 完全開源,任何人可以在此基礎上修改或提交代碼。
GitHub:https://github.com/knownsec/ZoomEye-python
希望各位在 issue 中提出好的建議,讓 ZoomEye-python 用著更順手。
本文由 Seebug Paper 發布,如需轉載請注明來源。本文地址:http://www.bjnorthway.com/1522/
暫無評論