admin管理员组

文章数量:1578025

关于搜索引擎

此处涉及的搜索引擎,不是常规的百度、谷歌之类的搜索引擎,而是专门为信息搜集而生的ShodanCensysFofaZoomeye等搜索引擎。

Shodan

shodan,是一款国外的在线设备搜索引擎,除了包含常见的在线服务器,还有各种路由器、在线摄像头、工控设备等网络资产都可以搜索到。其提供了注册和付费会员功能,注册后的会员被分配一个身份标识API,通过该API,用户可以在客户端(或者只使用浏览器)编写python脚本,结合专用的搜索关键词获取所需要的目标的信息,包括ip、端口、服务、设备指纹、地理位置、蜜罐防护等各类信息。
客户端安装shodan:

pip install shodan

安装之后,在命令行中输入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 different format.
  count       Returns the number of results for a search
  data        Bulk data access to Shodan
  download    Download search results and save them in a compressed JSON...
  honeyscore  Check whether the IP is a honeypot or not.
  host        View all available information for an IP address
  info        Shows general information about your account
  init        Initialize the Shodan command-line
  myip        Print your external IP address
  org         Manage your organization's access to Shodan
  parse       Extract information out of compressed JSON files.
  radar       Real-Time Map of some results as Shodan finds them.
  scan        Scan an IP/ netblock using Shodan.
  search      Search the Shodan database
  stats       Provide summary information about a search query
  stream      Stream data in real-time.

shodan的 API 使用语法可以参考其官方文档。
搜索结果为json格式,用户可以根据需要提取感兴趣的关键词所对应的键值。
shodan的非付费会员只能看到搜索结果的前5页
python 代码示例:

import shodan

SHODAN_API_KEY = '[YOUR_API_KEY]'
api = shodan.Shodan(SHODAN_API_KEY)
results = api.host("8.8.8.8")

>>> results.keys()
[u'data', u'city', u'region_code', u'ip', u'isp', u'area_code', u'dma_code', u'last_update', u'country_code3', u'latitude', u'hostnames', u'postal_code', u'longitude', u'country_code', u'org', u'country_name', u'ip_str', u'os', u'asn', u'ports']
>>> results['ip_str']
u'8.8.8.8'
>>> results['ports']
[80]

Censys

Censys同样是一款国外的搜索引擎,提供了search、view、report、query、export以及data六种API接口。
search:请求地址是https://www.censys.io/api/v1/search/?,其中?的地方可以是ipv4、websites或者certificates,分别代表搜索ipv4主机、网站和证书。通过POST请求发送一组包含query、page、fields的json数据,其中query是相应的搜索语句;page代表返回的页码,默认返回1页的数据;fields是需要返回的字段。
同样的,其客户端请求时也需要提供在注册会员时得到的UID和KEY。
Censys搜索引擎能够扫描整个互联网,Censys 每天都会扫描IPv4地址空间,以搜索所有联网设备并收集相关的信息,并返回一份有关资源(如设备、网站和证书)配置和部署信息的总体报告。
Censys使用到了ZMap和ZGrab,其中ZMap是一款网络扫描器,它能够扫描特定机器,以寻找可能被利用的安全漏洞,它分析了40亿个IP地址,并每天搜集这些IP地址上设备的信息;ZGrab是一款应用层扫描器。
python 代码示例:

import censys

api = censys.ipv4.CensysIPv4(api_id="[INSERT_KEY]", api_secret="[INSERT_KEY]")

>>> res = api.search("ip:8.8.8.8")
>>> res
{u'status': u'ok', u'results': [{u'ip': u'8.8.8.8', u'protocols': [u'53/dns']}], u'metadata': {u'count': 1, u'query': u'ip:8.8.8.8', u'backend_time': 34, u'page': 1, u'pages': 1}}

Zoomeye

zoomeye是国内的一款在线资产搜集搜索引擎,由知道创宇开发,是针对网络空间的搜索引擎,收录了互联网空间中的设备、网站及其使用的服务或组件等信息。
其使用与上面的两个搜索引擎类似,需要注册和获取API,具体用法参考在线官方开发文档。
其界面友好,中文排版,适合国内用户使用。
免费注册用户可以查看搜索结果的前100页
使用举例

指定搜索的组件以及版本
app:组件名称
ver:组件版本
例如:搜索 apache组件 版本2.4
app:apache ver:2.4

指定搜索的端口
port:端口号
例如:搜索开放了SSH端口的主机
port:22

一些服务器可能监听了非标准的端口。要按照更精确的协议进行检索,可以使用service进行过滤。

指定搜索的操作系统
OS:操作系统名称
例如:搜索Linux操作系统
OS:Linux

指定搜索的服务
service:服务名称
例如,搜素SSH服务
Service:SSH

指定搜索的地理位置范
country:国家名
city:城市名
例如:
country:China
city:Beijing

搜索指定的CIDR网段
CIDR:网段区域
例如:
CIDR:192.168.158.12/24[

搜索指定的网站域名
Site:网站域名
例如:
site:www.baidu

搜索指定的主机名
Hostname:主机名
例如:
hostname:zwl.cuit.edu

搜索指定的设备名
Device:设备名
例如:
device:router

搜索具有特定首页关键词的主机
Keyword:关键词
例如:
keyword:technology

python代码示例:

import requests
import json


def get_info():
    ip_list = []
    page = 1
    access_token = 'YOUR_TOKEN'
    headers = {'Authorization' : 'JWT ' + access_token}
    while True:
        try:
            res = requests.get(url = 'https://api.zoomeye/host/search?query="phpmyadmin"&facet=app,os&page=' + str(page), headers = headers)
            r_decoded = json.loads(res.text)
            for x in r_decoded['matches']:
                ip_list.append(x['ip'])
            print('[-] info : count ' + str(page * 10))
        except Exception as e:
            if str(e.message) == 'matches':
                break
        if page == 10:
            break
        page += 1
    return ip_list


if __name__ == "__main__":
    ips = get_info()
    for i in ips:
        print(i)

Fofa

fofa也是一款国产搜索引擎,由白帽汇推出。
用法参考帮助文档和API使用说明。

python使用代码可以参考:https://github/0nise/scripts/blob/master/fofa_spider_ext.py

本文标签: 搜索引擎信息