Shodan使用教程#

软件介绍#

Shodan是一款强大的互联网搜索引擎,专注于连接到互联网的设备和系统。它可以帮助安全专业人员发现网络设备、服务器、IoT设备等,并获取详细的设备信息。

入门级使用#

基本搜索#

功能说明:使用Shodan搜索互联网上的设备和系统

使用示例

# 基本IP搜索
shodan search 8.8.8.8

# 搜索特定服务
shodan search "nginx"

# 搜索特定端口
shodan search "port:80"

# 搜索特定国家
shodan search "country:US"

参数说明

  • search:执行搜索查询
  • 支持各种搜索过滤器

基本主机信息查询#

功能说明:查询特定IP或域名的详细信息

使用示例

# 查询IP信息
shodan host 8.8.8.8

# 查询域名信息
shodan host example.com

# 查询多个IP
for ip in 8.8.8.8 1.1.1.1; do shodan host $ip; done

参数说明

  • host:查询主机信息

初级使用#

搜索过滤器#

功能说明:使用各种过滤器进行精确搜索

使用示例

# 按产品搜索
shodan search "product:Apache"

# 按版本搜索
shodan search "version:2.4"

# 按操作系统搜索
shodan search "os:Linux"

# 按组织搜索
shodan search "org:Google"

# 组合搜索
shodan search "product:nginx country:CN port:80"

参数说明

  • 支持多种搜索过滤器
  • 可以组合使用多个过滤器

API密钥配置#

功能说明:配置和使用Shodan API密钥

使用示例

# 设置API密钥
export SHODAN_API_KEY="your_api_key"

# 查看API密钥信息
shodan info

# 查看API使用情况
shodan info --usage

参数说明

  • SHODAN_API_KEY:环境变量设置API密钥
  • info:查看API信息

中级使用#

高级搜索技巧#

功能说明:使用高级搜索技巧发现特定目标

使用示例

# 搜索特定漏洞
shodan search "vuln:CVE-2021-44228"

# 搜索未修补的设备
shodan search "has_vuln:true"

# 搜索特定网络段
shodan search "net:192.168.1.0/24"

# 搜索特定ASN
shodan search "asn:15169"

# 搜索IoT设备
shodan search "product:Webcam"

参数说明

  • vuln:漏洞搜索
  • has_vuln:有漏洞的设备
  • net:网络段搜索
  • asn:ASN搜索

批量操作#

功能说明:处理多个目标的批量查询

使用示例

# 批量查询IP信息
cat ips.txt | xargs -I {} shodan host {}

# 批量搜索
for query in "nginx" "apache" "iis"; do
    shodan search "$query" > "results_$query.txt"
done

# 批量导出结果
shodan search "product:nginx" --format json > nginx_results.json

参数说明

  • --format:指定输出格式
  • 支持批量处理

中上级使用#

数据导出和分析#

功能说明:导出搜索结果并进行深入分析

使用示例

# 导出为JSON格式
shodan search "product:nginx" --format json > results.json

# 导出为CSV格式
shodan search "product:nginx" --format csv > results.csv

# 导出为XML格式
shodan search "product:nginx" --format xml > results.xml

# 限制结果数量
shodan search "product:nginx" --limit 100 > results.txt

参数说明

  • --format:指定输出格式
  • --limit:限制结果数量

网络拓扑分析#

功能说明:分析网络拓扑和设备分布

使用示例

# 分析特定组织的网络
shodan search "org:Target Corporation" --limit 1000 > org_network.txt

# 分析特定ASN的网络
shodan search "asn:15169" --limit 1000 > asn_network.txt

# 分析特定国家的网络
shodan search "country:US" --limit 1000 > country_network.txt

# 生成网络报告
shodan search "product:nginx country:CN" --limit 1000 | awk '{print $1}' | sort -u > nginx_servers.txt

参数说明

  • 支持网络拓扑分析
  • 可以生成网络报告

高级使用#

自动化扫描和监控#

功能说明:使用Shodan进行自动化扫描和监控

使用示例

