Censys持續監控互聯網上全部可訪問的服務器和設備,以便您能夠實時搜索和分析它們,瞭解你的網絡攻擊面,發現新的威脅並評估其全球影響。從互聯網領先的掃描儀ZMap的創造者來講,咱們的使命是經過數據驅動安全。html
Censys跟國外的Shodan和國內的ZoomEye相似,能夠搜索世界範圍內的聯網設備。Shodan和ZoomEye是我的用的比較多的兩款,固然國內還有傻蛋和fofa, 國外也有其餘相似的搜索引擎,這裏就不一一列舉了。python
Censys與Shodan相比是一款免費搜索引擎,固然也有必定的限制(速度和搜索結果),而新改版後的ZoomEye對國內的搜索結果作了處理,幾乎沒有什麼價值,對於非天朝的搜索仍是能夠適用的,若是對這兩款搜索引擎感興趣的朋友能夠去試用一下,博客中也有關於這兩款搜索引擎介紹,可自行查找。git
先來膜拜一下發表在信息安全頂會CCS'15 : A Search Engine Backed by Internet-Wide Scanning 。github
Censys提供6種API的使用方式,以下:web
不過這裏咱們僅介紹第一種的使用,即獲取搜索條件下的ip地址,這個也是咱們用的最多的。json
固然在使用以前也是須要註冊一個帳號的,由於在使用API時須要提供API Credentials即你的ID和Secret,能夠在我的信息中看到。api
最下面是使用的速度限制,咱們能夠在程序中設置一個延時,好比每查詢一次睡眠三秒鐘,整體來講,速度仍是比較可觀的。安全
初看確實感受搜索語法好像略微繁瑣,沒有Shodan和ZoomEye那麼簡練,並且文檔也不夠,怎麼說呢,簡單明瞭吧。不信你點開看看服務器
Search 的Data Parameters 主要有四個,分別是網絡
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