From 061ef0bb2287d96a9d05338306c67b2042ed6060 Mon Sep 17 00:00:00 2001 From: BlBana <635373043@qq.com> Date: Tue, 27 Mar 2018 16:06:28 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=AF=B9sing=5Frule['language']=E8=BF=9B?= =?UTF-8?q?=E8=A1=8C=E4=BA=86=E5=B0=8F=E5=86=99=E8=BD=AC=E6=8D=A2=EF=BC=8C?= =?UTF-8?q?=E5=AF=B9CVE=E8=A7=84=E5=88=99=E6=8F=90=E5=8F=96=E8=BF=9B?= =?UTF-8?q?=E8=A1=8C=E4=BA=86=E9=9D=9ENone=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cobra/engine.py | 7 +++++-- cobra/rule.py | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/cobra/engine.py b/cobra/engine.py index 493769da..8882a3de 100644 --- a/cobra/engine.py +++ b/cobra/engine.py @@ -155,8 +155,11 @@ def scan(target_directory, a_sid=None, s_sid=None, special_rules=None, language= rules = r.rules(special_rules) find_vulnerabilities = [] - cve_vuls = scan_cve(target_directory) - find_vulnerabilities += cve_vuls + try: + cve_vuls = scan_cve(target_directory) + find_vulnerabilities += cve_vuls + except Exception: + logger.warning('[SCAN] [CVE] CVE rule is None') def store(result): if result is not None and isinstance(result, list) is True: diff --git a/cobra/rule.py b/cobra/rule.py index fc246ff5..f49f6c23 100644 --- a/cobra/rule.py +++ b/cobra/rule.py @@ -182,7 +182,7 @@ def rules(self, rules=None): if x.tag == 'name': rule_info['name'] = x.get('value') if x.tag == 'language': - rule_info['language'] = x.get('value') + rule_info['language'] = x.get('value').lower() if x.tag == 'status': rule_info['status'] = to_bool(x.get('value')) if x.tag == 'author': From c9571729b31c74332de1403801a1011185d1a05e Mon Sep 17 00:00:00 2001 From: BlBana <635373043@qq.com> Date: Wed, 28 Mar 2018 15:46:36 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E4=BA=86API=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=E4=B8=8B=E5=8D=95=E4=B8=AA=E6=96=87=E4=BB=B6=E6=89=AB?= =?UTF-8?q?=E6=8F=8F,=E6=9F=A5=E7=9C=8B=E6=8A=A5=E5=91=8A=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E8=8E=B7=E5=8F=96=E6=96=87=E4=BB=B6=E5=86=85=E5=AE=B9?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cobra/engine.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cobra/engine.py b/cobra/engine.py index 8882a3de..93f94335 100644 --- a/cobra/engine.py +++ b/cobra/engine.py @@ -156,8 +156,9 @@ def scan(target_directory, a_sid=None, s_sid=None, special_rules=None, language= find_vulnerabilities = [] try: - cve_vuls = scan_cve(target_directory) - find_vulnerabilities += cve_vuls + if special_rules is None or len(special_rules) == 0: + cve_vuls = scan_cve(target_directory) + find_vulnerabilities += cve_vuls except Exception: logger.warning('[SCAN] [CVE] CVE rule is None') @@ -168,6 +169,7 @@ def store(result): res.file_path = res.file_path.replace(target_directory, '') else: res.file_path = res.file_path.replace(os.path.dirname(target_directory), '') + find_vulnerabilities.append(res) else: logger.debug('[SCAN] [STORE] Not found vulnerabilities on this rule!') @@ -237,6 +239,8 @@ def store(result): if len(diff_rules) > 0: logger.info('[SCAN] Not Trigger Rules ({l}): {r}'.format(l=len(diff_rules), r=','.join(diff_rules))) + if os.path.isfile(target_directory): + target_directory = os.path.dirname(target_directory) # completed running data if s_sid is not None: Running(s_sid).data({ From ad23757d869ef716fd9534e5d73fcc140d8cf525 Mon Sep 17 00:00:00 2001 From: BlBana <635373043@qq.com> Date: Thu, 29 Mar 2018 11:26:22 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E4=BA=86API=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=E4=B8=8B=E6=97=A5=E5=BF=97=E8=A6=86=E7=9B=96=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cobra/log.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cobra/log.py b/cobra/log.py index 3b24c702..cd27fb22 100644 --- a/cobra/log.py +++ b/cobra/log.py @@ -16,7 +16,7 @@ import re import subprocess import logging -from logging import handlers +import cloghandler # stream handle # @@ -228,7 +228,7 @@ def format(self, record): logger.addHandler(sh) # file handle -fh = handlers.RotatingFileHandler(logfile, maxBytes=(1048576 * 5), backupCount=7) +fh = cloghandler.ConcurrentRotatingFileHandler(logfile, maxBytes=(1048576 * 5), backupCount=7) fh.setFormatter(fh_format) fh.setLevel(logging.DEBUG) logger.addHandler(fh) From 3d206f0192d0c6d94fd6b3dcdf432df398ad1976 Mon Sep 17 00:00:00 2001 From: BlBana <635373043@qq.com> Date: Thu, 29 Mar 2018 12:06:57 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E5=A4=9A?= =?UTF-8?q?=E8=BF=9B=E7=A8=8B=E5=86=99=E6=97=A5=E5=BF=97=E7=9A=84log?= =?UTF-8?q?=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 9aa6a39c..7e8ba0a5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,4 +6,5 @@ requests==2.6.2 pytest==3.0.6 pip==9.0.1 phply==1.0.0 -Werkzeug==0.11.9 \ No newline at end of file +Werkzeug==0.11.9 +ConcurrentLogHandler==0.9.1 \ No newline at end of file