Welcome to SeeCode Scanner’s documentation!¶
Table of Contents
What Is This?¶
seecode-scanner
是一款开源可独立运行的 SAST 代码检测工具,其支持命令行下对离线项目(本地项目)扫描;也可结合 SeeCode Audit 对线上(如:GitLab、GitHub)项目进行分布式扫描。
seecode-scanner
也是一个扫描引擎框架,您可以包装任意的扫描引擎集成到该工具中, seecode-scanner
默认集成了三个引擎: SonarScanner、RuleScanner、PluginScanner。通过编写不同的扫描模板,来满足您在不同场景下的代码检测需求。
主要功能特点:
引擎可扩展
扫描配置灵活
您可以创建不同的扫描模板,来定制您的扫描需求,如:项目依赖组件漏洞、检测代码质量等。
支持单机/多节点/Docker部署
单机:通过命令行手动触发扫描;
分布式:使用了 Celery 框架,进行分布式部署扫描;
Docker:您可以通过 Dockfile 一键来部署您的扫描工具,方便快捷。
可通过 FTP、AWS(TODO)等方式来存储扫描结果与日志。
依赖组件识别
工具使用 clocwalk 进行组件分析,默认支持:Java Maven、NodeJs、pip、Ruby 组件分析。
传输安全
支持与服务端通信内容 RSA 非对称加密,保证传输内容安全。
代码质量保证
- 单元测试覆盖率 70%;
- 功能测试完成:规则引擎、Sonar 引擎测试,详情请查看 tests 。
Note
seecode-scanner 是采用 python3 语言开发, 目前只支持 Linux 平台,建议您使用 CentOS 7 来安装部署。
1 使用说明¶
1.1 安装¶
您可以通过以下命令进行安装:
$ pip install seecode-scanner
或者直接使用 cli.py 脚本来运行:
$ cd seecode_scanner
$ python3 cli.py
1.2 配置¶
seecode_scanner.yml 是 seecode-scanner 的核心配置文件,默认路径为 /etc/seecode_scanner.yml 下, 其配置内容主要是与 SeeCode Audit 的服务端相关,本地测试使用可以不用配置。
$ vim /etc/seecode_scanner.yml
其内容如下,详细参数说明请参考 系统配置 章节
server:
domain: "http://seecode.com"
api_uri: "/api/v2/"
token: "dca58d563917b9325252f8a4b6c57e7331349052"
public_key_path:
private_key_path:
celery:
broker_url: ""
timezone: "Asia/Shanghai"
c_force_root: False
task_timeout: 7200
http:
timeout: 10
timeout_try: 3
failed_try: 3
try_status_code: 500, 502, 503
proxies:
http:
https:
socks5:
headers:
accept-encoding: "gzip, deflate"
distributed:
ftp:
host: "192.168.1.1"
port: 21
username: "seecode"
password: "test1234"
path: "/home/seecode/"
2 命令行操作¶
$ python cli.py
-------------------------------------------------------------------------------------------
____ U _____ u U _____ u ____ U ___ u ____ U _____ u
/ __"| u \| ___"|/ \| ___"|/ U /"___| \/"_ \/ | _"\ \| ___"|/
<\___ \/ | _|" | _|" \| | u | | | | /| | | | | _|"
u___) | | |___ | |___ | |/__ .-,_| |_| | U| |_| |\ | |___
|____/>> |_____| |_____| \____| \_)-\___/ |____/ u |_____|
)( (__) << >> << >> _// \\ \\ |||_ << >>
(__) (__) (__) (__) (__) (__)(__) (__) (__)_) (__) (__)
____ ____ _ _ _ _ _ U _____ u ____
/ __"| u U /"___| U /"\ u | \ |"| | \ |"| \| ___"|/ U | _"\ u
<\___ \/ \| | u \/ _ \/ <| \| |> <| \| |> | _|" \| |_) |/
u___) | | |/__ / ___ \ U| |\ |u U| |\ |u | |___ | _ <
|____/>> \____| /_/ \_\ |_| \_| |_| \_| |_____| |_| \_\
)( (__) _// \\ \\ >> || \\,-. || \\,-. << >> // \\_
(__) (__)(__) (__) (__) (_") (_/ (_") (_/ (__) (__) (__) (__)
SeeCode Audit seecode-scanner/1.0.0-20190903 xsseroot#gmail.com
-------------------------------------------------------------------------------------------
usage: seecode-scanner [-h] [-v {warn,debug,info,error}] [--test]
[--no-banner] [--version] [--upgrade] [--monitor]
[-c CONFIG] [--scan-template TEMPLATE]
[--scan-threads THREADS] [--scan-path PROJECT_PATH]
[--name PROJECT_NAME] [--result-file RESULT_FILE]
[--celery] [--celery-concurrency CELERY_CONCURRENCY]
[--celery-name CELERY_NAME]
optional arguments:
-h, --help show this help message and exit
-v {warn,debug,info,error}
Verbosity level, default: info.
--test, -t Test the status of all system services, default:
False.
--no-banner Do not display banner information, default: False.
--version Show current software version.
--upgrade Connect to the server for scanning configuration
upgrade, default: False.
--monitor SeeCode Scanner client heartbeat monitoring service,
default: False.
scan arguments:
-c CONFIG Project scan configuration file based on yaml format.
--scan-template TEMPLATE
Scan the name of the template, default: normal
--scan-threads THREADS
The number of threads when the engine scans, default:
20.
--scan-path PROJECT_PATH, -p PROJECT_PATH
The absolute path of the item to be scanned.
--name PROJECT_NAME, -n PROJECT_NAME
The name of the project to scan.
--result-file RESULT_FILE, -o RESULT_FILE
Scan the path saved by the report.
task arguments:
--celery Start celery's work tasks.
--celery-concurrency CELERY_CONCURRENCY
Number of child processes processing the queue,
default: 4
--celery-name CELERY_NAME
Set custom hostname, default: sca-1
2.1 基本配置¶
--no-banner
¶
用于设置是否显示 banner 的开关。布尔型参数,默认为False。
2.2 扫描配置¶
--scan-template
¶
通过命令行来设置扫描模板,输入范围必须是在 profiles 文件夹下的 xml 文件名。系统默认包含三个模板:default、normal、component_scan。
--scan-threads
¶
通过命令行来设置扫描使用的线程(协成)数,默认为 20 。
--scan-path
¶
扫描本地项目的项目路径,参数必须结合 –name 参数一起使用。
--result-file
¶
用于设置扫描结果的文件名称,其内容默认为 json 格式。
2.3 Celery 配置¶
--celery-concurrency
¶
该参数等同于 celery 中的 -c 参数。整型参数,默认为 4。
--celery-name
¶
该参数等同于 celery 中的 -n 参数。默认值为 sca1。
捐赠¶
- BTC 地址:18F4VFDX2MCEXod7zjUF8NepUdAspEcJR8
- ETH 地址:0xB3Bc55F4AAa8E87D3675B547e31d3eEbb585175c
- HT 地址:0x952b4cd9f18126987fdbfab55e1ea72c5ae72e16
1 系统配置¶
1.1 Server¶
该节点主要是 SeeCode Audit 服务端的相关配置信息,包括域名、认证Token、公钥路径、私钥路径。其配置内容如下:
server:
domain: "http://seecode.com"
api_uri: "/api/v2/"
token: "dca58d563917b9325252f8a*********"
public_key_path:
private_key_path:
1.1.1 domain¶
SeeCode Audit 服务端的域名,如:http://seecode.example.com。
1.1.2 api_uri¶
SeeCode Audit 中 API 接口的 URI,默认为 /api/v2/
1.1.3 token¶
SeeCode Audit 服务端的,认证 Token。
1.1.4 public_key_path¶
与 SeeCode Audit 服务端通信使用人 RSA 公钥文件地址, 如:/home/seecode/public.pem。
1.1.5 private_key_path¶
与 SeeCode Audit 服务端通信使用人 RSA 私钥文件地址,如:/home/seecode/private.pem。
1.2 Celery¶
该节点是 Celery 配置信息,包括 border_url, timezone、c_force_root、task_timeout:
celery:
broker_url: ""
timezone: "Asia/Shanghai"
c_force_root: False
task_timeout: 7200
1.2.1 broker_url¶
Celery Broker URL 地址,可以使用:Redis、RabbitMQR。
1.2.2 timezone¶
Celery 中的时区,默认为:”Asia/Shanghai”。
1.2.3 c_force_root¶
Celery 的扫描任务是发运行使用 Root 账号运行, 默认为 False。
1.2.4 task_timeout¶
Celery 的任务超时时间,单位为秒。默认 7200 秒。
1.3 HTTP¶
该节点主要是 HTTP 相关参数设置,包括:超时时间、超时尝试、代理、请求头。
http:
timeout: 10
timeout_try: 3
failed_try: 3
try_status_code: 500, 502, 503
proxies:
http:
https:
socks5:
headers:
accept-encoding: "gzip, deflate"
1.3.1 timeout¶
访问 SeeCode Audit 服务端的超时等待的时间(requests.exceptions.Timeout) ,默认为 10 秒。
1.3.2 timeout_try¶
访问 SeeCode Audit 服务端超时后尝试重新尝试连接的次数,默认为 3 次。
1.3.3 failed_try¶
访问 SeeCode Audit 服务端发生失败(可以设置状态码)后尝试重新尝试连接的次数,默认为 3 次。
1.3.4 try_status_code¶
设置失败的状态码(范围非200),默认为:500、502、503。
1.3.5 proxies¶
通过代理来访问 SeeCode Audit 服务。
http¶
http 协议的代理地址,如:http://192.168.1.1:8080
https¶
https 协议的代理地址,如:https://192.168.1.1:8080
socks5¶
socks5 协议的代理地址,如:socks5://192.168.1.1:8080
1.3.6 headers¶
可以为 HTTP 中添加自定义请求头,如:accept-encoding、user-agent。
1.4 Distributed¶
该节点是为了将扫描任务日志、扫描结果存储在一个公共存储区域。如:FTP、AWS。
distributed:
ftp:
host: "192.168.1.1"
port: 21
username: "seecode"
password: "test1234"
path: "/home/seecode/"
1.4.1 FTP¶
host¶
FTP 服务的域名或者 IP 地址, 如:192.168.1.10。
port¶
FTP 服务的端口, 默认为 21。
username¶
FTP 服务的用户名,如:seecode。
password¶
FTP 用户的认证密码。
path¶
FTP 服务的存储路径,默认为:/home/seecode/。
1.4.2 AWS (TODO)¶
该配置暂时未实现。
2 扫描模板¶
扫描模板主要是通过 SeeCode Audit 系统来自动生成,并通过 seecode-scanner --upgrade
命令进行升级,
您也可以手动编辑扫描模板来满足自己的扫描需求。
工具默认自带了:SonarScanner、RuleScanner、PluginScanner 三种扫描引擎。针对不同的扫描引擎有不同的参数设置,下面会逐一说明。
seecode-scanner 使用 xml 文件来编写扫描模板,其主要包含 config 与 engines 两个节点,描模板的内容大致如下:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<template version="1.0.0">
<config>
<name>normal</name>
<version>6.0</version>
<exclude_dir>.git/,bin/,node_modules/,assets/,static/,.svn/</exclude_dir>
<exclude_ext>.jpg,.jpeg,.png,.bmp,.gif,.ico,.cur,</exclude_ext>
<exclude_file></exclude_file>
</config>
<engines>
<engine></engine>
</engines>
</template>
2.2 config 子节点¶
name
¶
模板名称,命名规则建议使用小写英文字母或下划线。如系统自带的:default、normal、component_scan。
version
¶
模板的版本,用于区分同一个模板不同时间的配置,版本号使用浮点数默认保留一位小数,如:2.1。
exclude_dir
¶
扫描时不包含的路径,如:.git/,.svn/。多个路径使用英文逗号(,)分隔。
exclude_ext
¶
扫描时不包含的文件后缀,如:readme.md。多个路径使用英文逗号(,)分隔。
exclude_file
¶
扫描时不包含的文件,如:.log,.txt。多个路径使用英文逗号(,)分隔。
2.3 engine 子节点¶
engine 是 engines 下的子节点,engines 必须包含一个或多个 engine 节点。
属性: |
---|
parameters
¶
扫描引擎的全局参数设定如下, 这里用了 SonarScanner 引擎的全局参数进行说明:
<parameters>
<!-- SonarQube 服务端的认证 Token -->
<item name="API_TOKEN">80828d9343317970f*********</item>
<!-- SonarQube 服务端的 API 地址 -->
<item name="API_DOMAIN">http://sonar7.example.com</item>
<!-- sonar-scanner 工具路径 -->
<item name="SONAR_SCANNER_PATH">/usr/bin/sonar-scanner</item>
<!-- SonarScanner 引擎的执行超时时间,单位秒 -->
<item name="ENGINE_TIMEOUT">1200</item>
<!-- SonarScanner 连接 SonarQube 服务端的超时时间,单位秒 -->
<item name="HTTP_TIMEOUT">10</item>
<!-- SonarScanner 连接 SonarQube 服务端的超时尝试次数 -->
<item name="HTTP_TIMEOUT_RETRY">3</item>
<!-- SonarScanner 连接 SonarQube 服务端的非超时失败尝试次数 -->
<item name="HTTP_FAILED_RETRY">3</item>
<!-- sonar 扫描的配置文件, 全局参数参数
{{project_key}}: 项目的key
{{project_name}}:项目名称
{{sonar_host}}:sonarqube 地址,使用 API_DOMAIN 替换
{{sonar_login}}:sonarqube token,使用 API_TOKEN 替换
-->
<item name="SONAR_PROJECT_PROPERTIES">sonar.projectKey={{project_key}}
sonar.projectName={{project_name}}
sonar.projectVersion=1.0
sonar.sources=.
sonar.sourceEncoding=UTF-8
sonar.exclusions=**/node_modules/**/*.*,
sonar.host.url={{sonar_host}}
sonar.login={{sonar_login}}
sonar.java.binaries=.
</item>
</parameters>
item
- name
- [属性]参数名称,建议使用大写字母。
- item 内容
- 参数值。
component
¶
用于组件漏洞检测的扫描规则,默认只支持 RuleScanner,其中 SonarScanner、PuginScanner 引擎没有实现组件规则检测。
RuleScanner 引擎
<component>
<item id="7582">
<name>Apache Solr 远程代码执行(CVE-2019-0192)</name>
<key>java:apache-solr-cve-2019-0192</key>
<revision>0.43</revision>
<risk id="3">中危</risk>
<category>Vulnerability</category>
<match_type>name</match_type>
<match_content><![CDATA[solr-solrj]]></match_content>
<match_regex flag="I"><![CDATA[(5\.[0-5]{1}) ### 5.0-5.5
(5\.2\.1) ### 5.0-5.5
(5\.3\.[1-2]{1}) ### 5.3.1 - 5.3.2
(5\.4\.1) ### 5.4.1
(5\.5\.[1-5]{1}) ### 5.5.1 - 5.5.5
(6\.[0-6]{1})
(6\.0\.1)
(6\.1\.1)
(6\.2\.1)
(6\.4\.[1-2]{1})
(6\.5\.1)
(6\.6\.[1-5]{1})]]>
</match_regex>
</item>
</component>
item
- id
- [属性]为整数型,默认为 SeeCode Audit 中的规则 ID。
- name
- 规则名称,如:Apache Solr 远程代码执行(CVE-2019-0192)。
- key
- 规则 Key 使用小写的英文字母,其主要有两部分组成,并使用英文的冒号(:)分割,第一部分代表组件使用的语言,第二部分代表组件相关信息。
- revision
- 规则修订的版本号,默认使用浮点型并保留两位小数。
- risk
- id 是在 SeeCode Audit 中对应的编号,其为 risk 节点的一个属性。
- 内容为风险描述,其范围为:严重、高危、中危、低危、信息五个级别。
- category
- 规则所属类型,分为三种:Code Smell、Bug、Vulnerability,对应 sonarqube 中的类型(不区分大小写)。
- match_type
- 匹配类分为两种,分别为:name、groupId。
- match_content
- 匹配内容用于匹配组件的名称,必须是字符中格式,区分大小写。
- match_regex
- 匹配组件版本的正则表达式。
- flag 用于正则的标志位,可选范围:I(忽略大小写)、M(多行匹配)、I|M(忽略大小写、多行匹配)。
blacklist
¶
黑名单是定义扫描规则用于发现漏洞或者安全风险。SonarScanner 引擎比较特殊,它不能设置任何(组件、黑名单、白名单)规则,如若需要定制扫描参数必须修改 扫描引擎全局参数 中的 SONAR_PROJECT_PROPERTIES 。
(1) RuleScanner 引擎
<blacklist>
<item id="7583">
<name>密码硬编码</name>
<key>common:password-hard</key>
<revision>0.27</revision>
<risk id="3">中危</risk>
<category>Vulnerability</category>
<match_type>content</match_type>
<file_ext>.java</file_ext>
<match_regex flag="I"><![CDATA[PARAM_NAME_password\s+=\s+['"].+['"]]]></match_regex>
</item>
</blacklist>
item
- id 略 ,同上 component中id
- name 略 ,同上 component中name
- key 略 ,同上 component中key
- revision 略 ,同上 component中revision
- risk 略 ,同上 component中risk
- category 略,同上 component中category
- match_type
- 匹配类分为三种,分别是:dir、file、content。
- file_ext ※
- 该节点必须当 match_type 内容为 content 时才会出现, 多个文件后缀需要使用英文的逗号(,)分隔, 如:.java,.jsp。
- match_regex
- ↑ 同上 component中match_regex。
(2) PluginScanner 引擎
<blacklist>
<item id="7583">
<name>反射型XSS检测</name>
<key>java:reflective-xss</key>
<revision>0.03</revision>
<risk id="4">低危</risk>
<category id="3">Vulnerability</category>
<module>seecode_scanner.plugins.blacklist.reflective_xss_java</module>
<script>plugins/whitelist/reflective_xss_java.py</script>
</item>
</blacklist>
item
- id 略
- name 略
- key 略
- revision 略
- risk 略
- category 略
- module
- 插件所在的 seecode_scanner 的所在引用位置。
- script
- 插件的 py 脚本文件路径,路径为相对路径。
whitelist
¶
白名单检测规则用于已经识别出的安全分析,进行的二次分析,主要用于减少误报。
(1) RuleScanner 引擎
<whitelist>
<item id="7580">
<name>误报密码参数排除规则</name>
<key>common:password-exclude</key>
<revision>0.27</revision>
<risk id="4">信息</risk>
<category>BUG</category>
<match_type>content</match_type>
<match_regex flag=""><![CDATA[PARAM_NAME_PASSWORD\s+=\s+['"].+['"]]]></match_regex>
</item>
</whitelist>
item
- id 略 ,同上 component中id
- name 略 ,同上 component中name
- key 略 ,同上 component中key
- revision 略 ,同上 component中revision
- risk 略 ,同上 component中risk
- category 略,同上 component中category
- match_type
- 匹配类分为三种,分别是:dir、file、content。
- file_ext ※
- 该节点必须当 match_type 内容为 content 时才会出现, 多个文件后缀需要使用英文的逗号(,)分隔, 如:.java,.jsp。
- match_regex
- ↑ 同上 component中match_regex。
(2)PluginScanner 引擎
<whitelist>
<item id="7583">
<name>跳过测试文件与目录</name>
<key>java:pass-test-file-dir</key>
<revision>0.03</revision>
<risk id="5">信息</risk>
<category id="3">Vulnerability</category>
<module>seecode_scanner.plugins.whitelist.pass_file_dir</module>
<script>plugins/whitelist/pass_file_dir.py</script>
</item>
</whitelist>
item
- id 略
- name 略
- key 略
- revision 略
- risk 略
- category 略
- module
- 插件所在的 seecode_scanner 的所在引用位置。
- script
- 插件的 py 脚本文件路径,路径为相对路径。
3 项目配置¶
项目扫描配置,主要是使用 yaml 文件来编写一个配置文件,方便 seecode-scanner 的 -c 参数来执行扫描。其可以省去繁琐的命令行参数和 Celery 的集成,更方便测试时使用。
3.1 配置格式¶
其内容格式如下, 这一个线上(online)项目的扫描配置:
scan:
# 任务ID
task_id: 9527
# 扫描模板
template: "normal"
# 扫描线程数
threads: 20
# 日志
log_level: "debug"
# 工作目录
work_dir: "/data/seecode/"
# 项目 git 地址
project_ssh: "git@github.com:seecode-audit/vuln_java.git"
# web
project_web: "https://github.com/seecode-audit/vuln_java"
# 项目名称
project_name: "vuln_java"
# 分支名称
project_branch: "master"
# 项目类型: online, offline
project_type: "online"
# 上传方式: local, ftp, aws
project_storage_type: "local"
# 文件原始名称
project_file_origin_name: ""
# 文件MD5
project_file_hash: ""
# 分组名称
group_name: "seecode-audit"
# 分组key
group_key: "seecode-audit"
# 取证开始行偏移
evidence_start_line_offset: -1
# 取证行数
evidence_count: 5
# 强制同步线上代码
force_sync_code: True
# 同步漏洞到 server 需要与 task_id 参数一起使用
sync_vuln_to_server: True
# 结果格式
result_format: "json"
# 结果文件
result_file: "9527.json"
线下(offline)项目的扫描配置内容大致如下:
scan:
task_id: 184
template: "normal"
log_level: "debug"
work_dir: "/data/seecode/"
project_name: "xxxxx"
project_branch: "master"
project_ssh: "ftp://192.168.1.100:21/home/seecode/projects/XIANXIAXIANGMUZU/1566816638.zip"
project_web: ""
project_file_origin_name: "xxxxx.zip"
project_file_hash: "1b6d61ee077eb0b9c12465e24b388033"
group_name: "线下项目组"
group_key: "xianxiaxiangmuzu"
project_type: "offline"
project_storage_type: "ftp"
evidence_start_line_offset: -1
evidence_count: 5
result_file: "184.json"
sync_vuln_to_server: True
force_sync_code: False
3.2 参数说明¶
scan 是 yaml 的主节点,默认配置文件中仅存在这一个主节点。
task_id
¶
扫描任务的 id,该 id 来自 SeeCode Audit 系统中下发的扫描任务 id,一般形式为整型。
template
¶
扫描模板名称,系统默认自带了三个扫描模板: default、normal、component_scan。
- default 扫描模板包含了:RuleScanner、PluginScanner 两个扫描引擎
- normal 扫描模板包含了:RuleScanner、PluginScanner、SonarScanner 三个扫描引擎
- component_scan 扫描模板包含了:RuleScanner 一个扫描引擎
threads
¶
扫描线程数,默认值为 20 个。
log_level
¶
扫描任务的日志级别,其范围:info、debug、error。
work_dir
¶
扫描的工作目录,默认目录为: “/data/seecode/”。
project_ssh
¶
项目 git 地址,如: “git@github.com/seecode-audit/vuln_java.git” 或 “https://github.com/seecode-audit/vuln_java.git”。
project_web
¶
项目的 http 访问地址, 如: “https://github.com/seecode-audit/vuln_java”。
project_name
¶
项目名称,如: “vuln_java”。
project_branch
¶
分支名称,如: “master”。
project_type
¶
项目类型,其范围分为: online、offline。
- online 为线上项目,其必须包含 project_ssh 参数,用于使用 git 来拉取源代码
- offline 为线下项目,其必须包含 project_ssh 参数,用于下载压缩文件,系统默认只支持 zip 压缩
project_storage_type
¶
离线文件的存储方式,其范围: local, ftp, aws
- local 代码文件在本地存储
- ftp 需要使用 ftp 进行下载
- aws 需要使用 aws 进行下载
project_file_origin_name
¶
离线文件原始名称, 当 project_type 类型为 offline 时有效。
project_file_hash
¶
离线文件文件 MD5, 当 project_type 类型为 offline 时有效。
group_name
¶
项目分组名称,如: “线下项目组”。
group_key
¶
分组 key,如: “xianxiaxiangmuzu”。
evidence_start_line_offset
¶
取证开始行偏移,默认为 -1,问题行的上一行。
evidence_count
¶
取证总行数,默认 5。
force_sync_code
¶
强制同步线上代码,布尔型参数,默认为 True。
sync_vuln_to_server
¶
同步漏洞到 server 需要与 task_id 参数一起使用,布尔型参数,默认为 True。
result_format
¶
结果格式,默认 “json” 格式(目前只支持 json )。
result_file
¶
结果文件,默认为 task_id 作为结果的文件名称,如: “453.json”。
4 扫描结果¶
扫描结果目前只支持 json 格式,内容格式如下:
{
"749c86838b5d24a64ed2b40fb18f5af4": {
"rule_key": "java:apache-solr-cve-2019-0192",
"risk_id": 3,
"category": "vulnerability",
"title": "Apache Solr \u8fdc\u7a0b\u4ee3\u7801\u6267\u884c(CVE-2019-0192)",
"file": "pom.xml",
"author": "MyKings",
"author_email": "xsseroot@gmail.com",
"hash": "d3f491ad09eaa9f7923edd2e041099e81171eb38",
"start_line": 37,
"end_line": 38,
"report": "https://github.com/seecode-audit/vuln_java/blob/master/pom.xml#L37",
"code_example": " <artifactId>solr-solrj</artifactId>\n <version>5.5.3</version>\n </dependency>\n <dependency>\n <groupId>org.apache.shiro</groupId>\n",
"is_false_positive": false,
"whitelist_rule_id": "",
"evidence_content": "5.5.3",
"engine": 2
}
4.1 参数说明¶
rule_key
¶
检测规则的 key。
risk_id
¶
安全风险对应的ID
category
¶
风险类型,默认三种:Code Smell、Bug、Vulnerability(不区分大小写)。
title
¶
安全风险的标题。
file
¶
存在安全风险的文件路径,路径为绝对路径。
author
¶
文件最后的修改作者(必须为线上项目才会存在这个内容)。
author_email
¶
文件最后的修改作者邮箱(必须为线上项目才会存在这个内容)。
hash
¶
文件最后的 commit id(必须为线上项目才会存在这个内容)。
start_line
¶
问题存在的开始行。
end_line
¶
问题存在的结束行。
report
¶
扫描的文件报告 URL。
- 如果为 SonarScanner 引擎,报告地址为 SonarQube 中的文件地址。
- 如果为线上项目,报告地址为 gitlab 或 github 的文件地址。
code_example
¶
取证的代码片段,默认为 6 行。
evidence_content
¶
取证匹配到的内容。
is_false_positive
¶
是否为误报。
whitelist_rule_id
¶
误报白名单检测的规则ID。
1 安装配置¶
1.1 安装¶
环境初始化¶
初始化系统环境与安装依赖,建议单独创建一个账号来运行扫描引擎。
$ sudo yum install -y perl perl-Digest-MD5 unzip git
安装 python 3.6 环境
$ sudo yum install -y centos-release-scl rh-python36 && scl enable rh-python36 bash
$ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py && python get-pip.py
$ echo "export PYTHONIOENCODING=utf-8" >> ~/.bashrc && source ~/.bashrc
sonarscanner 安装¶
sonarscanner 官方下载地址: https://docs.sonarqube.org/latest/analysis/scan/sonarscanner/ , 下载 sonarscanner 并解压到 /usr/local/ 目录下,为 sonarscanner 工具创建一个软链接到 /usr/bin/sonar-scanner。
$ wget https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.0.0.1744-linux.zip
$ sudo unzip sonar-scanner-cli-4.0.0.1744-linux.zip -d /usr/local/ && \
ln -s /usr/local/sonar-scanner-4.0.0.1744-linux/bin/sonar-scanner /usr/bin/sonar-scanner
cloc 安装¶
使用 yum 进行安装,如果 yum 不能安装可以手动下载安装:
$ sudo yum install -y cloc
下载 cloc-1.82 安装:
$ sudo wget https://github.com/AlDanial/cloc/releases/download/1.82/cloc-1.82.pl && \
cp cloc-1.82.pl /usr/bin/cloc
账号配置¶
创建 seecode 账号, 并设置密码:
$ sudo useradd -m -s /bin/bash seecode && passwd seecode
登录 seecode 账户,创建 SSH 密钥对,得到 /home/seecode/.ssh/id_rsa 私钥;/home/seecode/.ssh/id_rsa.pub 公钥两个文件。
$ su - seecode
$ mkdir ~/.ssh && ssh-keygen
配置 gitlab 中 “个人资料” -> “SSH 密钥”, 将 id_rsa.pub 内容添加到配置中。
$ cat /home/seecode/.ssh/id_rsa.pub
1.2 升级¶
$ seecode-scanner --upgrade
---------------------------------------------------------------------------------------------------
____ U _____ u U _____ u ____ U ___ u ____ U _____ u
/ __"| u \| ___"|/ \| ___"|/ U /"___| \/"_ \/ | _"\ \| ___"|/
<\___ \/ | _|" | _|" \| | u | | | | /| | | | | _|"
u___) | | |___ | |___ | |/__ .-,_| |_| | U| |_| |\ | |___
|____/>> |_____| |_____| \____| \_)-\___/ |____/ u |_____|
)( (__) << >> << >> _// \\ \\ |||_ << >>
(__) (__) (__) (__) (__) (__)(__) (__) (__)_) (__) (__)
____ ____ _ _ _ _ _ U _____ u ____
/ __"| u U /"___| U /"\ u | \ |"| | \ |"| \| ___"|/ U | _"\ u
<\___ \/ \| | u \/ _ \/ <| \| |> <| \| |> | _|" \| |_) |/
u___) | | |/__ / ___ \ U| |\ |u U| |\ |u | |___ | _ <
|____/>> \____| /_/ \_\ |_| \_| |_| \_| |_____| |_| \_\
)( (__) _// \\ \\ >> || \\,-. || \\,-. << >> // \\_
(__) (__)(__) (__) (__) (_") (_/ (_") (_/ (__) (__) (__) (__)
SeeCode Audit seecode-scanner/1.0.0-20190903 xsseroot#gmail.com
---------------------------------------------------------------------------------------------------
[15:18:36] [INFO] Check the latest version...
[15:18:36] [INFO] [+] The server has opened the encrypted communication.
[15:18:36] [INFO] The latest version of: [v1.85.14]
[15:18:36] [INFO] Initialize the upgrade environment and create an upgrade directory...
[15:18:36] [INFO] Start upgrading, check if the local version is consistent with the server version...
[15:18:36] [INFO] current version: [v1.1.1], new version: [v1.85.14].
[15:18:36] [INFO] Start downloading the upgrade package...
[15:18:36] [INFO] Start decompressing the encryption upgrade package...
[15:18:37] [INFO] Unzip the encryption upgrade package to complete.
[15:18:37] [INFO] Start decompressing the decryption upgrade package...
[15:18:37] [INFO] Decompression and decryption upgrade package completed
[15:18:37] [INFO] Start syncing scan templates...
[15:18:37] [INFO] Synchronous scan template completion.
[15:18:37] [INFO] Start syncing whitelist plugin...
[15:18:37] [INFO] Synchronous whitelist plugin completed.
[15:18:37] [INFO] Start updating the current version to v1.85.14.
[15:18:37] [INFO] Upgrade completed, current version: v1.85.14
1.3 采集¶
1.4 检测配置¶
$ seecode-scanner -t
---------------------------------------------------------------------------------------------------
____ U _____ u U _____ u ____ U ___ u ____ U _____ u
/ __"| u \| ___"|/ \| ___"|/ U /"___| \/"_ \/ | _"\ \| ___"|/
<\___ \/ | _|" | _|" \| | u | | | | /| | | | | _|"
u___) | | |___ | |___ | |/__ .-,_| |_| | U| |_| |\ | |___
|____/>> |_____| |_____| \____| \_)-\___/ |____/ u |_____|
)( (__) << >> << >> _// \\ \\ |||_ << >>
(__) (__) (__) (__) (__) (__)(__) (__) (__)_) (__) (__)
____ ____ _ _ _ _ _ U _____ u ____
/ __"| u U /"___| U /"\ u | \ |"| | \ |"| \| ___"|/ U | _"\ u
<\___ \/ \| | u \/ _ \/ <| \| |> <| \| |> | _|" \| |_) |/
u___) | | |/__ / ___ \ U| |\ |u U| |\ |u | |___ | _ <
|____/>> \____| /_/ \_\ |_| \_| |_| \_| |_____| |_| \_\
)( (__) _// \\ \\ >> || \\,-. || \\,-. << >> // \\_
(__) (__)(__) (__) (__) (_") (_/ (_") (_/ (__) (__) (__) (__)
SeeCode Audit seecode-scanner/1.0.0-20190911 xsseroot#gmail.com
---------------------------------------------------------------------------------------------------
[07:24:03] [INFO] [CORE] Start testing whether the core file of seecode-scanner exists...
[07:24:03] [ERROR] [-] "/etc/seecode_scanner.yml" file not found.
[07:24:03] [INFO] [+] Discover "/data/seecode/" directory.
[07:24:03] [INFO] [SERVER] Start detecting service list files...
[07:24:03] [ERROR] [-] "/usr/local/etc/seecode/conf/services.json" file not found.
[07:24:03] [INFO] [SERVER] Start detecting core files...
[07:24:03] [ERROR] [-] "monitor_url" is not set, the current content is: None.
[07:24:03] [ERROR] [-] "upgrade_url" is not set, the current content is: None.
[07:24:03] [ERROR] [-] "task_url" is not set, the current content is: None.
[07:24:03] [INFO] [SCAN] Start testing whether the scan template of seecode-scanner exists...
[07:24:03] [INFO] [+] Found "/seecode_scanner/profiles/normal.xml" file.
[07:24:03] [INFO] [+] Found "/seecode_scanner/profiles/component_scan.xml" file.
[07:24:03] [INFO] [+] Found "/seecode_scanner/profiles/default.xml" file.
[07:24:03] [INFO] [ENGINE] Start detecting the scan engine...
[07:24:03] [INFO] [+] Found the "sonar-scanner" tool with the path "/usr/bin/sonar-scanner"
========================================================================================================================
NAME || STATUS || VERSION || DESCRIPTION
========================================================================================================================
Core | MISSING | - | -
------------------------------------------------------------------------------------------------------------------------
Server | MISSING | - | -
------------------------------------------------------------------------------------------------------------------------
Scan Template | FOUND | - | /seecode_scanner/profiles/normal.xml
Scan Template | FOUND | - | /seecode_scanner/profiles/component_scan.xml
Scan Template | FOUND | - | /seecode_scanner/profiles/default.xml
------------------------------------------------------------------------------------------------------------------------
Engine | FOUND | - | seecode_scanner.lib.engines.sonarscanner (/usr/bin/sonar-scanner)
Engine | FOUND | - | seecode_scanner.lib.engines.rulescanner
Engine | FOUND | - | seecode_scanner.lib.engines.pluginscanner
------------------------------------------------------------------------------------------------------------------------
2 Docker 部署¶
使用 Docker 配置时,请先配置 seecode_scanner.yml 文件,配置说明请参考 系统配置 。
2.1 创建镜像¶
通过如下命令来创建一个 seecode-scanner 镜像,使用 docker images 来查看镜像是否创建成功。
$ docker build -t seecode-scanner .
2.2 运行容器¶
创建容器是,请确保 seecode_scanner.yml 中配置的服务可用。
以交互的方式创建一个 sca1 容器,并设置 shell 为 bash。
$ docker run -it --name sca1 seecode-scanner /bin/bash
以后台服务方式创建一个 sca1 容器,默认启动 supervisord。
$ docker run -d --name sca1 seecode-scanner
以交互的方式进入到 sca1 容器中。
$ docker exec -it sca1 sh
1 本地项目¶
扫描本地项目是根据现有的扫描规则模板对本地项目的代码安全检测,检测结果可保存为 json 文件,可供第三方系统调用使用。
下面是通过命令行方式对本地的 vuln_java 目录进行代码扫描,使用了默认 (default.xml) 的扫描模板。
$ python cli.py --scan-path ./tmp/vuln_java --name vuln_java -o 1.json
---------------------------------------------------------------------------------------------------
____ U _____ u U _____ u ____ U ___ u ____ U _____ u
/ __"| u \| ___"|/ \| ___"|/ U /"___| \/"_ \/ | _"\ \| ___"|/
<\___ \/ | _|" | _|" \| | u | | | | /| | | | | _|"
u___) | | |___ | |___ | |/__ .-,_| |_| | U| |_| |\ | |___
|____/>> |_____| |_____| \____| \_)-\___/ |____/ u |_____|
)( (__) << >> << >> _// \\ \\ |||_ << >>
(__) (__) (__) (__) (__) (__)(__) (__) (__)_) (__) (__)
____ ____ _ _ _ _ _ U _____ u ____
/ __"| u U /"___| U /"\ u | \ |"| | \ |"| \| ___"|/ U | _"\ u
<\___ \/ \| | u \/ _ \/ <| \| |> <| \| |> | _|" \| |_) |/
u___) | | |/__ / ___ \ U| |\ |u U| |\ |u | |___ | _ <
|____/>> \____| /_/ \_\ |_| \_| |_| \_| |_____| |_| \_\
)( (__) _// \\ \\ >> || \\,-. || \\,-. << >> // \\_
(__) (__)(__) (__) (__) (_") (_/ (_") (_/ (__) (__) (__) (__)
SeeCode Audit seecode-scanner/1.0.0-20190911 xsseroot#gmail.com
---------------------------------------------------------------------------------------------------
[02:36:13] [INFO] [ScanProject] Start syncing project code into the scan directory...
[02:36:13] [INFO] [ScanProject] Synchronization project code completion.
[02:36:13] [INFO] [ScanProject] Start executing exclusion rules...
[02:36:13] [INFO] [ScanProject] Exclusion rule execution completed.
[02:36:13] [INFO] [ScanProject] Start analyzing components...
[02:36:13] [/opt/rh/rh-python36/root/usr/lib/python3.6/site-packages/clocwalk/cli.py(70)start()] [INFO] analysis statistics code ...
[02:36:14] [INFO] [ScanProject] Project code line: [419], language: [Python], size: [116] KB
[02:36:14] [INFO] [ScanProject] Start executing exclusion rules...
[02:36:14] [INFO] [ScanProject] Exclusion rule execution completed.
[02:36:14] [INFO] [RuleScanner] Begin to perform rule-based component vulnerability analysis...
[02:36:14] [INFO] [RuleScanner] [Component] [+] Found 'Apache Solr 远程代码执行(CVE-2019-0192)' vulnerability.
[02:36:14] [INFO] [RuleScanner] [Component] [+] Found 'Apache Shiro 反序列化漏洞 (RCE)' vulnerability.
[02:36:14] [INFO] [RuleScanner] [Component] [+] Found 'Spring Framework 远程代码执行(CVE-2018-1270)' vulnerability.
[02:36:14] [INFO] [RuleScanner] [Component] [+] Found 'fastjson 远程代码执行漏洞' vulnerability.
[02:36:14] [INFO] [RuleScanner] [Component] [+] Found 'Jackson-databind 反序列化漏洞 (CVE-2019-12384)' vulnerability.
[02:36:14] [INFO] [RuleScanner] [Component] [+] Found 'Jackson-databind 任意命令执行漏洞(CVE-2017-17485)' vulnerability.
[02:36:14] [INFO] [RuleScanner] [Component] [+] Found 'Jackson-databind 反序列化漏洞(CVE-2017-7525)' vulnerability.
[02:36:14] [INFO] [RuleScanner] [Component] [+] Found 'Jackson-databind polymorphic反序列化漏洞 (CVE-2018-12022)' vulnerability.
[02:36:14] [INFO] [RuleScanner] [Component] [+] Found 'Jackson-databind polymorphic反序列化漏洞 (CVE-2018-14719)' vulnerability.
[02:36:14] [INFO] [RuleScanner] [Component] [+] Found 'Jackson-databind polymorphic反序列化漏洞 (CVE-2018-19362)' vulnerability.
[02:36:14] [INFO] [RuleScanner] [Component] [+] Found 'Jackson-databind SubTypeValidator.java 存在远程代码执行漏洞 (CVE-2019-14379)' vulnerability.
[02:36:14] [INFO] [RuleScanner] [Component] [+] Found 'Fastjson远程拒绝服务漏洞' vulnerability.
[02:36:14] [INFO] [RuleScanner] Rule component scan completed.
[02:36:14] [INFO] [RuleScanner] 正在执行黑名单检测...
[02:36:14] [INFO] [RuleScanner] Begin to perform rule-based blacklist vulnerability analysis...
[02:36:14] [INFO] [RuleScanner] Rule blacklist scan completed.
[02:36:14] [INFO] [PluginScanner] 正在执行黑名单检测...
[02:36:14] [INFO] [RuleScanner] 正在执行白名单过滤...
[02:36:14] [INFO] [RuleScanner] False positive rule processing...
[02:36:14] [INFO] [RuleScanner] Rule whitelist scan completed.
[02:36:14] [INFO] [PluginScanner] 正在执行白名单过滤...
[02:36:14] [INFO] [PluginScanner] False positive plugin processing...
[02:36:14] [INFO] [PluginScanner] Plugin whitelist scan completed.
[02:36:14] [INFO] [ScanProject] [+] Save the scan results to '/data/seecode/logs/vuln_java/1.json', total: 12.
[02:36:14] [INFO] Analysis completed, time consuming: 1.57s
2 线上项目¶
线上扫描项目其大致流程是,通过 gitlab/github 等代码托管系统,来实时拉取线上代码进行扫描。 这是使用了 -c 参数,通过配置文件进行代码检测。
$ python cli.py -c vuln_java.yaml
---------------------------------------------------------------------------------------------------
____ U _____ u U _____ u ____ U ___ u ____ U _____ u
/ __"| u \| ___"|/ \| ___"|/ U /"___| \/"_ \/ | _"\ \| ___"|/
<\___ \/ | _|" | _|" \| | u | | | | /| | | | | _|"
u___) | | |___ | |___ | |/__ .-,_| |_| | U| |_| |\ | |___
|____/>> |_____| |_____| \____| \_)-\___/ |____/ u |_____|
)( (__) << >> << >> _// \\ \\ |||_ << >>
(__) (__) (__) (__) (__) (__)(__) (__) (__)_) (__) (__)
____ ____ _ _ _ _ _ U _____ u ____
/ __"| u U /"___| U /"\ u | \ |"| | \ |"| \| ___"|/ U | _"\ u
<\___ \/ \| | u \/ _ \/ <| \| |> <| \| |> | _|" \| |_) |/
u___) | | |/__ / ___ \ U| |\ |u U| |\ |u | |___ | _ <
|____/>> \____| /_/ \_\ |_| \_| |_| \_| |_____| |_| \_\
)( (__) _// \\ \\ >> || \\,-. || \\,-. << >> // \\_
(__) (__)(__) (__) (__) (_") (_/ (_") (_/ (__) (__) (__) (__)
SeeCode Audit seecode-scanner/1.0.0-20190911 xsseroot#gmail.com
---------------------------------------------------------------------------------------------------
[02:52:18] [WARNING] [TaskStatus] Query scan task information failed, returned '404 - Not Found' when accessing [http://seecode.com/api/v2/task/9527/] API interface.
[02:52:18] [INFO] [ScanProject] Start syncing project code into the scan directory...
[02:52:18] [INFO] [GitOperator] Force update of local code...
[02:52:22] [INFO] [GitOperator] Code synchronization completed.
[02:52:22] [INFO] [ScanProject] current branch commit:d3f491ad09eaa9f7923edd2e041099e81171eb38, branch name:master
[02:52:22] [INFO] [ScanProject] Synchronization project code completion.
[02:52:22] [INFO] [ScanProject] Start executing exclusion rules...
[02:52:22] [INFO] [ScanProject] Exclusion rule execution completed.
[02:52:22] [INFO] [ScanProject] Start analyzing components...
[02:52:22] [/opt/rh/rh-python36/root/usr/lib/python3.6/site-packages/clocwalk/cli.py(70)start()] [INFO] analysis statistics code ...
[02:52:22] [INFO] [ScanProject] Project code line: [419], language: [Python], size: [124] KB
[02:52:22] [INFO] [ScanProject] Start executing exclusion rules...
[02:52:23] [INFO] [ScanProject] Exclusion rule execution completed.
[02:52:23] [INFO] [RuleScanner] Begin to perform rule-based component vulnerability analysis...
[02:52:23] [INFO] [RuleScanner] [Component] [+] Found 'Apache Solr 远程代码执行(CVE-2019-0192)' vulnerability.
[02:52:23] [INFO] [RuleScanner] [Component] [+] Found 'Apache Shiro 反序列化漏洞 (RCE)' vulnerability.
[02:52:23] [INFO] [RuleScanner] [Component] [+] Found 'Spring Framework 远程代码执行(CVE-2018-1270)' vulnerability.
[02:52:23] [INFO] [RuleScanner] [Component] [+] Found 'fastjson 远程代码执行漏洞' vulnerability.
[02:52:23] [INFO] [RuleScanner] [Component] [+] Found 'Jackson-databind 反序列化漏洞 (CVE-2019-12384)' vulnerability.
[02:52:23] [INFO] [RuleScanner] [Component] [+] Found 'Jackson-databind 任意命令执行漏洞(CVE-2017-17485)' vulnerability.
[02:52:23] [INFO] [RuleScanner] [Component] [+] Found 'Jackson-databind 反序列化漏洞(CVE-2017-7525)' vulnerability.
[02:52:23] [INFO] [RuleScanner] [Component] [+] Found 'Jackson-databind polymorphic反序列化漏洞 (CVE-2018-12022)' vulnerability.
[02:52:23] [INFO] [RuleScanner] [Component] [+] Found 'Jackson-databind polymorphic反序列化漏洞 (CVE-2018-14719)' vulnerability.
[02:52:23] [INFO] [RuleScanner] [Component] [+] Found 'Jackson-databind polymorphic反序列化漏洞 (CVE-2018-19362)' vulnerability.
[02:52:23] [INFO] [RuleScanner] [Component] [+] Found 'Jackson-databind SubTypeValidator.java 存在远程代码执行漏洞 (CVE-2019-14379)' vulnerability.
[02:52:23] [INFO] [RuleScanner] [Component] [+] Found 'Fastjson远程拒绝服务漏洞' vulnerability.
[02:52:23] [INFO] [RuleScanner] Rule component scan completed.
[02:52:23] [INFO] [RuleScanner] 正在执行黑名单检测...
[02:52:23] [INFO] [RuleScanner] Begin to perform rule-based blacklist vulnerability analysis...
[02:52:23] [INFO] [RuleScanner] Rule blacklist scan completed.
[02:52:23] [INFO] [RuleScanner] 正在执行白名单过滤...
[02:52:23] [INFO] [RuleScanner] False positive rule processing...
[02:52:23] [INFO] [RuleScanner] Rule whitelist scan completed.
[02:52:23] [INFO] [ScanProject] [+] Save the scan results to '/data/seecode/logs/9527/9527.json', total: 12.
[02:52:23] [INFO] Analysis completed, time consuming: 5.59s
vuln_java.yaml 文件的格式如下,具体配置文件的参数说明请参考 项目配置
scan:
task_id: 9527
template: "component_scan"
threads: 20
log_level: "info"
work_dir: "/data/seecode/"
project_ssh: "https://github.com/seecode-audit/vuln_java.git"
project_web: "https://github.com/seecode-audit/vuln_java"
project_name: "vuln_java"
project_branch: "master"
project_type: "online"
project_storage_type: "local"
project_file_origin_name: ""
project_file_hash: ""
group_name: "seecode-audit"
group_key: "seecode-audit"
evidence_start_line_offset: -1
evidence_count: 5
force_sync_code: True
sync_vuln_to_server: False
result_format: "json"
result_file: "9527.json"