shodan使用教程

shodan使用教程

Shodan简介

Shodan是互联网上最可怕的搜索引擎,与谷歌不同的是,Shodan不是在网上搜索网址,而是直接进入互联网的背后通道。Shodan可以说是一款“黑暗”谷歌,一刻不停的寻找所有和互联网关联的服务器,摄像头,打印机,路由器。

网站地址https://www.shodan.io

搜索语法

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

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

常用示例

init

初始化命令行工具。

➜  ~ shodan init [API_Key]
Successfully initialized

count

返回查询的结果数量。

➜  ~ shodan count microsoft iis 6.0
575862

download

将搜索结果下载到一个文件中,文件中的每一行都是 JSON 格式存储的目标 banner 信息。默认情况下,该命令只会下载1000条结果,如果想下载更多结果需要增加 --limit 参数。

Shodan

parse

我们可以使用 parse 来解析之前下载数据,它可以帮助我们过滤出自己感兴趣的内容,也可以用来将下载的数据格式从 JSON 转换成 CSV 等等其他格式,当然更可以用作传递给其他处理脚本的管道。例如,我们想将上面下载的数据以CSV格式输出IP地址、端口号和组织名称:

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

Shodan

host

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

Shodan

search

直接将查询结果展示在命令行中,默认情况下只显示IP、端口号、主机名和HTTP数据。当然我们也可以通过使用 –fields 来自定义显示内容,例如,我们只显示IP、端口号、组织名称和主机名:

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

Shodan

代码中使用 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工具

这里 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数据
posted @ 2020-10-28 11:22  tomyyyyy  阅读(19703)  评论(2编辑  收藏  举报