# 持续监控特定网络
while true; do
    shodan search "net:192.168.1.0/24" --limit 100 > current_scan.txt
    if [ -f previous_scan.txt ]; then
        diff previous_scan.txt current_scan.txt > changes.txt
        if [ -s changes.txt ]; then
            echo "Network changes detected:"
            cat changes.txt
        fi
    fi
    mv current_scan.txt previous_scan.txt
    sleep 3600  # 每小时扫描一次
done

# 定期扫描特定服务
for service in nginx apache iis; do
    shodan search "product:$service" --limit 1000 > "$service.txt"
done

# 与其他工具结合使用
shodan search "product:nginx" --limit 1000 | awk '{print $1}' | xargs -I {} nmap -sV {}

参数说明

  • 支持自动化监控
  • 可以与其他工具结合使用

高级搜索策略#

功能说明:使用高级搜索策略发现更多目标

使用示例

# 多阶段搜索策略
# 第一阶段:广泛搜索
shodan search "country:CN" --limit 1000 > phase1.txt

# 第二阶段:精确搜索
shodan search "country:CN product:nginx" --limit 1000 > phase2.txt

# 第三阶段:漏洞搜索
shodan search "country:CN has_vuln:true" --limit 1000 > phase3.txt

# 合并结果
cat phase1.txt phase2.txt phase3.txt | sort -u > final_results.txt

# 智能搜索策略
# 1. 按产品分类搜索
for product in nginx apache iis; do
    shodan search "product:$product country:CN" --limit 500 > "$product.txt"
done

# 2. 按端口分类搜索
for port in 80 443 22; do
    shodan search "port:$port country:CN" --limit 500 > "port_$port.txt"
done

# 3. 按漏洞分类搜索
for vuln in CVE-2021-44228 CVE-2021-41773; do
    shodan search "vuln:$vuln" --limit 500 > "vuln_$vuln.txt"
done

参数说明

  • 支持多阶段搜索
  • 可以按不同维度分类搜索

大师级使用#

自定义脚本和自动化#

功能说明:创建自定义脚本实现自动化操作

使用示例

# 自定义Shodan扫描脚本
#!/usr/bin/env python3

import shodan
import json

api = shodan.Shodan("YOUR_API_KEY")

# 扫描特定网络
def scan_network(network):
    results = api.search(f"net:{network}")
    return results['matches']

# 分析扫描结果
def analyze_results(results):
    products = {}
    for result in results:
        product = result.get('product', 'unknown')
        products[product] = products.get(product, 0) + 1
    return products

# 生成报告
def generate_report(network):
    results = scan_network(network)
    products = analyze_results(results)
    
    report = {
        'network': network,
        'total_hosts': len(results),
        'products': products
    }
    
    return json.dumps(report, indent=2)

if __name__ == '__main__':
    network = "192.168.1.0/24"
    report = generate_report(network)
    print(report)

# 批量网络扫描脚本
#!/bin/bash

networks=("192.168.1.0/24" "10.0.0.0/8" "172.16.0.0/12")

for network in "${networks[@]}"; do
    echo "Scanning network: $network"
    shodan search "net:$network" --limit 1000 > "scan_$network.txt"
done

# 结果汇总脚本
#!/bin/bash

for file in scan_*.txt; do
    if [[ $file != "scan.txt" ]]; then
        network=$(echo $file | sed 's/scan_//g' | sed 's/.txt$//g')
        count=$(wc -l "$file" | awk '{print $1}')
        echo "$network: $count hosts" >> summary.txt
    fi
done

参数说明

  • 使用Python脚本实现自动化
  • 支持批量操作和结果汇总

综合安全评估#

功能说明:使用Shodan进行综合安全评估

使用示例

# 完整的安全评估流程
# 1. 目标识别
shodan search "org:Target Corporation" --limit 1000 > target_hosts.txt

# 2. 服务发现
shodan search "org:Target Corporation" --limit 1000 --format json | jq -r '.[] | .ip_str' > target_ips.txt

# 3. 漏洞扫描
shodan search "org:Target Corporation has_vuln:true" --limit 1000 > vulnerable_hosts.txt

