优化banner识别模块

This commit is contained in:
Jing Ling
2020-08-05 02:13:23 +08:00
parent e2729848d9
commit ecc91f99f7
3 changed files with 20 additions and 17 deletions
+3
View File
@@ -77,6 +77,9 @@ fuzz_rule = None # fuzz域名的正则 示例:'[a-z][0-9]' 表示第一位是
brute_ip_blacklist = {'0.0.0.0', '0.0.0.1'} # IP黑名单 子域解析到IP黑名单则标记为非法子域 brute_ip_blacklist = {'0.0.0.0', '0.0.0.1'} # IP黑名单 子域解析到IP黑名单则标记为非法子域
ip_appear_maximum = 100 # 多个子域解析到同一IP次数超过100次则标记为非法(泛解析)子域 ip_appear_maximum = 100 # 多个子域解析到同一IP次数超过100次则标记为非法(泛解析)子域
# banner识别模块设置
banner_process_number = 4 # 识别进程数量(默认4)
# 代理设置 # 代理设置
enable_proxy = False # 是否使用代理(全局开关) enable_proxy = False # 是否使用代理(全局开关)
proxy_all_module = False # 代理所有模块 proxy_all_module = False # 代理所有模块
+16 -16
View File
@@ -17,25 +17,25 @@ from config import setting
from config.log import logger from config.log import logger
class MultiProcess(Module): class MultiIdentify(Module):
def __init__(self): def __init__(self):
Module.__init__(self) Module.__init__(self)
self.module = 'Identify' self.module = 'Identify'
self.source = 'Identify' self.source = 'Identify'
self.start = time.time() # 模块开始执行时间 self.start = time.time() # 模块开始执行时间
def run(self, data: list): def run(self, data):
logger.log('INFOR', f'Start Identify module') logger.log('INFOR', f'Start Identify module')
freeze_support() freeze_support()
task_queue = Manager().Queue() task_queue = Manager().Queue()
done_queue = Manager().Queue() done_queue = Manager().Queue()
for d in data: for d in data:
task_queue.put(d) task_queue.put(d)
PROCESSES_NUM = os.cpu_count() processes_num = min(setting.banner_process_number, os.cpu_count())
logger.log('INFOR', f'Creating {PROCESSES_NUM} processes to identify') logger.log('INFOR', f'Creating {processes_num} processes to identify')
result_data = [] result_data = []
_p = [] _p = []
for i in range(PROCESSES_NUM): for i in range(processes_num):
_identify = Identify() _identify = Identify()
p = Process(target=_identify.run, args=(task_queue, done_queue)) p = Process(target=_identify.run, args=(task_queue, done_queue))
_p.append(p) _p.append(p)
@@ -266,7 +266,7 @@ class Identify(object):
return True, version return True, version
def _check_rule(self, rule: hash) -> hash: def _check_rule(self, rule):
matches = rule['matches'] matches = rule['matches']
cond_map = {} cond_map = {}
@@ -351,7 +351,7 @@ class Condition(object):
self.allow_character = string.ascii_lowercase + string.digits + '_' self.allow_character = string.ascii_lowercase + string.digits + '_'
self.ignore_character = ' \t' self.ignore_character = ' \t'
def _get_token(self) -> Token: def _get_token(self):
while self.index < len(self.condstr): while self.index < len(self.condstr):
if self.condstr[self.index] in self.ignore_character: if self.condstr[self.index] in self.ignore_character:
self.index += 1 self.index += 1
@@ -392,7 +392,7 @@ class Condition(object):
return Token(TOKEN_TYPE['eof']) return Token(TOKEN_TYPE['eof'])
def pop_token(self) -> Token: def pop_token(self):
if self.back_tokens: if self.back_tokens:
return self.back_tokens.pop(0) return self.back_tokens.pop(0)
try: try:
@@ -400,10 +400,10 @@ class Condition(object):
except IndexError: except IndexError:
raise ParseException('invalid condition "%s"', self.condstr) raise ParseException('invalid condition "%s"', self.condstr)
def push_token(self, token: Token): def push_token(self, token):
self.back_tokens.append(token) self.back_tokens.append(token)
def parse_var_expression(self) -> Result: def parse_var_expression(self):
""" """
v_exp := VARIABLE v_exp := VARIABLE
""" """
@@ -416,7 +416,7 @@ class Condition(object):
return Result(name=token.name, value=token.value) return Result(name=token.name, value=token.value)
def parse_primary_expression(self) -> Result: def parse_primary_expression(self):
""" """
p_exp := (exp) p_exp := (exp)
""" """
@@ -435,7 +435,7 @@ class Condition(object):
return r return r
def parse_not_expression(self) -> Result: def parse_not_expression(self):
""" """
n_exp := NOT n_exp | NOT p_exp n_exp := NOT n_exp | NOT p_exp
""" """
@@ -452,7 +452,7 @@ class Condition(object):
logger.debug('[*] {}'.format(r)) logger.debug('[*] {}'.format(r))
return r return r
def parse_and_expression(self) -> Result: def parse_and_expression(self):
""" """
and_exp := and_exp AND n_exp and_exp := and_exp AND n_exp
""" """
@@ -482,7 +482,7 @@ class Condition(object):
return r1 return r1
def parse_or_expression(self) -> Result: def parse_or_expression(self):
""" """
or_exp := or_exp OR and_exp or_exp := or_exp OR and_exp
""" """
@@ -512,13 +512,13 @@ class Condition(object):
return r1 return r1
def parse_expression(self) -> Result: def parse_expression(self):
""" """
exp := or_exp exp := or_exp
""" """
return self.parse_or_expression() return self.parse_or_expression()
def parse(self, condstr: str, symbol_table: hash) -> bool: def parse(self, condstr, symbol_table):
self.condstr = condstr.lower() self.condstr = condstr.lower()
self.symbol_table = symbol_table self.symbol_table = symbol_table
self.index = 0 self.index = 0
+1 -1
View File
@@ -223,7 +223,7 @@ class OneForAll(object):
# Identify banner module # Identify banner module
if setting.enable_banner_identify: if setting.enable_banner_identify:
identifier = banner.Identify() identifier = banner.MultiIdentify()
self.data = identifier.run(self.data) self.data = identifier.run(self.data)
banner.save_db(self.domain, self.data) banner.save_db(self.domain, self.data)