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

 import getopt
 import requests
 import sys
 import time

 USER = ""
 PASS = ""

 def main():
     try:
         opts, args = getopt.getopt(sys.argv[1:], "hu:p:m:q:l:", ["help", "user=", "pass=", "mode=", "query=", "limit="])
     except getopt.GetoptError as e:
         print("[-] %s" % e)
         usage()
         sys.exit(2)

     username = USER
     password = PASS
     mode = "host"
     query = ""
     limit = 2048

     for o, a in opts:
         if o in ("-h", "--help"):
             usage()
             sys.exit()
         elif o in ("-u", "--user"):
             username = a
         elif o in ("-p", "--pass"):
             password = a
         elif o in ("-m", "--mode"):
             if a in ("host", "web"):
                 mode = a
             else:
                 print("[-] Unknown Mode!")
                 usage()
                 sys.exit(2)
         elif o in ("-q", "--query"):
             query = a
         elif o in ("-l", "--limit"):
             try:
                 limit = int(a)
             except ValueError as e:
                 print("[-] %s" % e)
                 usage()
                 sys.exit(2)
         else:
             pass

     if not query:
         print("[-] Query Keyword Not Found!")
         usage()
         sys.exit(2)

     print("[!] Mode: %s" % mode)
     print("[!] Query: %s" % query)
     print("[!] Limit: %s" % limit)

     try:
         choice = raw_input("Start Query? [Y/n] ")
     except NameError as e:
         choice = input("Start Query? [Y/n] ")

     if choice.lower() == "n":
         sys.exit()

     authorization = get_authorization(username, password)
     if not authorization:
         sys.exit(1)

     resources_info = get_resources_info(authorization)
     if not resources_info:
         sys.exit(1)
     else:
         print("[*] Plan: %s" % resources_info["plan"])
         print("[*] Resources: Host %s Web %s" % (resources_info["resources"]["host-search"], resources_info["resources"]["web-search"]))

     result = list()
     page = 1
     while page <= limit:
         temp = search(authorization, mode, query, str(page))
         if not temp:
             break
         result.extend(extract(mode, temp))
         print("Download Page: %s" % page)
         page += 1
     result = set(result)

     log = "ZoomEye_" + str(time.time()) + ".txt"
     with open(log, "w") as f:
         f.writelines(result)

     print("Please Check The %s" % log)

 def usage():
     print("Usage: python %s [options]" % sys.argv[0])
     print("")
     print("Options:")
     print("  -h, --help                        Show Help Message And Exit")
     print("  -u USER, --user=USER              ZoomEye E-Mail")
     print("  -p PASS, --pass=PASS              ZoomEye Password")
     print("  -m MODE, --mode=MODE              host || web (Default: host)")
     print("  -q QUERY, --query=QUERY           Query Keyword")
     print("  -l LIMIT, --limit=LIMIT           Page Limit (Default: 2048)")

 def get_authorization(username, password):
     authorization = dict()
     access_token = get_access_token(username, password)
     if access_token:
         authorization["Authorization"] = "JWT " + access_token["access_token"]
     else:
         pass
     return authorization

 def get_access_token(username, password):
     try:
         r = requests.post("https://api.zoomeye.org/user/login", json={"username": username, "password": password})
     except requests.RequestException as e:
         print("[-] %s" % e)
         print("[-] Get Access Token Failed!")
     else:
         if r.status_code == requests.codes.ok:
             return r.json()
         else:
             print("[-] %s %s \n[-] %s" % (r.status_code, r.json()["error"], r.json()["message"]))
             print("[-] Get Access Token Failed!")

 def get_resources_info(authorization):
     try:
         r = requests.get("https://api.zoomeye.org/resources-info", headers=authorization)
     except requests.RequestException as e:
         print("[-] %s" % e)
         print("[-] Get Resources Info Failed!")
     else:
         if r.status_code == requests.codes.ok:
             return r.json()
         else:
             print("[-] %s %s \n[-] %s" % (r.status_code, r.json()["error"], r.json()["message"]))
             print("[-] Get Resources Info Failed!")

 "):
     try:
         url = "https://api.zoomeye.org/" + mode + "/search?query=" + query + "&page=" + page
         print("GET %s" % url)
         r = requests.get(url, headers=authorization)
     except requests.RequestException as e:
         print("[-] %s" % e)
         print("[-] %s Search Failed!" % mode.capitalize())
     else:
         if r.status_code == requests.codes.ok:
             return r.json()
         else:
             print("[-] %s %s \n[-] %s" % (r.status_code, r.json()["error"], r.json()["message"]))
             print("[-] %s Search Failed!" % mode.capitalize())

 def extract(mode, temp):
     result = list()
     if mode == "host":
         for line in temp["matches"]:
             result.append(line["ip"] + ":" + str(line["portinfo"]["port"]) + "\n")
     else:
         for line in temp["matches"]:
             result.append(line["site"] + "\n")
     return result

 if __name__ == "__main__":
     main()

