mirror of
https://github.com/shmilylty/OneForAll.git
synced 2026-08-26 12:57:50 +08:00
统一异常处理
This commit is contained in:
@@ -63,7 +63,7 @@ class Database(object):
|
|||||||
f'elapsed float,'
|
f'elapsed float,'
|
||||||
f'count int)')
|
f'count int)')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.log('ERROR', e)
|
logger.log('ERROR', e.args)
|
||||||
|
|
||||||
def save_db(self, table_name, results, module_name=None):
|
def save_db(self, table_name, results, module_name=None):
|
||||||
"""
|
"""
|
||||||
@@ -88,7 +88,7 @@ class Database(object):
|
|||||||
f':response, :module, :source,:elapsed, :count)',
|
f':response, :module, :source,:elapsed, :count)',
|
||||||
results)
|
results)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.log('ERROR', e)
|
logger.log('ERROR', e.args)
|
||||||
|
|
||||||
def exist_table(self, table_name):
|
def exist_table(self, table_name):
|
||||||
"""
|
"""
|
||||||
@@ -103,7 +103,7 @@ class Database(object):
|
|||||||
f'where type = "table" and '
|
f'where type = "table" and '
|
||||||
f'name = "{table_name}"')
|
f'name = "{table_name}"')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.log('ERROR', e)
|
logger.log('ERROR', e.args)
|
||||||
else:
|
else:
|
||||||
if len(result) != 0:
|
if len(result) != 0:
|
||||||
return True
|
return True
|
||||||
@@ -125,7 +125,7 @@ class Database(object):
|
|||||||
self.conn.query(f'create table "{bak_table_name}" '
|
self.conn.query(f'create table "{bak_table_name}" '
|
||||||
f'as select * from "{table_name}"')
|
f'as select * from "{table_name}"')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.log('ERROR', e)
|
logger.log('ERROR', e.args)
|
||||||
|
|
||||||
def clear_table(self, table_name):
|
def clear_table(self, table_name):
|
||||||
"""
|
"""
|
||||||
@@ -138,7 +138,7 @@ class Database(object):
|
|||||||
try:
|
try:
|
||||||
self.conn.query(f'delete from "{table_name}"')
|
self.conn.query(f'delete from "{table_name}"')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.log('ERROR', e)
|
logger.log('ERROR', e.args)
|
||||||
|
|
||||||
def drop_table(self, table_name):
|
def drop_table(self, table_name):
|
||||||
"""
|
"""
|
||||||
@@ -151,7 +151,7 @@ class Database(object):
|
|||||||
try:
|
try:
|
||||||
self.conn.query(f'drop table if exists "{table_name}"')
|
self.conn.query(f'drop table if exists "{table_name}"')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.log('ERROR', e)
|
logger.log('ERROR', e.args)
|
||||||
|
|
||||||
def rename_table(self, table_name, new_table_name):
|
def rename_table(self, table_name, new_table_name):
|
||||||
"""
|
"""
|
||||||
@@ -167,7 +167,7 @@ class Database(object):
|
|||||||
self.conn.query(f'alter table "{table_name}" '
|
self.conn.query(f'alter table "{table_name}" '
|
||||||
f'rename to "{new_table_name}"')
|
f'rename to "{new_table_name}"')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.log('ERROR', e)
|
logger.log('ERROR', e.args)
|
||||||
|
|
||||||
def deduplicate_subdomain(self, table_name):
|
def deduplicate_subdomain(self, table_name):
|
||||||
"""
|
"""
|
||||||
@@ -182,7 +182,7 @@ class Database(object):
|
|||||||
f'delete from "{table_name}" where id not in (select min(id) '
|
f'delete from "{table_name}" where id not in (select min(id) '
|
||||||
f'from "{table_name}" group by subdomain)')
|
f'from "{table_name}" group by subdomain)')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.log('ERROR', e)
|
logger.log('ERROR', e.args)
|
||||||
|
|
||||||
def remove_invalid(self, table_name):
|
def remove_invalid(self, table_name):
|
||||||
"""
|
"""
|
||||||
@@ -197,7 +197,7 @@ class Database(object):
|
|||||||
f'delete from "{table_name}" where '
|
f'delete from "{table_name}" where '
|
||||||
f'subdomain is null or valid == 0')
|
f'subdomain is null or valid == 0')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.log('ERROR', e)
|
logger.log('ERROR', e.args)
|
||||||
|
|
||||||
def get_data(self, table_name):
|
def get_data(self, table_name):
|
||||||
"""
|
"""
|
||||||
@@ -210,7 +210,7 @@ class Database(object):
|
|||||||
try:
|
try:
|
||||||
rows = self.conn.query(f'select * from "{table_name}"')
|
rows = self.conn.query(f'select * from "{table_name}"')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.log('ERROR', e)
|
logger.log('ERROR', e.args)
|
||||||
else:
|
else:
|
||||||
return rows
|
return rows
|
||||||
|
|
||||||
@@ -231,7 +231,7 @@ class Database(object):
|
|||||||
try:
|
try:
|
||||||
rows = self.conn.query(query)
|
rows = self.conn.query(query)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.log('ERROR', e)
|
logger.log('ERROR', e.args)
|
||||||
else:
|
else:
|
||||||
return rows
|
return rows
|
||||||
|
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ class Module(object):
|
|||||||
verify=self.verify,
|
verify=self.verify,
|
||||||
**kwargs)
|
**kwargs)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.log('ERROR', e)
|
logger.log('ERROR', e.args)
|
||||||
return None
|
return None
|
||||||
if not check:
|
if not check:
|
||||||
return resp
|
return resp
|
||||||
@@ -113,7 +113,7 @@ class Module(object):
|
|||||||
verify=self.verify,
|
verify=self.verify,
|
||||||
**kwargs)
|
**kwargs)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.log('ERROR', e)
|
logger.log('ERROR', e.args)
|
||||||
return None
|
return None
|
||||||
if not check:
|
if not check:
|
||||||
return resp
|
return resp
|
||||||
@@ -141,7 +141,7 @@ class Module(object):
|
|||||||
verify=self.verify,
|
verify=self.verify,
|
||||||
**kwargs)
|
**kwargs)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.log('ERROR', e)
|
logger.log('ERROR', e.args)
|
||||||
return None
|
return None
|
||||||
if not check:
|
if not check:
|
||||||
return resp
|
return resp
|
||||||
|
|||||||
@@ -96,8 +96,8 @@ async def fetch(session, url):
|
|||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
text = await resp.text(errors='ignore')
|
text = await resp.text(errors='ignore')
|
||||||
return resp, text
|
return resp, text
|
||||||
except BaseException as exception:
|
except Exception as e:
|
||||||
return exception
|
return e
|
||||||
|
|
||||||
|
|
||||||
def get_title(markup):
|
def get_title(markup):
|
||||||
@@ -146,7 +146,7 @@ def get_title(markup):
|
|||||||
def request_callback(future, index, datas):
|
def request_callback(future, index, datas):
|
||||||
try:
|
try:
|
||||||
result = future.result()
|
result = future.result()
|
||||||
except BaseException as e:
|
except Exception as e:
|
||||||
logger.log('TRACE', e.args)
|
logger.log('TRACE', e.args)
|
||||||
datas[index]['reason'] = str(e.args)
|
datas[index]['reason'] = str(e.args)
|
||||||
datas[index]['valid'] = 0
|
datas[index]['valid'] = 0
|
||||||
|
|||||||
@@ -29,9 +29,9 @@ async def dns_query_a(hostname):
|
|||||||
resolver = dns_resolver()
|
resolver = dns_resolver()
|
||||||
try:
|
try:
|
||||||
answer = resolver.query(hostname, 'A')
|
answer = resolver.query(hostname, 'A')
|
||||||
except BaseException as exception:
|
except Exception as e:
|
||||||
logger.log('TRACE', exception.args)
|
logger.log('TRACE', e.args)
|
||||||
answer = exception
|
answer = e
|
||||||
return answer
|
return answer
|
||||||
|
|
||||||
|
|
||||||
@@ -45,9 +45,9 @@ async def aiodns_query_a(hostname):
|
|||||||
try:
|
try:
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
answer = await loop.getaddrinfo(hostname, 'http')
|
answer = await loop.getaddrinfo(hostname, 'http')
|
||||||
except BaseException as exception:
|
except Exception as e:
|
||||||
logger.log('TRACE', exception.args)
|
logger.log('TRACE', e.args)
|
||||||
answer = exception
|
answer = e
|
||||||
return answer
|
return answer
|
||||||
|
|
||||||
|
|
||||||
@@ -61,7 +61,7 @@ def resolve_callback(future, index, datas):
|
|||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
answer = future.result()
|
answer = future.result()
|
||||||
except BaseException as e:
|
except Exception as e:
|
||||||
datas[index]['ips'] = str(e.args)
|
datas[index]['ips'] = str(e.args)
|
||||||
datas[index]['valid'] = 0
|
datas[index]['valid'] = 0
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -190,7 +190,7 @@ def save_data(fpath, data):
|
|||||||
file.write(data)
|
file.write(data)
|
||||||
logger.log('ALERT', fpath)
|
logger.log('ALERT', fpath)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.log('ERROR', e)
|
logger.log('ERROR', e.args)
|
||||||
|
|
||||||
|
|
||||||
def check_response(method, resp):
|
def check_response(method, resp):
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ class CheckAXFR(Module):
|
|||||||
try:
|
try:
|
||||||
answers = resolver.query(self.domain, "NS")
|
answers = resolver.query(self.domain, "NS")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.log('ERROR', e)
|
logger.log('ERROR', e.args)
|
||||||
return
|
return
|
||||||
nsservers = [str(answer) for answer in answers]
|
nsservers = [str(answer) for answer in answers]
|
||||||
if not len(nsservers):
|
if not len(nsservers):
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ class CheckCert(Module):
|
|||||||
sock.connect((self.domain, self.port))
|
sock.connect((self.domain, self.port))
|
||||||
cert_dict = sock.getpeercert()
|
cert_dict = sock.getpeercert()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.log('ERROR', e)
|
logger.log('ERROR', e.args)
|
||||||
return
|
return
|
||||||
subdomains = utils.match_subdomain(self.domain, str(cert_dict))
|
subdomains = utils.match_subdomain(self.domain, str(cert_dict))
|
||||||
self.subdomains = self.subdomains.union(subdomains)
|
self.subdomains = self.subdomains.union(subdomains)
|
||||||
|
|||||||
@@ -81,8 +81,8 @@ class BruteThread(threading.Thread):
|
|||||||
logger.log('TRACE', f'尝试查询{name}的SRV记录')
|
logger.log('TRACE', f'尝试查询{name}的SRV记录')
|
||||||
try:
|
try:
|
||||||
answer = self.resolver.query(name, 'SRV')
|
answer = self.resolver.query(name, 'SRV')
|
||||||
except Exception as exception:
|
except Exception as e:
|
||||||
logger.log('TRACE', exception.args)
|
logger.log('TRACE', e.args)
|
||||||
logger.log('TRACE', f'查询{name}的SRV记录失败')
|
logger.log('TRACE', f'查询{name}的SRV记录失败')
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -87,4 +87,4 @@ def do(domain): # 统一入口名字 方便多线程调用
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
do('example.com')
|
do('huawei.com')
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ class Github(Search):
|
|||||||
try:
|
try:
|
||||||
resp = self.session.post(self.post_url, data=post_data)
|
resp = self.session.post(self.post_url, data=post_data)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.log('ERROR', e)
|
logger.log('ERROR', e.args)
|
||||||
return False
|
return False
|
||||||
if resp.status_code != 200:
|
if resp.status_code != 200:
|
||||||
return False
|
return False
|
||||||
@@ -58,7 +58,7 @@ class Github(Search):
|
|||||||
try:
|
try:
|
||||||
resp = self.session.get(self.login_url)
|
resp = self.session.get(self.login_url)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.log('ERROR', e)
|
logger.log('ERROR', e.args)
|
||||||
return None
|
return None
|
||||||
if resp.status_code != 200:
|
if resp.status_code != 200:
|
||||||
return None
|
return None
|
||||||
@@ -85,7 +85,7 @@ class Github(Search):
|
|||||||
try:
|
try:
|
||||||
resp = self.session.get(self.addr, params=params)
|
resp = self.session.get(self.addr, params=params)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.log('ERROR', e)
|
logger.log('ERROR', e.args)
|
||||||
break
|
break
|
||||||
if resp.status_code != 200:
|
if resp.status_code != 200:
|
||||||
logger.log('ERROR', f'{self.session}模块搜索出错')
|
logger.log('ERROR', f'{self.session}模块搜索出错')
|
||||||
|
|||||||
@@ -34,8 +34,8 @@ def get_cname(subdomain):
|
|||||||
resolver = resolve.dns_resolver()
|
resolver = resolve.dns_resolver()
|
||||||
try:
|
try:
|
||||||
answers = resolver.query(subdomain, 'CNAME')
|
answers = resolver.query(subdomain, 'CNAME')
|
||||||
except Exception as exception:
|
except Exception as e:
|
||||||
logger.log('TRACE', exception.args)
|
logger.log('TRACE', e.args)
|
||||||
return None
|
return None
|
||||||
for answer in answers:
|
for answer in answers:
|
||||||
return answer.to_text() # 一个子域只有一个CNAME记录
|
return answer.to_text() # 一个子域只有一个CNAME记录
|
||||||
|
|||||||
Reference in New Issue
Block a user