乐于分享
好东西不私藏

Gobra源代码安全审计

Gobra源代码安全审计

前言: 2025年各位师傅新年快乐!祝各位事业有成!

Gobra源代码安全审计

CLI模式

「Examples」

扫描一个文件夹的代码python cobra.py -t tests/vulnerabilities扫描一个Git项目代码python cobra.py -t https://github.com/FeeiCN/grw.git扫描一个文件夹,并将扫描结果导出为JSON文件python cobra.py -t tests/vulnerabilities -f json -o /tmp/report.json扫描一个Git项目,并将扫描结果JSON文件推送到API上python cobra.py -f json -o http://push.to.com/api -t https://github.com/FeeiCN/vc.git扫描一个Git项目,并将扫描结果JSON文件发送到邮箱中python cobra.py -f json -o feei@feei.cn -t https://github.com/FeeiCN/grw.git扫描一个文件夹代码的某两种漏洞python cobra.py -t tests/vulnerabilities -r cvi-190001,cvi-190002开启一个Cobra HTTP Server,然后可以使用API接口来添加扫描任务python cobra.py -H 127.0.0.1 -P 8888查看版本python cobra.py --version查看帮助python cobra.py --help扫描一个Git项目,扫描完毕自动删除缓存python cobra.py -t http://github.com/xx/xx.git -dels扫描gitlab全部项目,配置好config中private_token,gitlab_url,cobra_ippython git_projects.py自动生成Cobra扫描周报发送至指定邮箱,需要配置好config中的SMTP服务器信息python cobra.py -rp

「Help」

➜  cobra git:(master) ✗ python cobra.py --helpusage: cobra [-h] [-t <target>] [-f<format>] [-o<output>] [-r <rule_id>]             [-d] [-sid SID] [-H <host>] [-P<port>]    ,---.     |    |    ,---.|---.,---.,---.    |    |   ||   ||    ,---|    `---``---``---``    `---^ v2.0.0GitHub: https://github.com/WhaleShark-Team/cobraCobra isa static code analysis system that automates the detecting vulnerabilities and security issue.optional arguments:  -h, --help            show this help message andexitScan:  -t <target>, --target <target>file, folder, compress, or repository address  -f<format>, --format <format>                        vulnerability output format (formats: json, csv,                        xml)  -o<output>, --output <output>                        vulnerability output STREAM, FILE, HTTP API URL, MAIL  -r <rule_id>, --rule <rule_id>                        specifies rules e.g: CVI-100001,cvi-190001  -d, --debugopendebugmode  -sid SID, --sid SID   scan id(API)  -dels, --dels         del target directory True or False  -rp, --report         automation report Cobra dataRESTful:  -H <host>, --host <host>                        REST-JSON API Service Host  -P<port>, --port <port>                        REST-JSON API Service PortUsage:python cobra.py -t tests/vulnerabilitiespython cobra.py -t tests/vulnerabilities -r cvi-190001,cvi-190002python cobra.py -t tests/vulnerabilities -f json -o /tmp/report.jsonpython cobra.py -t https://github.com/ethicalhack3r/DVWA -f json -o feei@feei.cnpython cobra.py -t https://github.com/ethicalhack3r/DVWA -f json -o http://push.to.com/apipython cobra.py -t https://github.com/ethicalhack3r/DVWA -delspython cobra.py -H 127.0.0.1 -P8888

API接口

1. 添加扫描任务

请求接口接口:/api/add方法:POST类型:JSON

参数
类型
描述
例子
key
string
config文件中配置的secret_key
{“key”:”your_secret_key”}
target
string或list
需要扫描的git地址,默认为master分支,如需指定分支或tag可在git地址末尾加上:master
单个项目扫描:{“target”: “https://github.com/FeeiCN/dict.git:master”};多个项目扫描:{“target“: [“https://github.com/FeeiCN/dict.git:master“, “https://github.com/FeeiCN/autossh.git:master“]}
rule
string
仅扫描指定规则,以,分隔
{“rule”: “cvi-130003,cvi-130004”}

2. 查询扫描任务状态

请求接口接口:/api/status方法:POST类型:JSON

请求参数

参数
类型
描述
例子
key
string
config文件中配置的secret_key
{“key”:”your_secret_key”}
sid
string
扫描的任务ID

响应例子

{"code"1001# 状态码为1001则表示逻辑处理正常"result": {"msg""success"# 消息"not_finished"0# 未完成的项目数"report""http://127.0.0.1/?sid=ae3ea90pkoo5"# 扫描报告页"sid""ae3ea90pkoo5"# 扫描的任务ID"allow_deploy"true# 是否允许发布上线"statistic": { # 高中低危漏洞数量"high"5,"medium"18,"critical"0,"low"28      },"status""done"# 扫描状态"still_running": {}, # 正在扫描的项目"total_target_num"1# 扫描任务的项目总数  }}

完整的例子

启动HTTP服务python cobra.py -H 127.0.0.1 -P 8888添加扫描任务# 添加一条任务curl -H"Content-Type: application/json" -X POST -d '{"key":"your_secret_key""target":"https://github.com/FeeiCN/grw.git:master""rule""cvi-130003,cvi-130004"}' http://127.0.0.1:8888/api/add# 添加多条任务curl -H"Content-Type: application/json" -X POST -d '{"key":"your_secret_key""target":["https://github.com/WhaleShark-Team/cobra.git:master""https://github.com/FeeiCN/grw.git:master"]}' http://127.0.0.1:8888/api/add查询任务状态curl -H"Content-Type: application/json" -X POST -d '{"key":"your_secret_key","sid""a938e29vdse8"}' http://127.0.0.1:8888/api/statusWeb 报告页http://127.0.0.1:8888/?sid=afbe69p7dxvaWeb 指定时间段漏洞统计http://127.0.0.1:8888/report