本文已参与「新人创作礼」活动,一起开启掘金创作之路
- shodan:理论上shodan可以搜索、监控一切联网设备(偏向主机层面)
- 国内同类型网站:FOFA,钟馗之眼(ZoomEye)(侧重Web层面的扫描偏向资产搜索)
- 自我感觉 shodan 中文搜索能力偏弱
Google hacking 语法
- Index of/ 使用它可以直接进入网站首页下的所有文件和文件夹中
- intext: 将返回所有在网页正文部分包含关键词的网页
- intitle: 将返回所有网页标题中包含关键词的网页
- cache: 搜索google里关于某些内容的缓存
- define: 搜索某个词语的定义
- filetype: 搜索指定的文件类型,如:.bak,.mdb,.inc等
- info: 查找指定站点的一些基本信息
- inurl: 搜索我们指定的字符是否存在于URL中
- Link: link:thief.one可以返回所有和thief.one做了链接的URL site: site:thief.one将返回所有和这个站有关的URL
+ 把google可能忽略的字列如查询范围
+ 把某个字忽略,例子:新加 -坡
+ ~ 同意词
+ . 单一的通配符
+ * 通配符,可代表多个字母。
+ “” 精确查询。
搜索不同国家网站
inurl:tw 台湾
inurl:jp 日本
利用google暴库
利用goole可以搜索到互联网上可以直接下载到的数据库文件,语法如下:
inurl:editor/db/
inurl:eWebEditor/db/
inurl:bbs/data/
inurl:databackup/
inurl:blog/data/
inurl:\boke\data
inurl:bbs/database/
inurl:conn.asp
inc/conn.asp
Server.mapPath(“.mdb”)
allinurl:bbs data
filetype:mdb inurl:database
filetype:inc conn
inurl:data filetype:mdb
intitle:"index of" data
利用goole索敏感信息
利用google可以搜索一些网站的敏感信息,语法如下:
intitle:"index of" etc
intitle:"Index of" .sh_history
intitle:"Index of" .bash_history
intitle:"index of" passwd
intitle:"index of" people.lst
intitle:"index of" pwd.db
intitle:"index of" etc/shadow
intitle:"index of" spwd
intitle:"index of" master.passwd
intitle:"index of" htpasswd
inurl:service.pwd
利用google搜索C段服务器信息
此技巧来自lostwolf
site:218.87.21.*
可通过google可获取218.87.21.0/24网络的服务信息
Shodan
搜索语法
使用搜索过滤
- 限定国家和城市
限定国家
country:"CN"限定城市city:"ShangHai" - 限定主机名或域名
hostname:.orghostname:"google"hostname:baidu.com - 限定组织或机构
org:"alibaba" - 限定系统OS版本
os:"Windows Server 2008 R2"os:"Windows 7 or 8"os:"Linux 2.6.x" - 限定端口
port:22port:80 - 指定网段
net:"59.56.19.0/24" - 指定使用的软件或产品
product:"Apache httpd"product:"nginx"product:"Microsoft IIS httpd"product:"mysql" - 指定CVE漏洞编号
vuln:"CVE-2014-0723" - 指定网页内容
http.html:"hello world" - 指定网页标题
http.title:"hello" - 指定返回响应码
http.status:200 - 指定返回中的server类型
http.server:Apache/2.4.7http.server:PHP - 指定地理位置
geo:"31.25,121.44" - 指定ISP供应商
isp:"China Telecom" - 多个语句直接跟在后边,无并列符,如:Server: Hikvision-Webs country:"CN"
ssh default password
ssh default password country:"JP"
FTP anon successful
shadon API
安装python包
pip install shodan
初始化
shodan init <api key>
search
搜索指定内容(apache)的数量
shodan count apache
搜索指定内容(apache)的信息
shodan search --fields ip_str,port,org,hostnames apache
download
下载指定内容(apache)的搜索结果
shodan download apache-test apache
# 表示文件名
将搜索结果下载到一个文件中,文件中的每一行都是 JSON 格式存储的目标 banner 信息。默认情况下,该命令只会下载1000条结果,如果想下载更多结果需要增加 --limit 参数
parse
可以使用 parse 来解析之前下载数据,它可以帮助我们过滤出自己感兴趣的内容,也可以用来将下载的数据格式从 JSON 转换成 CSV 等等其他格式,当然更可以用作传递给其他处理脚本的管道。例如,我们想将上面下载的数据以CSV格式输出IP地址、端口号和组织名称
shodan parse --fields ip_str,port,org --separator , apache-test.json.gz
66.242.151.249,80,Host Depot, Inc.
194.180.224.190,80,Patron Technology Persia Ltd
108.171.48.2,80,Smart Solutions IT
35.230.134.45,80,Google LLC
54.191.28.88,9306,Amazon.com, Inc.
90.0.213.224,80,
3.8.200.10,80,Amazon Data Services UK
175.177.155.188,443,its communications Inc.
205.196.20.46,80,Certified Hosting
210.191.214.40,80,HOKKAIDO TELECOMMUNICATION NETWORK Co.,Inc.
162.243.7.51,80,DigitalOcean, LLC
5.198.248.98,80,ACUIT HOSTING
用 powershell 会存在不显示的问题
导出到文档,可以结合 xray 去挖洞
shodan parse --fields ip_str,port --separator : rencai.json.gz > rencai.txt
更多语法
➜ ~ shodan -h
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. # 实时显示流数据
shadon py库
代码中使用 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数据
FOFA
搜索语法
搜索语法
- title=”abc” 从标题中搜索abc。例:标题中有北京的网站。
- header=”abc” 从http头中搜索abc。例:jboss服务器。
- body=”abc” 从html正文中搜索abc。例:正文包含Hacked by。
- domain=”qq.com” 搜索根域名带有qq.com的网站。例: 根域名是qq.com的网站。
- host=”.gov.cn” 从url中搜索.gov.cn,注意搜索要用host作为名称。
- port=”443” 查找对应443端口的资产。例: 查找对应443端口的资产。
- ip=”1.1.1.1” 从ip中搜索包含1.1.1.1的网站,注意搜索要用ip作为名称。
- protocol=”https” 搜索制定协议类型(在开启端口扫描的情况下有效)。例: 查询https协议资产。
- city=”Beijing” 搜索指定城市的资产。例: 搜索指定城市的资产。
- region=”Zhejiang” 搜索指定行政区的资产。例: 搜索指定行政区的资产。
- country=”CN” 搜索指定国家(编码)的资产。例: 搜索指定国家(编码)的资产。
- cert=”google.com” 搜索证书(https或者imaps等)中带有google.com的资产。
高级搜索:
- title=”powered by” && title!=discuz
- title!=”powered by” && body=discuz
- ( body=”content=\”WordPress” || (header=”X-Pingback” && header=”/xmlrpc.php” && body=”/wp-includes/“) ) && host=”gov.cn”