-
Notifications
You must be signed in to change notification settings - Fork 750
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
358 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# !/usr/bin/env python | ||
# -*- coding: utf-8 -*- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# !/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
__author__ = 'xy' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
""" | ||
Copyright (c) 2014-2016 pocsuite developers (https://seebug.org) | ||
See the file 'docs/COPYING' for copying permission | ||
""" | ||
import os | ||
|
||
|
||
# TODO 这里不改成统一的path调用? | ||
def initial(): | ||
currentUserHomePath = os.path.expanduser('~') | ||
_ = """[zoomeye]\nusername = Your ZoomEye Username\npassword = Your ZoomEye Password\n\n[token]\nseebug = Your Seebug Token""" | ||
if not os.path.isfile(currentUserHomePath + '/.rc'): | ||
with open(os.path.join(currentUserHomePath, '.rc'), 'w') as fp: | ||
fp.write(_) | ||
|
||
|
||
initial() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
""" | ||
Copyright (c) 2014-2016 pocsuite developers (https://seebug.org) | ||
See the file 'docs/COPYING' for copying permission | ||
""" | ||
import ast | ||
import json | ||
import urllib | ||
import requests | ||
import ConfigParser | ||
from .rcGen import initial | ||
|
||
|
||
class ZoomEye(): | ||
def __init__(self, confPath=None): | ||
self.plan = self.token = None | ||
self.headers = self.username = self.password = None | ||
self.resources = {} | ||
|
||
if confPath: | ||
self.confPath = confPath | ||
self.parser = ConfigParser.ConfigParser() | ||
self.parser.read(self.confPath) | ||
|
||
self.username = self.parser.get('zoomeye', 'Username') | ||
self.password = self.parser.get('zoomeye', 'Password') | ||
|
||
def newToken(self): | ||
data = '{{"username": "{}", "password": "{}"}}'.format(self.username, self.password) | ||
req = requests.post('https://api.zoomeye.org/user/login', data=data, ) | ||
content = json.loads(req.content) | ||
if req.status_code != 401 and "access_token" in content: | ||
self.token = content['access_token'] | ||
self.headers = {'Authorization': 'JWT %s' % self.token} | ||
return True | ||
return False | ||
|
||
def resourceInfo(self): | ||
req = requests.get('https://api.zoomeye.org/resources-info', headers=self.headers, ) | ||
content = json.loads(req.content) | ||
if 'plan' in content: | ||
self.plan = content['plan'] | ||
self.resources['web-search'] = content['resources']['web-search'] | ||
self.resources['host-search'] = content['resources']['host-search'] | ||
return True | ||
return False | ||
|
||
def search(self, dork, page=1, resource='web'): | ||
req = requests.get( | ||
'https://api.zoomeye.org/{}/search?query="{}"&page={}&facet=app,os'.format(resource, urllib.quote(dork), page + 1), | ||
headers=self.headers | ||
) | ||
content = json.loads(req.content) | ||
if 'matches' in content: | ||
return [match['ip'] for match in content['matches']] | ||
else: | ||
return [] | ||
|
||
def write_conf(self): | ||
if not self.parser.has_section("zoomeye"): | ||
self.parser.add_section("zoomeye") | ||
|
||
username = raw_input("ZoomEye Email:") | ||
password = raw_input("ZoomEye Password:") | ||
self.parser.set("zoomeye", "Username", username) | ||
self.parser.set("zoomeye", "Password", password) | ||
self.username = username | ||
self.password = password | ||
self.parser.write(open(self.confPath, "w")) | ||
|
||
|
||
class Seebug(): | ||
def __init__(self, confPath=None): | ||
self.token = None | ||
|
||
if confPath: | ||
self.confPath = confPath | ||
self.parser = ConfigParser.ConfigParser() | ||
self.parser.read(self.confPath) | ||
self.token = self.parser.get('token', 'seebug') | ||
|
||
self.headers = {'Authorization': 'Token %s' % self.token} | ||
|
||
def static(self): | ||
req = requests.get('https://www.seebug.org/api/user/poc_list', headers=self.headers, ) | ||
self.stats = ast.literal_eval(req.content) | ||
if 'detail' in self.stats: | ||
return False | ||
return 'According to record total %s PoC purchased' % len(self.stats) | ||
|
||
def seek(self, keyword): | ||
req = requests.get('https://www.seebug.org/api/user/poc_list?q=%s' % keyword, headers=self.headers, ) | ||
self.pocs = ast.literal_eval(req.content) | ||
return '%s purchased poc related to keyword "%s"' % (len(self.pocs), keyword) | ||
|
||
def retrieve(self, ID): | ||
req = requests.get('https://www.seebug.org/api/user/poc_detail?id=%s' % ID, headers=self.headers, ) | ||
return ast.literal_eval(req.content) | ||
|
||
def write_conf(self): | ||
if not self.parser.has_section("token"): | ||
self.parser.add_section("token") | ||
|
||
token = raw_input("Seebug Token:") | ||
self.parser.set("token", "seebug", token) | ||
self.token = token | ||
self.parser.write(open(self.confPath, "w")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
""" | ||
Copyright (c) 2014-2016 pocsuite developers (https://seebug.org) | ||
See the file 'docs/COPYING' for copying permission | ||
""" | ||
from pocsuite.thirdparty import requests | ||
from pocsuite.lib.core.data import logger | ||
from pocsuite.lib.core.enums import CUSTOM_LOGGING | ||
|
||
|
||
class Zoomeye(object): | ||
|
||
def __init__(self, token, host="api.zoomeye.org"): | ||
self._base_uri = "http://%s" % host | ||
self._headers = {"Authorization": "JWT %s" % token, "Content-Type": "application/json"} | ||
|
||
def _response_for(self, path): | ||
uri = "/".join([self._base_uri, path]) | ||
response = requests.get(uri, headers=self._headers) | ||
if response.status_code == 200: | ||
body = self._handle_success(response, uri) | ||
return body | ||
else: | ||
self._handle_error(response, uri) | ||
|
||
def _handle_success(self, response, uri): | ||
try: | ||
return response.json() | ||
except ValueError as ex: | ||
logger.log(CUSTOM_LOGGING.ERROR, ex) | ||
|
||
def _handle_error(self, response, uri): | ||
status = response.status_code | ||
|
||
if 400 <= status < 500: | ||
self._handle_4xx_status(response, status, uri) | ||
elif 500 <= status < 600: | ||
self._handle_5xx_status(status, uri) | ||
else: | ||
self._handle_non_200_status(status, uri) | ||
|
||
def _handle_non_200_status(self, status, uri): | ||
errMsg = "Received a very surprising HTTP status %i for %s" % (status, uri) | ||
logger.log(CUSTOM_LOGGING.ERROR, errMsg) | ||
|
||
def _handle_5xx_status(self, status, uri): | ||
errMsg = "Received a server error %i for %s" % (status, uri) | ||
logger.log(CUSTOM_LOGGING.ERROR, errMsg) | ||
|
||
def _handle_4xx_status(self, response, status, uri): | ||
if not response.content: | ||
errMsg = "Received a %i error for %s with no body." % (status, uri) | ||
logger.log(CUSTOM_LOGGING.ERROR, errMsg) | ||
elif response.headers["Content-Type"].find("json") == -1: | ||
errMsg = "Received a %i for %s with the following body: %s" % (status, uri, response.content) | ||
logger.log(CUSTOM_LOGGING.ERROR, errMsg) | ||
|
||
try: | ||
body = response.json() | ||
except ValueError: | ||
errMsg = "Received a %i error for %s but it did not include the expected JSON body" % (status, uri) | ||
logger.log(CUSTOM_LOGGING.ERROR, errMsg) | ||
else: | ||
if "error" in body: | ||
self._handle_web_service_error(body.get("error"), status, uri) | ||
else: | ||
errMsg = "Response contains JSON but it does not specify code or error keys" | ||
logger.log(CUSTOM_LOGGING.ERROR, errMsg) | ||
|
||
def _handle_web_service_error(self, message, status, uri): | ||
if message == "unauthorized": | ||
errMsg = "AuthenticationError, please check your Zoomeye Token" | ||
logger.log(CUSTOM_LOGGING.ERROR, errMsg) | ||
else: | ||
logger.log(CUSTOM_LOGGING.ERROR, message) | ||
|
||
def resource_info(self): | ||
return self._response_for("resources-info") | ||
|
||
def search(self, keyword, page=1, searchtype="web"): | ||
path = '%s/search?query="%s"&page=%s&fact=app,os' % (searchtype, keyword, page) | ||
return self._response_for(path) | ||
|
||
|
||
if __name__ == "__main__": | ||
z = Zoomeye("RSjz3c") | ||
print z.search("port:80") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# !/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
import sys | ||
import os | ||
import time | ||
from lib.api.zoomeye.x import ZoomEye | ||
from lib.core.data import conf, paths, logger | ||
from lib.core.log import CUSTOM_LOGGING | ||
|
||
|
||
def runZoomeyeApi(args): | ||
if args['dork']: | ||
z = ZoomEye(paths.RC_PATH) | ||
if z.newToken(): | ||
logger.log(CUSTOM_LOGGING.SUCCESS, 'ZoomEye API authorization success.') | ||
z.resourceInfo() | ||
else: | ||
logger.log(CUSTOM_LOGGING.SUCCESS, | ||
'ZoomEye API authorization failed,Please input ZoomEye Email and Password for use ZoomEye API!') | ||
z.write_conf() | ||
if z.newToken(): | ||
logger.log(CUSTOM_LOGGING.SUCCESS, 'ZoomEye API authorization success.') | ||
z.resourceInfo() | ||
else: | ||
sys.exit(logger.log(CUSTOM_LOGGING.ERROR, | ||
'ZoomEye API authorization failed, make sure correct credentials provided in "~/.pocsuiterc".')) | ||
|
||
info = z.resources | ||
logger.log( | ||
CUSTOM_LOGGING.SYSINFO, | ||
'Available ZoomEye search, web-search:{}, host-search:{}'.format(info['web-search'], info['host-search']) | ||
) | ||
|
||
tmpIpFile = os.path.join(conf.ZOOMEYE_OUTPUT_PATH, '%s_%s.txt' % ( | ||
args['dork'].replace(':', '-').replace(' ', '-').strip(), time.strftime('%Y_%m_%d_%H_%M_%S'))) | ||
with open(tmpIpFile, 'w') as fp: | ||
search_types = args.get('search_type', 'web') | ||
if 'host' not in search_types and 'web' not in search_types: | ||
search_types = 'web' | ||
for page in range(args.get('max_page', 1)): | ||
for search_type in search_types.split(','): | ||
if search_type in ['web', 'host']: | ||
for ip in z.search(args['dork'], page, search_type): | ||
if type(ip) == list: | ||
fp.write('%s\n' % ip[0]) | ||
else: | ||
fp.write('%s\n' % ip) | ||
return tmpIpFile | ||
|
||
|
||
def setApi(): | ||
# TODO 判断使用哪家的api | ||
return runZoomeyeApi(conf) |
Oops, something went wrong.