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

 

posted @ 2019-11-24 00:03  君莫笑hhhhhh  阅读(1201)  评论(0编辑  收藏  举报