Shodan入坑指南


基本用法

這里就像是用 Google 一樣,在主頁的搜索框中輸入想要搜索的內容即可,例如下面我搜索 “SSH”:

上圖的搜索結果包含兩個部分,左側是大量的匯總數據包括:

  • Results map – 搜索結果展示地圖
  • Top services (Ports) – 使用最多的服務/端口
  • Top organizations (ISPs) – 使用最多的組織/ISP
  • Top operating systems – 使用最多的操作系統
  • Top products (Software name) – 使用最多的產品/軟件名稱

隨后,在中間的主頁面我們可以看到包含如下的搜索結果:

  • IP 地址
  • 主機名
  • ISP
  • 該條目的收錄收錄時間
  • 該主機位於的國家
  • Banner 信息

想要了解每個條目的具體信息,只需要點擊每個條目下方的 details 按鈕即可。此時,URL 會變成這種格式 https://www.shodan.io/host/[IP],所以我們也可以通過直接訪問指定的 IP 來查看詳細信息。

上圖中我們可以從頂部在地圖中看到主機的物理地址,從左側了解到主機的相關信息,右側則包含目標主機的端口列表及其詳細信息。

使用搜索過濾

如果像前面單純只使用關鍵字直接進行搜索,搜索結果可能不盡人意,那么此時我們就需要使用一些特定的命令對搜索結果進行過濾,常見用的過濾命令如下所示:

  • 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"

搜索實例

查找位於合肥的 Apache 服務器:

apache city:"Hefei"

查找位於國內的 Nginx 服務器:

nginx country:"CN"

查找 GWS(Google Web Server) 服務器:

"Server: gws" hostname:"google"

查找指定網段的華為設備:

huawei net:"61.191.146.0/24"

其他功能

Shodan 不僅可以查找網絡設備,它還具有其他相當不錯的功能。

Exploits:每次查詢完后,點擊頁面上的 “Exploits” 按鈕,Shodan 就會幫我們查找針對不同平台、不同類型可利用的 exploits。當然也可以通過直接訪問網址來自行搜索:https://exploits.shodan.io/welcome;

命令行下使用 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

安裝完后我們先看下幫助信息:

➜  ~ shodan -h
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

count

返回查詢的結果數量。

  ~ shodan count microsoft iis 6.0
575862

download

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

parse

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

➜  ~ shodan parse --fields ip_str,port,org --separator , microsoft-data.json.gz

host

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

search

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

➜  ~ shodan search --fields ip_str,port,org,hostnames microsoft iis 6.0

代碼中使用 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數據

 


免責聲明!

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



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