shodan 文檔學習筆記

Table of Contents

1 Introduction

  • Shodan 是聯網設備搜索引擎

1.1 All About the Data

  • Banner 服務相關的文本信息
  • Device Metadata 地理位置,主機名,操作系統信息
  • IPv6 2015 年之後開始支持

1.2 Data Collection

  • Frequency 24 小時實時更新數據庫
  • Distributed 全世界都部署有分佈式爬蟲,保證網絡封鎖不影響結果準確性
  • Randomized 基本算法:
    1. 產生一個隨機 IPv4 地址
    2. 從 shodan 理解的端口列表中隨機產生一個
    3. 檢查這個地址和端口,獲取 banner
    4. 返回 1

1.3 SSL in Depth

  • SSL 相關的信息包括 SSL 證書都保存在 banner 的 ssl 屬性

1.3.1 Vulnerability Testing

 
  1. Heartbleed
    • banner 會有另外兩個屬性 opts.heartbleed ,一小段 overflow 獲得的數據 opts.vulns ,CVE-2014-0160
    • 搜索在美國受此影響的設備 country:US vuln:CVE-2014-0160
  2. FREAK
    • opts.vulns , CVE-2015-0204
  3. Logjam
    • dhparams .prime .publickey .bits .generator .fingerprint

1.3.2 Version

  • 爬蟲會使用多個 SSL 版本 SSLv2, SSLv3, TLSv1.0, TLSv1.1, TLSv1.2
  • 獲得目標支持的 SSL 版本信息會放在 ssl.versions
  • 搜索支持特定 SSL 版本的設備 ssl.version:sslv2

1.3.3 Follow the Chain

  • 證書鏈會保存在 ssh.chain 屬性

1.4 Beyond the Basics

  • shodan 會嘗試從 banner 中解析有用的信息

1.4.1 Web Components

  • http.components
  • http.components.jQuery.categories
  • 獲取所有可能的 categories shodan stats –facets http.componentcategory:1000 http

1.4.2 Cascading

  • 如果 banner 裏有 ip 地址信息,會進一步抓取其 banner
  • 兩個屬性
    • _shodan.id
    • _shodan.options.referrer

2 Web Interfaces

 

2.1 Search Query Explained

  • 默認是在 banner 搜索指定字符
  • 默認在各搜索字串間是 and
  • 搜索元數據用 search filter

2.2 Introducing Filters

  • 帶空格的文本用雙引號 city:“San Diego”
  • 多個項用逗號 port:23,1023
  • 不包含 -city:“San Diego”
  • hash 屬性 shodan 中的每個 banner 都有個計算出的 hash 屬性,banner 爲空則 hash 爲 0
  • 結合多個 filter 使用 port:8080 -hash:0
  • 一些常用的 filter category 例如 ics,malware city country net 例如 net:190.20.40.0/24 org 例如 "Verizon Wireless“

2.3 Shodan Search Engine

  • 默認查詢只搜索 30 天內的數據

2.3.1 Download Data

  • 下載結果需要 export credit,需要購買,一個 credit 可下載最高 10000 個結果

2.3.2 Generate Report

  • 報告創建免費

2.3.3 Shared Search Queries

  • 可以查看別人共享的查詢語句

2.3.4 Example: Finding Non-Default Services

  • product:opennssh -port:22

2.4 Shodan Maps

  • 會顯示最多 1000 個結果,隨着放大縮小會修改顯示在視線範圍內的設備數量

2.4.1 Map Styles

2.5 Shodan Exploits

  • https://exploits.shodan.io/ 會從多個來源搜索 exp,其實和 shodan 本身功能沒啥關係了
  • 支持的 filters author description platform type remote/dos

2.6 Shodan Images

2.7 Exercises: Website

  • 找到 4SICS 網站
  • 有多少支持匿名訪問的 VNC 服務
  • 瑞典 Sweden 有多少存在 Heartbleed 並支持 SSLv3 的 IP
  • 你的組織內有多少存在 Heartbleed 的 IP
  • 找到你城市內的所有工控設備
  • USA 最流行的 RAT 是哪種

