From ecc91f99f7265196b4321dd2c216b4aec07e1f92 Mon Sep 17 00:00:00 2001 From: Jing Ling Date: Wed, 5 Aug 2020 02:13:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96banner=E8=AF=86=E5=88=AB?= =?UTF-8?q?=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/setting.py | 3 +++ modules/banner.py | 32 ++++++++++++++++---------------- oneforall.py | 2 +- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/config/setting.py b/config/setting.py index 21b5ce7..8806b8b 100644 --- a/config/setting.py +++ b/config/setting.py @@ -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黑名单则标记为非法子域 ip_appear_maximum = 100 # 多个子域解析到同一IP次数超过100次则标记为非法(泛解析)子域 +# banner识别模块设置 +banner_process_number = 4 # 识别进程数量(默认4) + # 代理设置 enable_proxy = False # 是否使用代理(全局开关) proxy_all_module = False # 代理所有模块 diff --git a/modules/banner.py b/modules/banner.py index 8880bf9..4861834 100644 --- a/modules/banner.py +++ b/modules/banner.py @@ -17,25 +17,25 @@ from config import setting from config.log import logger -class MultiProcess(Module): +class MultiIdentify(Module): def __init__(self): Module.__init__(self) self.module = 'Identify' self.source = 'Identify' self.start = time.time() # 模块开始执行时间 - def run(self, data: list): + def run(self, data): logger.log('INFOR', f'Start Identify module') freeze_support() task_queue = Manager().Queue() done_queue = Manager().Queue() for d in data: task_queue.put(d) - PROCESSES_NUM = os.cpu_count() - logger.log('INFOR', f'Creating {PROCESSES_NUM} processes to identify') + processes_num = min(setting.banner_process_number, os.cpu_count()) + logger.log('INFOR', f'Creating {processes_num} processes to identify') result_data = [] _p = [] - for i in range(PROCESSES_NUM): + for i in range(processes_num): _identify = Identify() p = Process(target=_identify.run, args=(task_queue, done_queue)) _p.append(p) @@ -266,7 +266,7 @@ class Identify(object): return True, version - def _check_rule(self, rule: hash) -> hash: + def _check_rule(self, rule): matches = rule['matches'] cond_map = {} @@ -351,7 +351,7 @@ class Condition(object): self.allow_character = string.ascii_lowercase + string.digits + '_' self.ignore_character = ' \t' - def _get_token(self) -> Token: + def _get_token(self): while self.index < len(self.condstr): if self.condstr[self.index] in self.ignore_character: self.index += 1 @@ -392,7 +392,7 @@ class Condition(object): return Token(TOKEN_TYPE['eof']) - def pop_token(self) -> Token: + def pop_token(self): if self.back_tokens: return self.back_tokens.pop(0) try: @@ -400,10 +400,10 @@ class Condition(object): except IndexError: raise ParseException('invalid condition "%s"', self.condstr) - def push_token(self, token: Token): + def push_token(self, token): self.back_tokens.append(token) - def parse_var_expression(self) -> Result: + def parse_var_expression(self): """ v_exp := VARIABLE """ @@ -416,7 +416,7 @@ class Condition(object): return Result(name=token.name, value=token.value) - def parse_primary_expression(self) -> Result: + def parse_primary_expression(self): """ p_exp := (exp) """ @@ -435,7 +435,7 @@ class Condition(object): return r - def parse_not_expression(self) -> Result: + def parse_not_expression(self): """ n_exp := NOT n_exp | NOT p_exp """ @@ -452,7 +452,7 @@ class Condition(object): logger.debug('[*] {}'.format(r)) return r - def parse_and_expression(self) -> Result: + def parse_and_expression(self): """ and_exp := and_exp AND n_exp """ @@ -482,7 +482,7 @@ class Condition(object): return r1 - def parse_or_expression(self) -> Result: + def parse_or_expression(self): """ or_exp := or_exp OR and_exp """ @@ -512,13 +512,13 @@ class Condition(object): return r1 - def parse_expression(self) -> Result: + def parse_expression(self): """ exp := or_exp """ 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.symbol_table = symbol_table self.index = 0 diff --git a/oneforall.py b/oneforall.py index 08a8f42..17f8a06 100644 --- a/oneforall.py +++ b/oneforall.py @@ -223,7 +223,7 @@ class OneForAll(object): # Identify banner module if setting.enable_banner_identify: - identifier = banner.Identify() + identifier = banner.MultiIdentify() self.data = identifier.run(self.data) banner.save_db(self.domain, self.data)