1. 程式人生 > >shodan 文件學習筆記

shodan 文件學習筆記

Table of Contents

  • 1. Introduction
    • 1.1. All About the Data
    • 1.2. Data Collection
    • 1.3. SSL in Depth
      • 1.3.1. Vulnerability Testing
      • 1.3.2. Version
      • 1.3.3. Follow the Chain
    • 1.4. Beyond the Basics
      • 1.4.1. Web Components
      • 1.4.2. Cascading
  • 2. Web Interfaces
    • 2.1. Search Query Explained
    • 2.2. Introducing Filters
    • 2.3. Shodan Search Engine
      • 2.3.1. Download Data
      • 2.3.2. Generate Report
      • 2.3.3. Shared Search Queries
      • 2.3.4. Example: Finding Non-Default Services
    • 2.4. Shodan Maps
      • 2.4.1. Map Styles
    • 2.5. Shodan Exploits
    • 2.6. Shodan Images
    • 2.7. Exercises: Website
  • 3. External Tools
    • 3.1. Shodan Command-Line Interface
      • 3.1.1. Gettig Started
      • 3.1.2. alert
      • 3.1.3. convert
      • 3.1.4. count
      • 3.1.5. download
      • 3.1.6. host
      • 3.1.7. honeyscore
      • 3.1.8. info
      • 3.1.9. myip
      • 3.1.10. parse
      • 3.1.11. scan
      • 3.1.12. search
      • 3.1.13. stats
      • 3.1.14. stream
      • 3.1.15. Example: Network Analysis
      • 3.1.16. Example: Telnet Research
    • 3.2. Maltego Add-On
    • 3.3. Browser Plug-Ins
    • 3.4. Exercises: Command-Line Interface
  • 4. Developer API
    • 4.1. Usage Limits
    • 4.2. Introducing Facets
    • 4.3. Gettign Started
    • 4.4. Initialization
    • 4.5. Search
    • 4.6. Host Lookup
    • 4.7. Scanning
    • 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
    • 5.2. Protocols
    • 5.3. Securing Internet-Connected ICS
    • 5.4. Use Cases
      • 5.4.1. Assessing ICS for the USA
      • 5.4.2. Identifying Honeypots
  • 6. Appendix A: Banner Specification
    • 6.1. General Properties
    • 6.2. Elastic Properties
    • 6.3. HTTP(S) Properties
    • 6.4. Location Properties
    • 6.5. SMB Properties
    • 6.6. SSH Properties
    • 6.7. SSL Properties
    • 6.8. ISAKMP Properties
    • 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

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

  • https://images.shodan.io/
  • 會從五種來源收集截圖 VNC RDP RTSP Webcams X Windows
  • filter hasscreenshot:true

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
    • https://honeyscore.shodan.io/ 判斷 IP 是不是蜜罐
  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

&nbs