本文来自:Shodan新手入坑指南, 记录简要用法,以便使用。

文章先给出搜索过滤方法,然后再简单介绍两种使用shodan的方法:使用命令和编写代码。

搜索过滤

  • 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

查看帮助信息

starnight:~ starnight$ shodan 
Usage: shodan [OPTIONS] COMMAND [ARGS]...
Options:
-h, --help Show this message and exit.
Commands:
alert Manage the network alerts for your account    # 管理账户的网络提示
convert Convert the given input data file into a...   # 转换输入文件
count Returns the number of results for a search   # 返回查询结果数量
download Download search results and save them in a... # 下载查询结果到文件
honeyscore Check whether the IP is a honeypot or not.    # 检查 IP 是否为蜜罐
host View all available information for an IP...   # 显示一个 IP 所有可用的详细信息
info Shows general information about your account    # 显示账户的一般信息
init Initialize the Shodan command-line         # 初始化命令行
myip Print your external IP address           # 输出用户当前公网IP
parse Extract information out of compressed JSON... # 解析提取压缩的JSON信息,即使用download下载的数据
scan Scan an IP/ netblock using Shodan.          # 使用 Shodan 扫描一个IP或者网段
search Search the Shodan database             # 查询 Shodan 数据库
stats Provide summary information about a search... # 提供搜索结果的概要信息
stream Stream data in real-time.             # 实时显示流数据

常用实例

init : 初始化

shodan init [API_Key]
Successfully initialized

需要提供你自己的API key, 注册后可能还需要升级账户。

count: 返回查询的结果数量

starnight:~ starnight$ shodan count tomcat country:cn
14826

download: 下载查询结果

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

starnight:~ starnight$ shodan download
Usage: shodan download [OPTIONS] <filename> <search query>

parse: 过滤搜索结果

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

starnight:~ starnight$ shodan parse --fields ip_str,port,org --separator , tomcat-cn.json.gz

host:查询主机信息

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

以上诉查询结果的最后一个IP:222.243.129.135 为例做演示

search: 在命令行下搜索

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

starnight:~ starnight$ shodan search --fields ip_str,port,org,hostnames tomcat country:cn --limit 10

代码中使用 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.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数据

参考:

Shodan新手入坑指南:http://www.freebuf.com/sectool/121339.html

Shodan documentation: https://shodan.readthedocs.io/en/latest/tutorial.html

Shodan记录的标识信息:https://developer.shodan.io/api/banner-specification

More: 国内的ZoomEye使用 请参考:

从ZoomEye API 到 Weblogic 弱口令扫描

最新文章

  1. lecture16-联合模型、分层坐标系、超参数优化及本课未来的探讨
  2. 【codevs1034】 家园
  3. Codeforce Round #218 Div2
  4. Android_显示器本身被卸载应用程序
  5. Qt:添加点击事件的Label并显示图片
  6. hdu 1548 简单BFS
  7. python全栈学习--day3
  8. mac eclipse maven -solved
  9. JEECG &amp; JEESite Tomcat集群 Session共享
  10. [k8s]kube-dns架构图解
  11. 20165326 java第六周学习笔记
  12. dns隧道 dns2tcpd
  13. SQL字符串分割解析
  14. 使用Spring框架入门三:基于XML配置的AOP的使用
  15. New text file line delimiter
  16. Windows下Postgresql数据库的下载与配置方法
  17. 20145326 《Java程序设计》课程总结
  18. 问题:一球从某高度自由落下,每次落地后反跳回原高度的一半;再落下,求它在第n次落地时,共经过多少米?第n次反弹多高?
  19. ZABBIX 3.0 配置监控MYSQL性能【OK】
  20. hive中行转换成列以及hive相关知识

热门文章

  1. C语言文法翻译
  2. 安恒杯-babysql
  3. Windows连接Linux服务器中MySQL数据库-权限配置
  4. ASP.NET存储Session的StateServer
  5. node.js入门(一)
  6. [翻译]API Guides - Bound Services
  7. PHP中大括号用法
  8. struts.xml 文件中的 namespace 属性图文详解
  9. hdu6415 Rikka with Nash Equilibrium (DP)
  10. 当使用listIterator进行迭代时候 list的迭代器可以在创建迭代器对象后 添加数据 但打印的时候不显示添加后的数据。 collection 的iterator迭代器不能添加数据 。list的对象与collection的实例对象都不能在创建迭代器后添加数据 list的迭代器保存的是循环前的数据长度