Skip to content
This repository was archived by the owner on Nov 28, 2023. It is now read-only.

Commit 885dafc

Browse files
authored
Merge pull request #555 from wufeifei/develop
Released v2.0.0-alpha.2
2 parents 886aae9 + 2d979c5 commit 885dafc

30 files changed

+269
-446
lines changed

CHANGES.md

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Cobra Changelog
2+
===============
3+
4+
Here you can see the full list of changes between each Cobra release.
5+
6+
Version 2.0.0-alpha.2
7+
---------------------
8+
9+
Released on Sep 06 2017
10+
11+
- 修复上传非支持的后缀提示
12+
- 修复VirtualEnv环境下无法执行
13+
- 修复grep/find路径位置变动
14+
- 优化日志等级
15+
- 优化Docker下路径错误
16+
- 优化耗时计算
17+
- 其它细节优化和Bug修复
18+
19+
Version 2.0.0-alpha.1
20+
---------------------
21+
22+
Released on Sep 05 2017
23+
24+
内测正式版本
25+
26+
- 简化安装和使用成本
27+
- 增加CLI模式
28+
- 开源扫描规则

CONTRIBUTING.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
仔细描述问题的复现步骤,并提供对应的运行环境信息(Python版本、系统版本)
66

77
## 提交代码
8-
- Fork项目,切换到`develop`分支开发,或新建分支`feature-xxx`
8+
- Fork项目,切换到`develop`分支开发
99
- 按照PEP8格式
1010
- 所有代码都需要有对应的单元测试用例
1111
- 运行所有测试用例
12-
- 提交Pull Request
12+
- 提交Pull Request到`develop`分支
13+
- 等待测试稳定后合并到`master`分支

Dockerfile

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM ubuntu:xenial
2+
3+
COPY . /code/
4+
WORKDIR /code
5+
6+
RUN apt-get update && apt-get install -y python-pip curl \
7+
&& apt-get autoremove \
8+
&& apt-get clean \
9+
&& apt-get autoclean \
10+
&& pip install -r requirements.txt \
11+
&& cp config.template config
12+
13+
EXPOSE 5000
14+
CMD ["python", "cobra.py", "-H", "0.0.0.0", "-P", "5000"]

cobra.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
#!/usr/bin/python
2-
1+
#!/usr/bin/env python
32
# -*- coding: utf-8 -*-
3+
44
import re
55
import sys
66

77
from cobra import main
88

9+
910
if __name__ == '__main__':
1011
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
1112
sys.exit(main())
13+

cobra/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
def main():
3838
try:
3939
# arg parse
40-
t1 = time.clock()
40+
t1 = time.time()
4141
parser = argparse.ArgumentParser(prog=__title__, description=__introduction__, epilog=__epilog__, formatter_class=argparse.RawDescriptionHelpFormatter)
4242

4343
parser_group_scan = parser.add_argument_group('Scan')
@@ -80,7 +80,7 @@ def main():
8080
# API call CLI mode
8181
a_sid = args.sid
8282
cli.start(args.target, args.format, args.output, args.special_rules, a_sid)
83-
t2 = time.clock()
83+
t2 = time.time()
8484
logger.info('[INIT] Done! Consume Time:{ct}s'.format(ct=t2 - t1))
8585
except Exception as e:
8686
err_msg = unhandled_exception_message()

cobra/__version__.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
__issue_page__ = 'https://github.com/wufeifei/cobra/issues/new'
88
__python_version__ = sys.version.split()[0]
99
__platform__ = platform.platform()
10-
__version__ = '2.0.0-alpha'
10+
__version__ = '2.0.0-alpha.2'
1111
__author__ = 'Feei'
1212
__author_email__ = '[email protected]'
1313
__license__ = 'MIT License'
@@ -22,10 +22,10 @@
2222
2323
Cobra is a static code analysis system that automates the detecting vulnerabilities and security issue.""".format(version=__version__)
2424
__epilog__ = """Usage:
25-
{m} -t {td}
26-
{m} -t {td} -r cvi-190001,cvi-190002
27-
{m} -t {td} -f json -o /tmp/report.json
28-
{m} -t {tg} -f json -o [email protected]
29-
{m} -t {tg} -f json -o http://push.to.com/api
30-
sudo {m} -H 127.0.0.1 -P 80
31-
""".format(m='./cobra.py', td='tests/vulnerabilities', tg='https://github.com/ethicalhack3r/DVWA')
25+
python {m} -t {td}
26+
python {m} -t {td} -r cvi-190001,cvi-190002
27+
python {m} -t {td} -f json -o /tmp/report.json
28+
python {m} -t {tg} -f json -o [email protected]
29+
python {m} -t {tg} -f json -o http://push.to.com/api
30+
sudo python {m} -H 127.0.0.1 -P 80
31+
""".format(m='cobra.py', td='tests/vulnerabilities', tg='https://github.com/ethicalhack3r/DVWA')

cobra/api.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242

4343
q = queue.Queue()
4444
app = Flask(__name__, static_folder='templates/asset')
45+
running_host = '0.0.0.0'
46+
running_port = 5000
4547

4648

4749
def producer(task):
@@ -204,7 +206,7 @@ def post():
204206
code, result = 1001, {'sid': a_sid}
205207
return {'code': code, 'result': result}
206208
else:
207-
return {'code': 1002, 'msg': "This extension can't support!"}
209+
return {'code': 1002, 'result': "This extension can't support!"}
208210