3 External Tools

 

3.1 Shodan Command-Line Interface

 

3.1.1 Gettig Started

  • 安裝 easyinstall shodan shodan init APIKEY

3.1.2 alert

create list clear remove

3.1.3 convert

  • 能夠把 shodan 生成的 JSON 文件轉換成 kml csv 格式

3.1.4 count

  • 返回查詢結果條數 shodan count microsoft iis 6.0

3.1.5 download

shodan download microsoft-data microsoft iis 6.0

3.1.6 host

  • 查詢主機信息 shodan host 189.201.128.250

3.1.7 honeyscore

  • 檢查主機是否是僞裝成工控系統的蜜罐 shodan honeyscore 41.231.95.212

3.1.8 info

  • 查詢 API 的查詢條數和下載條數

3.1.9 myip

  • 返回自己的公網 ip

3.1.10 parse

  • 可以解析之前下載的文件 shodan parse –fields ipstr,port,org –separator , microsoft-data.json.gz

3.1.11 scan

提供了多條子命令,最常用的是 submit shodan scan submit 202.69.165.20

3.1.12 search

shodann search –fields ipstr,port,org,hostname microsoft iis 6.0

3.1.13 stats

  • 按照某個分類顯示結果統計

shodan stats –facets country apache

3.1.14 stream

  • 提供了訪問爬蟲實時獲取的數據
  1. -datadir
  2. -limit
  3. -ports

3.1.15 Example: Network Analysis

shodan count net:78.13/16 shodan stats –facets port net:78.13/16 shodan stats –facets port:100000 net:78.13/16 shodan stats –facets product “HTTP net:78.13/16 -port:80,443” shodan stats –facets ssl.version HTTP net:78.13/16

3.1.16 Example: Telnet Research

mkdir telnet-data shodan stream –ports 23,1023,2323 –datadir telnet-data/ –limit 10000

3.2 Maltego Add-On

3.3 Browser Plug-Ins

3.4 Exercises: Command-Line Interface

  • 下載 Sweden 和 Norway 內有 Heartbleed 的 IP,從中過濾出 Sweden 的 IP
  • 使用實時 stream 下載最近 1000 個 banner,並用 Google Maps 映射
  • 寫個腳本下載已知惡意 ip 列表並封掉到這些 ip 的流量 iptables -A OUTPUT -d x.x.x.x -j DROP

4 Developer API

  • shodan 提供了兩種 API REST API, 正常查詢 Streaming API

4.1 Usage Limits

  • 如果查詢包含 filter 或者查詢了第二頁,會消耗一個 query credit
  • 每月重置 query 和 scan credit 條數

4.2 Introducing Facets

  • facets 現在只能通過 API 和 cli 訪問

4.3 Gettign Started

easyinstall shodan easyinstall -U shodan

4.4 Initialization

import shodan
api = shodan.Shodan('your api key')

4.5 Search

try:
    results = api.search('apache')
    print('Results found: %s' % results['total'])
    for result in results['matches']:
        print 'IP: %s' % results['ip_str']
        print result['data']
        print ''
except shodan.APIError, e:
    print 'Error: %s' % e
  • 默認返回第 1 頁,只包含 100 個結果 api.search(’apache’, page=2)
  • 返回數據是個字典 .total .matches .data .hostname .ipython.ipstr’.os .port .timestamp
  • 默認太長的數據會被截斷 api.search(’hasscreenshot:true’, minify=False)
  • 遍歷所有結果

    for banner in api.search_cursor('apache'):
        print(bannner['ip_str'])
    

4.6 Host Lookup

  • 查詢指定 ip
host = api.host('1.1.1.1')
print """
    IP: %s
    Organization: %s
    Operating System: %s
""" % (host['ip_str'], host.get('org', 'n/a'), host.get('os', 'n/a'))

for item in host['data']:
    print """
        Port: %s
        Banner: %s
    """ % (item['port'], item['data'])
  • 默認只返回最近的數據,用 history 參數返回所有歷史數據 host = api.host(’1.1.1.1’, history=True)