ZoomEye 钟馗之眼 搜索工具 基于API的更多相关文章

  1. ZoomEye(钟馗之眼)搜索技巧记录:

    做个记录方便查看 钟馗之眼: 指定搜索的组件:    app:组件名称    ver:组件版本    例:搜索 apache组件版本2.4:app:apache var:2.4指定搜素的端口:     ...

  2. 基于文本图形(ncurses)的文本搜索工具 ncgrep

    背景 作为一个VIM党,日常工作开发中,会经常利用grep进行关键词搜索,以快速定位到文件.如图: 利用grep进行文本搜索 但是,这一过程会有两个效率问题: 展示的结果无法进行直接交互,需要手动粘贴 ...

  3. 揭开Faiss的面纱 探究Facebook相似性搜索工具的原理

    https://www.leiphone.com/news/201703/84gDbSOgJcxiC3DW.html 本月初雷锋网报道,Facebook 开源了 AI 相似性搜索工具 Faiss.而在 ...

  4. 文件快速搜索工具-Everything的使用(转)

    首先它是一款基于名称实时定位文件和目录的搜索工具,有以下几个优点: 快速文件索引 快速文件搜索 较低资源占用 轻松分享文件索引 实时跟踪文件更新 通过使用everything小工具,可以提高我们的工作 ...

  5. Everything:速度最快的文件名搜索工具(Linux版本) 转

    Everything是windows的一个快速搜索工具. 基本上转移到Linux上来后,没有怎么用过. 一直在用Gnome-Do,感觉还可以. 这个程序只是用来练习wxPython用的,目前还只是一个 ...

  6. 文件搜索工具everything

    Everything是voidtools开发的一款文件搜索工具,官网描述为“基于名称实时定位文件和目录(Locate files and folders by name instantly) (“Ev ...

  7. Python开发环境Wing IDE搜索工具介绍

    Wing IDE编辑器的搜索工具提供了一个基于友好GUI的搜索和替换工具. 某些情况下搜索可能会跨越整个文件,也有可能被限制到当前所选择的区域:可以区分大小写,也可以设置为不区分:可以被限制为只匹配整 ...

  8. [转帖]推荐一款比 Find 快 10 倍的搜索工具 FD

    推荐一款比 Find 快 10 倍的搜索工具 FD https://www.hi-linux.com/posts/15017.html 试了下 很好用呢. Posted by Mike on 2018 ...

  9. centos locate搜索工具

    locate搜索工具 [root@localhost ~]# yum install mlocate [root@localhost ~]# locate passwd locate: can not ...

随机推荐

  1. 一起阅读《Java多线程编程核心技术》

    目录 第一章 Java多线程技能 (待续...)

  2. mongodb指南

    一.简介 从官网 https://www.mongodb.com/download-center?jmp=nav#community 下载相应平台及版本的 mongodb,解压后的 bin 文件夹中有 ...

  3. TeamViewer 12.0.71503 Patch By.Sound

    TeamViewer - the All-In-One Software for Remote Support and Online Meetings - Remote control any com ...

  4. c语言经典算法——查找一个整数数组中第二大数

    题目: 实现一个函数,查找一个整数数组中第二大数. 算法思想: 设置两个变量max1和max2,用来保存最大数和第二大数,然后将数组剩余的数依次与这两个数比较,如果这个数a比max1大,则先将max1 ...

  5. C++ 共享内存 函数封装

    #pragma once #include <string> #include <wtypes.h> #include <map> using namespace ...

  6. easyui Datagrid查询报错Uncaught TypeError:Cannot read property 'length' of undefined

    1.问题描述 easyui中datagrid执行loadData方法出现如下异常:Cannot read property 'length' of undefined 2.一开始怀疑是js或者页面的问 ...

  7. JS获取元素CSS值

    一.getComputedStyle getComputedStyle 是一个可以获取当前元素所有最终使用的CSS属性值.返回的是一个CSS样式声明对象([object CSSStyleDeclara ...

  8. Gerrit增加SSL证书

    在http的基础上增加SSL 配置gerrit.config文件 [gerrit] basePath = git canonicalWebUrl = https://172.16.99.212/ .. ...

  9. 在Xcode5中修改整个项目名

    总会遇到几个项目,在做到一半的时候被要求改项目名,网上找了下相关的资料,大多数是xcode5以前的版本,所以解决好了在这里mark一下,给需要的人. 目标为:将项目名XCD4改成xcd5. 先上结果图 ...

  10. Python 之旅

    Python2 之旅:   https://funhacks.net/explore-python/ <Python Cookbook>第三版   PYTHON3   http://pyt ...