Shodan 使用


本文來自:Shodan新手入坑指南, 記錄簡要用法,以便使用。 

文章先給出搜索過濾方法,然后再簡單介紹兩種使用shodan的方法:使用命令和編寫代碼。

搜索過濾

  • hostname:搜索指定的主機或域名,例如 hostname:"google"
  • port:搜索指定的端口或服務,例如 port:"21"
  • country:搜索指定的國家,例如 country:"CN"
  • city:搜索指定的城市,例如 city:"Hefei"
  • org:搜索指定的組織或公司,例如 org:"google"
  • isp:搜索指定的ISP供應商,例如 isp:"China Telecom"
  • product:搜索指定的操作系統/軟件/平台,例如 product:"Apache httpd"
  • version:搜索指定的軟件版本,例如 version:"1.6.2"
  • geo:搜索指定的地理位置,參數為經緯度,例如 geo:"31.8639, 117.2808"
  • before/after:搜索指定收錄時間前后的數據,格式為dd-mm-yy,例如 before:"11-11-15"
  • net:搜索指定的IP地址或子網,例如 net:"210.45.240.0/24"

命令下使用shodan

Shodan 是由官方提供的 Python 庫的,項目位於:https://github.com/achillean/shodan-python

安裝

pip install shodan

或者

git clone https://github.com/achillean/shodan-python.git && cd shodan-python python setup.py install

查看幫助信息

starnight:~ starnight$ shodan 
Usage: shodan [OPTIONS] COMMAND [ARGS]... Options: -h, --help Show this message and exit. Commands: alert Manage the network alerts for your account    # 管理賬戶的網絡提示 convert Convert the given input data file into a...   # 轉換輸入文件 count Returns the number of results for a search   # 返回查詢結果數量 download Download search results and save them in a... # 下載查詢結果到文件 honeyscore Check whether the IP is a honeypot or not.    # 檢查 IP 是否為蜜罐 host View all available information for an IP...   # 顯示一個 IP 所有可用的詳細信息 info Shows general information about your account    # 顯示賬戶的一般信息 init Initialize the Shodan command-line         # 初始化命令行 myip Print your external IP address           # 輸出用戶當前公網IP parse Extract information out of compressed JSON... # 解析提取壓縮的JSON信息,即使用download下載的數據 scan Scan an IP/ netblock using Shodan.          # 使用 Shodan 掃描一個IP或者網段 search Search the Shodan database             # 查詢 Shodan 數據庫 stats Provide summary information about a search... # 提供搜索結果的概要信息 stream Stream data in real-time.             # 實時顯示流數據

常用實例

init : 初始化

shodan init [API_Key]
Successfully initialized

需要提供你自己的API key, 注冊后可能還需要升級賬戶。

count: 返回查詢的結果數量

starnight:~ starnight$ shodan count tomcat country:cn
14826

download: 下載查詢結果

將搜索結果下載到一個文件中,文件中的每一行都是 JSON 格式存儲的目標 banner 信息。默認情況下,該命令只會下載1000條結果,如果想下載更多結果需要增加 --limit 參數。

starnight:~ starnight$ shodan download
Usage: shodan download [OPTIONS] <filename> <search query>

 parse: 過濾搜索結果

我們可以使用 parse 來解析之前下載數據,它可以幫助我們過濾出自己感興趣的內容,也可以用來將下載的數據格式從 JSON 轉換成 CSV 等等其他格式,當然更可以用作傳遞給其他處理腳本的管道。例如,我們想將上面下載的數據以CSV格式輸出IP地址、端口號和組織名稱:

starnight:~ starnight$ shodan parse --fields ip_str,port,org --separator , tomcat-cn.json.gz

host:查詢主機信息

查看指定主機的相關信息,如地理位置信息,開放端口,甚至是否存在某些漏洞等信息。

以上訴查詢結果的最后一個IP:222.243.129.135 為例做演示

search: 在命令行下搜索

直接將查詢結果展示在命令行中,默認情況下只顯示IP、端口號、主機名和HTTP數據。當然我們也可以通過使用 –fields 來自定義顯示內容,例如,我們只顯示IP、端口號、組織名稱和主機名:

starnight:~ starnight$ shodan search --fields ip_str,port,org,hostnames tomcat country:cn --limit 10

代碼中使用 Shodan 庫

還是使用上一節講到的 shodan 庫,安裝方式這里不在闡述了。同樣的,在使用 shodan 庫之前需要初始化連接 API,代碼如下:

import shodan
SHODAN_API_KEY = "API_Key"
api = shodan.Shodan(SHODAN_API_KEY)

隨后,我們就可以搜索數據了,示例代碼片如下:

try:
    # 搜索 Shodan
    results = api.search('apache')
    # 顯示結果
    print 'Results found: %s' % results['total']
    for result in results['matches']:
            print result['ip_str']
except shodan.APIError, e:
    print 'Error: %s' % e

這里 Shodan.search() 會返回類似如下格式的 JSON 數據:

{
        'total': 8669969,
        'matches': [
                {
                        'data': 'HTTP/1.0 200 OK\r\nDate: Mon, 08 Nov 2010 05:09:59 GMT\r\nSer...',
                        'hostnames': ['pl4t1n.de'],
                        'ip': 3579573318,
                        'ip_str': '89.110.147.239',
                        'os': 'FreeBSD 4.4',
                        'port': 80,
                        'timestamp': '2014-01-15T05:49:56.283713'
                },
                ...
        ]
}

常用 Shodan 庫函數

shodan.Shodan(key) :初始化連接API
Shodan.count(query, facets=None):返回查詢結果數量
Shodan.host(ip, history=False):返回一個IP的詳細信息
Shodan.ports():返回Shodan可查詢的端口號
Shodan.protocols():返回Shodan可查詢的協議
Shodan.services():返回Shodan可查詢的服務
Shodan.queries(page=1, sort='timestamp', order='desc'):查詢其他用戶分享的查詢規則
Shodan.scan(ips, force=False):使用Shodan進行掃描,ips可以為字符或字典類型
Shodan.search(query, page=1, limit=None, offset=None, facets=None, minify=True):查詢Shodan數據

 參考:

Shodan新手入坑指南:http://www.freebuf.com/sectool/121339.html

Shodan documentation: https://shodan.readthedocs.io/en/latest/tutorial.html

Shodan記錄的標識信息:https://developer.shodan.io/api/banner-specification

More: 國內的ZoomEye使用 請參考:

從ZoomEye API 到 Weblogic 弱口令掃描


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM