LoginSignup
1
1

More than 1 year has passed since last update.

OWASP Dependency-Checkを使いLog4Shell(CVE-2021-44228)を検知する

Posted at

OWASP Dependency-Checkとは、SCA(Software Composition Analysis)1 を行うツールの一つで、プロジェクトが依存するライブラリに含まれる脆弱性を検出します。

CLI / Ant / Maven / Gradle / Homebrew / Jenkins / SonarQube / Circle CI などで使用できる豊富なプラグインが用意されています。

今回は、 Gradle Plugin で、Apache Log4jの任意コード実行の脆弱性(CVE-2021-44228: Log4Shell)2 が検知できるを確認してみます。

実行環境

  • Gradle: 7.3.3

準備

Gradleのプロジェクトを用意します。

$ gradle init

Select type of project to generate:
  1: basic
  2: application
  3: library
  4: Gradle plugin
Enter selection (default: basic) [1..4] 2

Select implementation language:
  1: C++
  2: Groovy
  3: Java
  4: Kotlin
  5: Scala
  6: Swift
Enter selection (default: Java) [1..6] 3

Split functionality across multiple subprojects?:
  1: no - only one application project
  2: yes - application and library projects
Enter selection (default: no - only one application project) [1..2] 1

Select build script DSL:
  1: Groovy
  2: Kotlin
Enter selection (default: Groovy) [1..2] 1

Generate build using new APIs and behavior (some features may change in the next minor release)? (default: no) [yes, no]
Select test framework:
  1: JUnit 4
  2: TestNG
  3: Spock
  4: JUnit Jupiter
Enter selection (default: JUnit Jupiter) [1..4] 3

Project name (default: example-dependency-check-gradle):
Source package (default: example.dependency.check.gradle):

> Task :init
Get more help with your project: https://docs.gradle.org/7.3.3/samples/sample_building_java_applications.html

BUILD SUCCESSFUL in 28s
2 actionable tasks: 2 executed

Dependency-Checkを有効化する

app/build.graldeに以下のプラグイン設定を追加するだけで、動作させることができます。

plugins {
  id "org.owasp.dependencycheck" version "6.5.3"
}

プラグインが追加されたことを確認する

./gradlew tasksを実行し、OWASP dependency-check tasksが出力されればプラグインが追加されたことを確認できます。

$ ./gradlew tasks

> Task :tasks

<snip>

OWASP dependency-check tasks
----------------------------
dependencyCheckAggregate - Identifies and reports known vulnerabilities (CVEs) in multi-project dependencies.
dependencyCheckAnalyze - Identifies and reports known vulnerabilities (CVEs) in project dependencies.
dependencyCheckPurge - Purges the local cache of the NVD.
dependencyCheckUpdate - Downloads and stores updates from the NVD CVE data feeds.

脆弱性データベースを更新する

Dependency-Checkは脆弱性のデータをローカルに保持するようになっています。そのため、データが古いと脆弱性を検知できない場合があるので更新をします。

$ ./gradlew dependencyCheckUpdate

脆弱性をチェックする

脆弱性をチェックします。

$ ./gradlew dependencyCheckAnalyze

> Task :app:dependencyCheckAnalyze
Verifying dependencies for project app
Checking for updates and analyzing dependencies for vulnerabilities
Generating report for project app
Found 0 vulnerabilities in project app

BUILD SUCCESSFUL in 4s
1 actionable task: 1 executed

プロジェクトを作成したばかりなので、何も検知されません。

Log4Shell(CVE-2021-44228)を検知する

app/build.gradleに脆弱性のあるlog4jの利用設定を追加します。

dependencies {
    // https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core
    implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.14.1'
}

準備ができたので、脆弱性のチェックを行うと、CVE-2021-44228を含む複数の脆弱性を検知することができました。

$ ./gradlew dependencyCheckAnalyze

> Task :app:dependencyCheckAnalyze
Verifying dependencies for project app
Checking for updates and analyzing dependencies for vulnerabilities
Generating report for project app
Found 5 vulnerabilities in project app


One or more dependencies were identified with known vulnerabilities in app:

log4j-core-2.14.1.jar (pkg:maven/org.apache.logging.log4j/log4j-core@2.14.1, cpe:2.3:a:apache:log4j:2.14.1:*:*:*:*:*:*:*) : CVE-2021-44228, CVE-2021-44832, CVE-2021-45046, CVE-2021-45105, CWE-502: Deserialization of Untrusted Data


See the dependency-check report for more details.



BUILD SUCCESSFUL in 4s
1 actionable task: 1 executed

レポートをチェックする

脆弱性をのチェックを実施すると、app/build/reports/dependency-check-report.htmlにHTML形式のレポートが出力されます。サマリや脆弱性の詳細がレポート中に記載されますので、マネジメント層への報告稼働の削減にもなると思います。

サマリ

image.png

CVE-2021-44228の詳細

image.png

さいごに

Gradle Plugin で、Apache Log4jの任意コード実行の脆弱性(CVE-2021-44228: Log4Shell) が検知できるを確認してみましたが、1行追記するだけでライブラリの脆弱性チェックを簡単に実施することができました。

また、レポート出力機能を備えてり、マネジメント層への報告にも活用ができますし、さまざまなプラグインが提供されていますので、CIに組み込むことも容易そうです。

2021/12に発生した、Apache Log4jの任意コード実行の脆弱性(CVE-2021-44228: Log4Shell)の影響でマネジメント層の脆弱性管理への関心も高いと思いますので、導入検討時の参考になれば幸いです。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1