# 4. 网络拓扑分析
shodan search "org:Target Corporation" --limit 1000 | awk '{print $2}' | sort -u > target_ports.txt

# 5. 生成综合报告
echo "Target Security Assessment" > assessment_report.txt
echo "=========================" >> assessment_report.txt
echo "Total hosts: $(wc -l target_hosts.txt | awk '{print $1}')" >> assessment_report.txt
echo "Vulnerable hosts: $(wc -l vulnerable_hosts.txt | awk '{print $1}')" >> assessment_report.txt
echo "Open ports: $(wc -l target_ports.txt | awk '{print $1}')" >> assessment_report.txt

# 持续监控
while true; do
    shodan search "org:Target Corporation has_vuln:true" --limit 100 > current_vulns.txt
    if [ -f previous_vulns.txt ]; then
        diff previous_vulns.txt current_vulns.txt > new_vulns.txt
        if [ -s new_vulns.txt ]; then
            echo "New vulnerabilities found:"
            cat new_vulns.txt
        fi
    fi
    mv current_vulns.txt previous_vulns.txt
    sleep 86400  # 每天扫描一次
done

参数说明

  • 支持综合安全评估
  • 可以持续监控安全状况

实战案例#

案例1:企业网络发现#

任务:发现企业的所有互联网资产

执行步骤

  1. 基本搜索

    shodan search "org:Company Inc." --limit 1000 > company_hosts.txt
  2. 服务分类

    shodan search "org:Company Inc. product:nginx" --limit 1000 > nginx_hosts.txt
    shodan search "org:Company Inc. product:Apache" --limit 1000 > apache_hosts.txt
  3. 漏洞扫描

    shodan search "org:Company Inc. has_vuln:true" --limit 1000 > vulnerable_hosts.txt
  4. 报告生成

    echo "Company Network Discovery Report" > report.txt
    echo "================================" >> report.txt
    echo "Total hosts: $(wc -l company_hosts.txt | awk '{print $1}')" >> report.txt
    echo "Nginx servers: $(wc -l nginx_hosts.txt | awk '{print $1}')" >> report.txt
    echo "Apache servers: $(wc -l apache_hosts.txt | awk '{print $1}')" >> report.txt
    echo "Vulnerable hosts: $(wc -l vulnerable_hosts.txt | awk '{print $1}')" >> report.txt

案例2:安全评估前的信息收集#

任务:在安全评估前收集目标的详细信息

执行步骤

  1. 多轮搜索

    # 第一轮:基本搜索
    shodan search "target.com" --limit 1000 > round1.txt
    
    # 第二轮:服务搜索
    shodan search "target.com product:nginx" --limit 1000 > round2.txt
    
    # 第三轮:漏洞搜索
    shodan search "target.com has_vuln:true" --limit 1000 > round3.txt
  2. 结果分析

    # 合并结果
    cat round1.txt round2.txt round3.txt | sort -u > all_results.txt
    
    # 统计发现的信息
    echo "Total hosts: $(wc -l all_results.txt | awk '{print $1}')" > analysis.txt
  3. 与其他工具结合

    # 服务发现
    cat all_results.txt | xargs -I {} nmap -sV {}
    
    # 漏洞扫描
    cat all_results.txt | xargs -I {} nuclei -t vulnerabilities/

总结#

Shodan是一款功能强大的互联网搜索引擎,专注于连接到互联网的设备和系统。通过本教程的学习,您应该能够:

  1. 入门级:掌握基本的搜索和主机信息查询
  2. 初级:了解搜索过滤器和API密钥配置
  3. 中级:使用高级搜索技巧和批量操作
  4. 中上级:掌握数据导出分析和网络拓扑分析
  5. 高级:进行自动化扫描监控和高级搜索策略
  6. 大师级:使用自定义脚本和自动化,以及综合安全评估

Shodan的优势在于其强大的搜索能力和丰富的设备信息。在实际使用中,Shodan常常与其他安全工具结合使用,以实现更全面的安全评估。