209211

210212
class ResultData(Resource):
@@ -309,7 +311,8 @@ def summary():
309311
return render_template(template_name_or_list='index.html',
310312
key=key)
311313

312-
status_url = request.url_root + 'api/status'
314+
status_url = 'http://{host}:{port}/api/status'.format(host=running_host, port=running_port)
315+
logger.critical(status_url)
313316
post_data = {
314317
'key': key,
315318
'sid': a_sid,
@@ -481,6 +484,9 @@ def start(host, port, debug):
481484
i.start()
482485

483486
try:
487+
global running_port, running_host
488+
running_host = host if host != '0.0.0.0' else '127.0.0.1'
489+
running_port = port
484490
app.run(debug=debug, host=host, port=int(port), threaded=True, processes=1)
485491
except socket.error as v:
486492
if v.errno == errno.EACCES:

cobra/cve_parse.py cobra/cve.py

+37-11
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# -*- coding: utf-8 -*-
2+
23
"""
3-
cobra
4-
~~~~~
4+
CVE
5+
~~~
56
6-
Implements cobra main
7+
Implements CVE Rules Parser
78
89
:author: BlBana <[email protected]>
910
:homepage: https://github.com/wufeifei/cobra
@@ -241,9 +242,9 @@ def log_result(self):
241242
for cve_child in self._scan_result[module_]:
242243
cve_id = cve_child
243244
level = self._scan_result[module_][cve_id]
244-
logger.warning('Find the module ' + module_ + ' have ' + cve_id + ',level: ' + level)
245+
logger.debug('Find the module ' + module_ + ' have ' + cve_id + ',level: ' + level)
245246
count = len(self._scan_result[module_])
246-
logger.warning('The ' + module_ + ' module have ' + str(count) + ' CVE Vul(s)')
247+
logger.debug('The ' + module_ + ' module have ' + str(count) + ' CVE Vul(s)')
247248

248249
def get_scan_result(self):
249250
return self._scan_result
@@ -337,7 +338,7 @@ def store(results):
337338
for module_ in results[0]:
338339
for cve_id, cve_level in results[0][module_].items():
339340
cve_path = results[1]
340-
cve_vul = parse_math(cve_path, cve_id, cve_level, module_)
341+
cve_vul = parse_math(cve_path, cve_id, cve_level, module_, target_directory)
341342
cve_vuls.append(cve_vul)
342343
else:
343344
logger.debug('[SCAN] [STORE] Not found vulnerabilities on this rule!')
@@ -371,11 +372,12 @@ def scan_single(target_directory, cve_path):
371372
return cve.get_scan_result(), cve_path
372373

373374

374-
def parse_math(cve_path, cve_id, cve_level, module_):
375+
def parse_math(cve_path, cve_id, cve_level, module_, target_directory):
376+
flag = 0
377+
file_path = 'unkown'
375378
mr = VulnerabilityResult()
376379
module_name, module_version = module_.split(':')
377380
cvi = cve_path.lower().split('cvi-')[1][:6]
378-
rule_name = '引用了存在漏洞的三方组件'
379381
if cve_level == 'LOW':
380382
cve_level = 2
381383

@@ -385,13 +387,37 @@ def parse_math(cve_path, cve_id, cve_level, module_):
385387
elif cve_level == 'HIGH':
386388
cve_level = 8
387389

388-
mr.language = cve_id
390+
for root, dirs, filenames in os.walk(target_directory):
391+
for filename in filenames:
392+
if filename == 'pom.xml' and flag != 2:
393+
file_path = os.path.join(root, filename)
394+
file_path = file_path.replace(target_directory, '')
395+
flag = 1
396+
397+
elif filename == 'requirements.txt' and flag != 1:
398+
file_path = os.path.join(root, filename)
399+
file_path = file_path.replace(target_directory, '')
400+
flag = 2
401+
402+
if flag != 0:
403+
mr.file_path = file_path
404+
405+
else:
406+
mr.file_path = 'unkown'
407+
mr.language = '*'
389408
mr.id = cvi
390-
mr.rule_name = rule_name
409+
mr.rule_name = cve_id
391410
mr.level = cve_level
392-
mr.file_path = module_name
393411
mr.line_number = 1
412+
mr.analysis = 'Dependencies Matched(依赖匹配)'
394413
mr.code_content = module_name + ':' + module_version
414+
mr.solution = """
415+
三方依赖**""" + module_name + """:""" + module_version + """**存在CVE漏洞,CVE漏洞编号为: **""" + cve_id + """**
416+
## 安全风险
417+
418+
## 安全修复
419+
请根据对应厂商公告,及时更新三方依赖至安全版本
420+
"""
395421

396422
logger.debug('[CVE {i}] {r}:Find {n}:{v} have vul {c} and level is {l}'.format(i=mr.id, r=mr.rule_name,
397423
n=mr.file_path, v=mr.line_number,

cobra/dependencies.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# -*- coding: utf-8 -*-
22

33
"""
4-
cobra
5-
~~~~~
4+
dependencies
5+
~~~~~~~~~~~~
66
7-
Implements cobra main
7+
Implements Dependencies Check
88
99
:author: BlBana <[email protected]>
1010
:homepage: https://github.com/wufeifei/cobra

0 commit comments

Comments
 (0)