Censys


 

censys

Censys

  Censys持續監控互聯網上所有可訪問的服務器和設備,以便您可以實時搜索和分析它們,了解你的網絡攻擊面,發現新的威脅並評估其全球影響。從互聯網領先的掃描儀ZMap的創造者來說,我們的使命是通過數據驅動安全。

  Censys跟國外的Shodan和國內的ZoomEye類似,可以搜索世界范圍內的聯網設備。Shodan和ZoomEye是個人用的比較多的兩款,當然國內還有傻蛋fofa, 國外也有其他類似的搜索引擎,這里就不一一列舉了。

  Censys與Shodan相比是一款免費搜索引擎,當然也有一定的限制(速度和搜索結果),而新改版后的ZoomEye對國內的搜索結果做了處理,幾乎沒有什么價值,對於非天朝的搜索還是可以適用的,如果對這兩款搜索引擎感興趣的朋友可以去試用一下,博客中也有關於這兩款搜索引擎介紹,可自行查找。

  先來膜拜一下發表在信息安全頂會CCS'15 : A Search Engine Backed by Internet-Wide Scanning 。

  Censys提供6種API的使用方式,如下:

 

  不過這里我們僅介紹第一種的使用,即獲取搜索條件下的ip地址,這個也是我們用的最多的。

使用說明

  當然在使用之前也是需要注冊一個賬號的,因為在使用API時需要提供API Credentials即你的ID和Secret,可以在個人信息中看到。

 

   最下面是使用的速度限制,我們可以在程序中設置一個延時,比如每查詢一次睡眠三秒鍾,總體來說,速度還是比較可觀的。

官方示例

  初看確實感覺搜索語法好像略微繁瑣,沒有Shodan和ZoomEye那么簡練,而且文檔也不夠,怎么說呢,簡單明了吧。不信你點開看看

查詢語法

  Search 的Data Parameters 主要有四個,分別是

  • query:查詢語句
  • page:查詢頁
  • fields:查詢的結果域(可選)
  • flatten:平整的結果(可選)
Example:
{
  "query":"80.http.get.headers.server: Apache",
  "page":1,
  "fields":["ip", "location.country", "autonomous_system.asn"],
  "flatten":true
}

  好了,說明部分差不多到這里了,下面給出一個完整的示例。

示例

  一般來說我們在查詢的時候,會加上一定的限制條件,比如天朝的某些設備,如:"query": "weblogic and location.country_code: CN"。

#!/usr/bin/env python
# -*- coding:utf-8 -*-

import sys
import json
import requests
import time

API_URL = "https://www.censys.io/api/v1"
UID = "aa7c1f3a-b6ab-497d-9788-5e9e4898a655"
SECRET = "pay3u4ytGjbdZGftJ8ow50E8hBQVLk7j"
page = 1
PAGES = 50           # the pages you want to fetch


def getIp(query, page):
    '''
    Return ips and total amount when doing query
    '''
    iplist = []
    data = {
        "query": query,
        "page": page,
        "fields": ["ip", "protocols", "location.country"]
    }
    try:
        res = requests.post(API_URL + "/search/ipv4", data=json.dumps(data), auth=(UID, SECRET))
    except:
        pass
    try:
        results = res.json()
    except:
        pass
    if res.status_code != 200:
        print("error occurred: %s" % results["error"])
        sys.exit(1)
    # total query result
    iplist.append("Total_count:%s" % (results["metadata"]["count"]))

    # add result in some specific form
    for result in results["results"]:
        for i in result["protocols"]:
            # iplist.append(result["ip"] + ':' + i + ' in ' + result["location.country"][0])
            iplist.append(result["ip"] + ':' + i)
    # return ips and total count
    return iplist, results["metadata"]["count"]


if __name__ == '__main__':

    query = input('please input query string : ')
    print('---', query, '---')
    ips, num = getIp(query=query, page=page)

    print("Total_count:%s" % num)

    dst = input('please input file name to save data (censys.txt default) : ')

    # 保存數據到文件
    if dst:
        dst = dst + '.txt'
    else:
        dst = 'censys.txt'

    # get result and save to file page by page
    with open(dst, 'a') as f:
        while page <= PAGES:
            print('page :' + str(page))
            iplist, num = (getIp(query=query, page=page))
            page += 1

            for i in iplist:
                print i[:i.find('/')]

            for i in iplist:
                f.write(i[:i.find('/')] + '\n')
            time.sleep(3)
    print('Finished. data saved to file', dst)

Sample:

starnight:censys starnight$ python script.py
please input query string : "weblogic"
('---', 'weblogic', '---')
Total_count:11836
please input file name to save data (censys.txt default) : "weblogic"
page :1
Total_count:1183
46.244.104.198:80
46.244.104.198:8080
31.134.202.10:2323
31.134.202.10:80
31.134.202.10:8080
31.134.203.85:2323
31.134.203.85:80
31.134.203.85:8080
31.134.205.92:2323
31.134.205.92:80
31.134.205.92:8080
31.134.206.202:2323
31.134.206.202:80
31.134.206.202:8080
31.134.201.249:80
31.134.201.249:8080
31.134.202.233:80
31.134.202.233:8080
31.134.200.94:80
31.134.200.94:8080
31.134.201.248:80
31.134.201.248:8080
31.134.200.6:80
31.134.200.6:8080
46.244.105.216:80
46.244.105.216:8080
31.134.206.131:80
31.134.206.131:2323
31.134.206.131:8080
31.134.204.127:80
31.134.204.127:8080
46.244.10.173:80
46.244.10.173:23
46.244.10.173:8080
31.134.202.82:80
31.134.202.82:8080
46.244.105.252:80
46.244.105.252:2323
46.244.105.252:8080
31.134.205.186:2323
31.134.205.186:80
31.134.205.186:8080
31.134.204.223:80
31.134.204.223:8080
31.134.207.182:2323
31.134.207.182:80
31.134.207.182:8080

  好像結果不是很准確 ~ 哈哈 ~ 另外,個人可以對返回iplist做相應的改變以方便自己使用 ~ 


  今天上午收到一封郵件,說Censys的商業版本要出來了 ~ 敬請期待 (2017.11.14)

  


  最后,Github地址: censys

References

  信息收集之censys

  Censys 搜索語法


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM