Dependency-Check
使用 “存在已知漏洞的组件” 已经成为OWASP TOP 10
的漏洞之一了,他是一个开源的程序,主要用于识别项目依赖项并检查是否存在已知的,公开披露的漏洞,目前支持Java
、.NET
、Ruby
、Node.js
、Python
等语言。
主要功能是对jar
依赖包进行扫描。他的简单工作原理是依靠强大的库,与被扫jar依赖包进行比对,输出jar
包详情。所以该工具只能扫描出已经公布的,无法扫描0day
工作原理
Dependency-Check
工作的方式是通过分析器对文件进行扫描搜集信息,搜集到的信息被叫做迹象。
这边共搜集3种迹象,分时是vendor
(供应商),product
(产品)和version
(版本)。例如,jarAnalyzer
将从jar文件包中的Mainfest
、pom.xml
和包名进行信息搜集,然后把各种搜集到的源放到一个或者多个迹象表里。
通过搜集到的迹象和CPE
条目(NVD
美国国家通用数据库、CVE数据索引)进行匹配,分析器匹配到了就会给个标志发送到报告。
Dependency-Check
目前不使用hash
识别文件,因为第三方依赖从源码中的hash值构建通常不会匹配官方发布版本的hash
。后续版本中可能会增加一些hash
来匹配一些常用的第三方库,例如Spring
, Struts
等。
使用
1 D:\app\dependency-check-8.2.1-release\dependency-check\bin>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 --advancedHelp Print the advanced help message. --enableExperimental Enables the experimental analyzers. --exclude <pattern> 指定一个排除模式。这个选项可以多次指定,它接受Ant风格的排除” -f,--format <format> The report format (HTML, XML, CSV, JSON, JUNIT, SARIF, JENKINS, or ALL). The default is HTML. Multiple format parameters can be specified. --failOnCVSS <score> 指定如果识别到高于指定级别的CVSS评分,是否应该使构建失败。 默认值是11;因为CVSS评分是0-10,所以默认情况下构建永远不会失败 -h,--help Print this message. --junitFailOnCVSS <score> 指定在生成junit报告时被视为失败的CVSS评分。默认值是0 -l,--log <file> The file path to write verbose logging information. -n,--noupdate 禁用NVD-CVE,hosted-suppressions和RetireJS数据的自动更新 -o,--out <path> 指定报告目录. --prettyPrint When specified the JSON and XML report formats will be pretty printed. --project <name> The name of the project being scanned. -s,--scan <path> 指定被扫描的jar文件目录 recommended to quote the argument value. --suppression <file> The file path to the suppression XML file. This can be specified more then once to utilize multiple suppression files -v,--version Print the version information.
CVE
CVSS评分标准: 漏洞的最终得分最大为10,最小为0。得分710的漏洞通常被认为比较严重,得分在46.9之间的是中级漏洞,0~3.9的则是低级漏洞。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 dependency-check.bat --disableRetireJS --disableNodeJS -s D:\project\checkjar -o D:\project\report [INFO] NVD CVE requires several updates; this could take a couple of minutes. [INFO] Download Started for NVD CVE - 2002 [INFO] Download Complete for NVD CVE - 2002 (4454 ms) [INFO] Processing Started for NVD CVE - 2002 [INFO] Download Started for NVD CVE - 2003 [INFO] Processing Complete for NVD CVE - 2002 (6277 ms) [INFO] Download Complete for NVD CVE - 2003 (2566 ms) [INFO] Processing Started for NVD CVE - 2003 [INFO] Processing Complete for NVD CVE - 2003 (1376 ms) ... INFO] Finished Dependency Bundling Analyzer (0 seconds) [INFO] Finished Unused Suppression Rule Analyzer (0 seconds) [INFO] Analysis Complete (8 seconds) [INFO] Writing report to: D:\project\report\dependency-check-report.html
报告分析
1 D:\project\report\dependency-check-report.html
比如log4j-core-2.16.0.jar
发现两个中等漏洞
当配置使用JDBC Appender
和JNDI LDAP
数据源URI
时,Apache Log4j2
版本2.0-beta7
至2.17.0
(不包括安全修复版本2.3.2和2.12.4
)容易受到远程代码执行(RCE
)攻击,如果攻击者控制了目标LDAP
服务器。这个问题通过将JNDI
数据源名称限制为java
协议在Log4j2
版本2.17.1,2.12.4
和2.3.2
中得到修复
离线审计
这里没有实践
当然了,如果你是离线审计,也可以将NVD
库搭建到本地,这样就会更加的方便,我们可以在本地搭建一个NVD
库来提高更新效率,具体可以参考这里
具体命令如下,其中cveUrlModified
和cveUrlModified
指定本地NVD
库
1 2 3 4 dependency-check.bat --cveUrlModified 本地nvd库的url/nvdcve-1.1-modified.json.gz --cveUrlBase本地nvd库的url/nvdcve-1.1-2020.json.gz --project test -s D:\checkjar\ -o D:\report\
集成
与maven集成
Dependency-check-maven
非常易于使用,可以作为独立插件使用,也可以作为maven site
的一部分使用。该插件需要使用Maven 3.1
或更高版本,第一次执行时,可能需要20分钟或更长时间,因为它会从NIST
托管的国家漏洞数据库下载漏洞数据到本地备份库。第一次批量下载后,只要插件每七天至少执行一次,本地漏洞库就会自动更新,更新只需几秒钟。
集成很简单,只需要在项目的pom
文件中增加maven
配置即可。
用法一 在target目录中创建dependency-check-report.html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 <plugin> <groupId>org.owasp</groupId> <artifactId>dependency-check-maven</artifactId> <version>4.0.2</version> <configuration> <autoUpdate>true</autoUpdate> </configuration> <executions> <execution> <goals> <goal>check</goal> </goals> </execution> </executions> </plugin>
用法二 在maven site中创建聚合性的报告
1 2 3 4 5 6 7 8 9 10 11 12 <plugin> <groupId>org.owasp</groupId> <artifactId>dependency-check-maven</artifactId> <version>4.0.2</version> <reportSets> <reportSet> <reports> <report>aggregate</report> </reports> </reportSet> </reportSets> </plugin>
用法三 设置当风险指数(CVSS)大于等于8时(CVSS分数为0-10)则项目编译失败
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 <plugin> <groupId>org.owasp</groupId> <artifactId>dependency-check-maven</artifactId> <version>4.0.2</version> <configuration> <failBuildOnCVSS>8</failBuildOnCVSS> </configuration> <executions> <execution> <goals> <goal>check</goal> </goals> </execution> </executions> </plugin>
用法四 仅更新NVD(漏洞库)数据,而不执行检查
1 2 3 4 5 6 7 8 9 10 11 12 <plugin> <groupId>org.owasp</groupId> <artifactId>dependency-check-maven</artifactId> <version>4.0.2</version> <executions> <execution> <goals> <goal>update-only</goal> </goals> </execution> </executions> </plugin>
更多配置信息,可以根据实际情况在官网查找:参考链接
与Jenkins集成
SonarQube 7.x集成
1 2 3 4 sonar.dependencyCheck.reportPath = ${WORKSPACE}/dependency-check-report.xml ##以Jenkins为例报告.xml路径 sonar.dependencyCheck.htmlReportPath = ${WORKSPACE}/dependency-check-report.html ##以Jenkins为例报告.html路径
1 2 3 4 sonar.dependencyCheck.severity.blocker = 9.0 sonar.dependencyCheck.severity.critical = 7.0 sonar.dependencyCheck.severity.major = 4.0 sonar.dependencyCheck.severity.minor = 0.0
报告查看
其他
扫描python
测试报告不好看,有能力的话,可以基于开源的代码进行修改