4.7 Scanning

  • api 的 scan 不會立刻掃描
  • 使用示例

    scan = api.scan('1.1.1.1/24')
    scan2 = api.scan(['1.1.1.1', '2.2.2.2/16'])
    

4.8 Real-Time Stream

4.9 Network Alert

 

4.9.1 Creating a Network Alert

4.9.2 Subscribling

4.9.3 Using the Shodan Command-Line Interface

4.10 Example: Public MongoDB Data

4.11 Exercises: Shodan API

5 Industrial Control Systems

 

5.1 Common Abbreviations

BMS Building Management System DCS Distributed Control System HMI Human Machine Interface ICS Industrial Control System PLC Programmable Logic Controller RTU Remote Treminal Unit SCADA Supervisory Control and Data Acquisition VNC Virtual Network Computing

5.2 Protocols

  • 有兩種識別網上的控制系統的方式
    1. Non-ICS protocols used in an ICS environment 一些工控設備可以通過 web 界面或者遠程連接訪問
    2. ICS protocols ICS 協議都沒有認證,但是基本都是私有協議,意味着能訪問但無法交互

5.3 Securing Internet-Connected ICS

5.4 Use Cases

 

5.4.1 Assessing ICS for the USA

5.4.2 Identifying Honeypots

 
  1. What is a honeypot?
    • 最流行的工控蜜罐:Conpot
  2. Why Detect Them?
  3. Default Configurations
    • 默認配置會返回同樣的 banner,包括 serial number, PLC names 等
  4. History Matters
    • 歷史中可能出現錯誤配置,比如模板沒有解析,直接輸出出來了
  5. Emulate Devices, Not Services
    • 蜜罐可能同時模擬太多服務
  6. Location, Location, Location
    • 部署在一些雲上的工控多半是蜜罐 Amazon EC2 Rackspace Digital Ocean Vultr Microsoft Azure Google Cloud
    • 蜜罐最好是部署在一些城市 ISP 的 IP 範圍
  7. Honeyscore
  8. Tag: honeypot
    • 判斷蜜罐的算法也被集成在了爬蟲中,同時會檢測一些流行的 web 應用,Elastic 等的蜜罐

6 Appendix A: Banner Specification

 

6.1 General Properties

asn data ip ipstr ipv6 port timestamp hash hostnames domains link 網絡連接類型,以太網或者光貓 location opts org isp os uptime tags transport 傳輸層協議

6.2 Elastic Properties

elastic.cluster elastic.indices elastic.nodes

6.3 HTTP(S) Properties

http.components http.host http.html http.htmlhash http.location http.redirects http.robots http.server http.sitemap http.title

6.4 Location Properties

  • location 的一些子屬性 areacode city countrycode countrycode3 countryname dmacode 美國專用 latitude longitude 經度 postalcode regioncode

6.5 SMB Properties

smb.anonymous smb.capabilities smb.shares smb.smbversion smb.software smb.raw

6.6 SSH Properties

ssh.cipher ssh.fingerprint ssh.kex 服務器支持的 key 交換算法 ssh.key ssh.mac

6.7 SSL Properties

ssl.acceptablecas 服務器支持的證書授權 ssl.cert ssl.cipher ssl.chain ssl.dhparams ssl.tlsext ssl.versions

6.8 ISAKMP Properties

  • 針對使用 ISAKMP 協議的 VPN,比如 IKE

6.9 Special Properties

6.10 Example

7 Appendix B: List of Search Filters

 

7.1 General Filters

7.2 HTTP Filters

7.3 NTP Filters

7.4 SSL Filters

7.5 Telnet Filters

8 Appendix C: Search Facets

 

8.1 General Facets

8.2 HTTP Facets

8.3 NTP Facets

8.4 SSH Facets

8.5 SSL Facets

8.6 Telnet Facets

9 Appendix D: List of Ports

10 Appendix E: Sample SSL Banner

11 Exercise Solutions

 

11.1 Website

11.2 Command-Line Interface

11.3 Shodan API

Author: cat

Created: 2019-11-23 六 23:22

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章