

https://github.com/mergebase/log4j-detector の Python 移植版です。log4j-detector は Copyright (C) Copyright 2021 Mergebase Software Inc. https://mergebase.com/ に帰属し、GPLv3 でライセンスされています。
Python に移植した動機は、パフォーマンスの向上、メモリ消費の削減、コードの可読性の向上です。比較については下記の パフォーマンス セクションを参照してください。
そして、これは 最も高速で、メモリ要件が最も低いスキャンツール のようです。
CVE-2021-44228、CVE-2021-45046 およびその他多数の脆弱性に対して影響を受ける、ファイルシステム上の log4j (1.x)、reload4j (1.2.18+)、log4j-core (2.x) のバージョンを特定します - 下の表 を参照。大規模なアプリケーションに数層深く埋め込まれたインスタンスも検出できます。Linux、Windows、Mac、その他 Python 3.8+ が動作するあらゆる環境で動作します。
実行可能な spring-boot の jar/war、uber jars に混在する依存関係、shaded jar、さらにはファイルシステム上に圧縮されずに置かれている exploded jar ファイル(別名 *.class)内の log4j も正確に検出できます。また、shaded クラスファイル(拡張子 .esclazz(elastic)および .classdata(Azure))も処理できます。
検索対象の Java アーカイブ拡張子: .zip, .jar, .war, .ear, .aar, .jpi,
.hpi, .rar, .nar, .wab, .eba, .ejb, .sar, .apk, .par, .kar
各インスタンスは、該当する CVE のリストとともに報告されます。各 CVE について、推奨される回避策(例: JndiLookup.class や JMSAppender.class の削除)が適用されたかどうかが log4j ライブラリファイルで分析され、適用済みの場合は脆弱性なしと見なされます。STRANGE ステータスは、log4j-core の pom.properties ファイルはあるが実際のバイトコードクラスが含まれないアーカイブについて報告されます。通常これらはソースパッケージなので無視して構いません。
警告
--fix機能は実験的です。自己責任で使用し、使用前に jar ファイルをバックアップしてください。
--fix 引数は、JndiLookup.class のインスタンスを JndiLookup.vulne にリネームすることで、クラスがロードされないようにします。Java アーカイブ内ではインプレースリネームで行われるため、アーカイブの再 zip 化は不要で、瞬時に完了します。
Linux 64bit、MS Windows 64bit および 32bit 向けのバイナリが利用可能です - Releases を参照
サポートされる最小 Python バージョンは 3.8 です。私のテストによると、Python 3.6 の zip 実装ではテストデータの多くの
.jarファイルを開くことができませんでした。
log4shell-finder はパフォーマンスと低メモリ消費向けに最適化されています。
2022年1月23日更新。2005 フォルダ内の 26237 ファイルがあるディレクトリでパフォーマンスを測定しました。
実行時間は半分、メモリ消費は 2/3、ファイルシステム読み取りは少なくとも 90% 削減
Command being timed: "./test_log4shell.py /home/hynek/war/ --exclude-dirs /mnt --same-fs"
User time (seconds): 17.68
System time (seconds): 1.20
Percent of CPU this job got: 127%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:14.47
Maximum resident set size (kbytes): 64144
File system inputs: 114424
Command being timed: "./log4j-finder.py /home/hynek/war/"
User time (seconds): 23.59
System time (seconds): 1.09
Percent of CPU this job got: 99%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:26.18
Maximum resident set size (kbytes): 38604
File system inputs: 142824
Command being timed: "java -jar log4j-detector-latest.jar /home/hynek/war"
User time (seconds): 30.56
System time (seconds): 1.39
Percent of CPU this job got: 113%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:28.26
Maximum resident set size (kbytes): 214116
File system inputs: 14416
Command being timed: "./log4j2-scan /home/hynek/war --scan-log4j1 --scan-zip"
User time (seconds): 52.05
System time (seconds): 25.32
Percent of CPU this job got: 88%
Elapsed (wall clock) time (h:mm:ss or m:ss): 1:27.86
Maximum resident set size (kbytes): 593080
File system inputs: 215416
all パラメータを使用してすべてのローカルドライブを自動検出--no-csv-header--threads パラメータ--cvs-clean パラメータ--cvs-stats パラメータ--fix コマンドが .jar アーカイブを破損する可能性がありました。以前の変更については リリースノート を参照してください。
Python インタープリターから実行するか、dist フォルダ内の Windows/Linux バイナリを使用します。
ファイルシステム全体にアクセスできる(少なくとも読み取り専用)ユーザーとして実行してください。log4shell-finder はアクセスできるフォルダのみを走査し、権限拒否エラーは報告しません。
PS C:\D\log4shell_finder> python3 .\test_log4shell.py --help
usage: Type "test_log4shell.py --help" for more information
On Windows "test_log4shell.py c:\ d:\"
On Linux "test_log4shell.py /"
Searches file system for vulnerable log4j version.
positional arguments:
folders List of folders or files to scan. Use "-" to read list of files from stdin. On MS Windows use "all" to scan all local drives.
optional arguments:
-h, --help show this help message and exit
--exclude-dirs DIR [DIR ...]
Exclude given directories from search.
-s, --same-fs Don't scan mounted volumens.
-j [FILE], --json-out [FILE]
Save results to json file.
-c [FILE], --csv-out [FILE]
Save results to csv file.
--csv-clean Add CLEAN status line in case no entries found
--csv-stats Add STATS line into csv output.
--no-csv-header Don't write CSV header to the output file.
-f, --fix Fix vulnerable by renaming JndiLookup.class into JndiLookup.vulne.
--threads [THREADS] Specify number of threads to use for parallel processing, default is 6.
--file-log [LOGFILE] Enable logging to log file, default is log4shell-finder.log.
--progress [SEC] Report progress every SEC seconds, default is 10 seconds.
--no-errors Suppress printing of file system errors.
--strange Report also strange occurences with pom.properties without binary classes (e.g. source or test packages)
-d, --debug Increase verbosity, mainly for debugging purposes.
-v, --version show program's version number and exit
追加の Python ライブラリは必要ありません。
バイナリは次の方法で生成されました:
pip install pyinstaller
pyinstaller -F ./test_log4shell.py
32bit 版をビルドする場合は、32bit Python インタープリターをインストールし、次のコマンドで pyinstaller をインストールします:
C:\Users\User\AppData\Local\Programs\Python\Python38-32\python.exe -m pip install pyinstaller
その後、次のコマンドを実行します:
C:\Users\User\AppData\Local\Programs\Python\Python38-32\Scripts\pyinstaller.exe -n test_log4shell-mswin32 -F test_log4shell.py
Linux では次のように実行できます:
python3 ./test_log4shell.py / /opt --same-fs --no-errors
MS Windows の場合:
python3 .\test_log4shell.py c:\ d:\ --same-fs --no-errors
MS Windows の場合:
pywin32 がインストールされていることを確認してください(例: pip install pywin32)。
PS C:\D\log4shell_finder> python3 .\test_log4shell.py c:\ --same-fs --no-errors
8 .8 8 8 8 d'b o 8
8 d'8 8 8 8 8 8
8 .oPYo. .oPYo. d' 8 .oPYo. 8oPYo. .oPYo. 8 8 o8P o8 odYo. .oPYo8 .oPYo. oPYo.
8 8 8 8 8 Pooooo Yb.. 8 8 8oooo8 8 8 8 8 8' `8 8 8 8oooo8 8 `'
8 8 8 8 8 8 'Yb. 8 8 8. 8 8 8 8 8 8 8 8 8. 8
8 `YooP' `YooP8 8 `YooP' 8 8 `Yooo' 8 8 8 8 8 8 `YooP' `Yooo' 8
..:.....::....8 ::::..::.....:..:::..:.....:....:::::::..:::....::..:.....::.....:..::::
:::::::::::ooP'.::::::::::::::::::::::::::::::::: Version 1.17-20220105 ::::::::::::
:::::::::::...::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Parameters: .\test_log4shell.py c:\ --same-fs --no-errors
Host info: 'hostname': 'TESTHOST', 'fqdn': 'TESTHOST.example.com', 'ip': '10.0.0.1', 'system': 'Windows', 'release': '10', 'version': '10.0.19043', 'machine': 'AMD64', 'cpu': 'Intel64 Family 6 Model 142 Stepping 12, GenuineIntel'
[+] [CVE-2021-4104 (8.1)] Package c:\Program Files\Microsoft SQL Server\150\DTS\Extensions\Common\Jars\log4j-1.2.17.jar contains Log4J-1.2.17 <= 1.2.17, JMSAppender.class found
[+] [CVE-2021-44832 (6.6), CVE-2021-45046 (9.0), CVE-2021-45105 (5.9)] Package c:\Program Files\OWASP\Zed Attack Proxy\lib\log4j-core-2.15.0.jar contains Log4J-2.15.0 == 2.15.0
[+] [CVE-2021-44228 (10.0), CVE-2021-44832 (6.6), CVE-2021-45046 (9.0), CVE-2021-45105 (5.9)] Package c:\Users\testuser\Downloads\sqldeveloper-20.4.1.407.0006-x64.zip -> sqldeveloper/sqldeveloper/lib/log4j-core.jar contains Log4J-2.13.3 >= 2.10.0
[+] [CVE-2021-44228 (10.0), CVE-2021-44832 (6.6), CVE-2021-45046 (9.0), CVE-2021-45105 (5.9)] Package c:\Users\testuser\Downloads\sqldeveloper-20.4.1.407.0006-x64\sqldeveloper\sqldeveloper\lib\log4j-core.jar contains Log4J-2.13.3 >= 2.10.0
Scanned 1162924 files in 286638 folders.
Found 1 instances vulnerable to CVE-2021-4104 (8.1)
Found 2 instances vulnerable to CVE-2021-44228 (10.0)
Found 3 instances vulnerable to CVE-2021-44832 (6.6)
Found 3 instances vulnerable to CVE-2021-45046 (9.0)
Found 3 instances vulnerable to CVE-2021-45105 (5.9)
Kali をスキャンし、1 秒ごとに進捗を報告、zip-bomb フォルダを除外した例:
root@kali:/home/hynek/log4shell-finder# python3 test_log4shell.py / --same-fs --no-errors --progress 1 --exclude-dirs /usr/share/seclists/Payloads/Zip-Bombs/
8 .8 8 8 8 d'b o 8
8 d'8 8 8 8 8 8
8 .oPYo. .oPYo. d' 8 .oPYo. 8oPYo. .oPYo. 8 8 o8P o8 odYo. .oPYo8 .oPYo. oPYo.
8 8 8 8 8 Pooooo Yb.. 8 8 8oooo8 8 8 8 8 8' `8 8 8 8oooo8 8 `'
8 8 8 8 8 8 'Yb. 8 8 8. 8 8 8 8 8 8 8 8 8. 8
8 `YooP' `YooP8 8 `YooP' 8 8 `Yooo' 8 8 8 8 8 8 `YooP' `Yooo' 8
..:.....::....8 ::::..::.....:..:::..:.....:....:::::::..:::....::..:.....::.....:..::::
:::::::::::ooP'.::::::::::::::::::::::::::::::::: Version 1.18-20220106 ::::::::::::
:::::::::::...::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Parameters: test_log4shell.py / --same-fs --no-errors --progress 1 --exclude-dirs /usr/share/seclists/Payloads/Zip-Bombs/
Host info: 'hostname': 'kali', 'fqdn': 'kali', 'ip': '10.0.0.2', 'system': 'Linux', 'release': '5.14.0-kali4-amd64', 'version': '#1 SMP Debian 5.14.16-1kali1 (2021-11-05)', 'machine': 'x86_64', 'cpu': ''
Skipping mount point: /data
Skipping mount point: /home
Skipping mount point: /dev
Skipping mount point: /sys
[+] [CVE-2021-4104 (8.1)] Package /usr/share/paros/paros.jar contains Log4J-1.x <= 1.2.17, JMSAppender.class found
After 1 secs, scanned 119762 files in 4853 folders.
Currently at: /usr/share/icons/hicolor/48x48/apps/kali-jd-gui.png
Skipping blaclisted folder: /usr/share/seclists/Payloads/Zip-Bombs
After 2 secs, scanned 190067 files in 12980 folders.
Currently at: /usr/share/plasma/desktoptheme/kali/metadata.desktop
[+] [CVE-2021-44228 (10.0), CVE-2021-44832 (6.6), CVE-2021-45046 (9.0), CVE-2021-45105 (5.9)] Package /usr/share/jsql-injection/jsql-injection.jar contains Log4J-2.14.0 >= 2.10.0
After 3 secs, scanned 221233 files in 17725 folders.
Currently at: /usr/share/maltego/maltego-ui/modules/com-paterva-maltego-transform-finder.jar
[+] [CVE-2021-44228 (10.0), CVE-2021-44832 (6.6), CVE-2021-45046 (9.0), CVE-2021-45105 (5.9)] Package /usr/share/zaproxy/lib/log4j-core-2.14.1.jar contains Log4J-2.14.1 >= 2.10.0
[+] [CVE-2021-4104 (8.1)] Package /usr/share/javasnoop/lib/log4j-1.2.16.jar contains Log4J-1.2.16 <= 1.2.17, JMSAppender.class found
After 7 secs, scanned 233394 files in 18705 folders.
Currently at: /usr/share/images/desktop-base/login-background.svg
After 8 secs, scanned 301417 files in 27952 folders.
Currently at: /usr/lib/python3/dist-packages/faraday_plugins/plugins/repo/dirb/plugin.py
After 9 secs, scanned 342342 files in 34421 folders.
Currently at: /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/jexec
Skipping mount point: /run
Skipping mount point: /proc
Scanned 379253 files in 37742 folders in 9.9 seconds.
Found 2 instances vulnerable to CVE-2021-4104 (8.1)
Found 2 instances vulnerable to CVE-2021-44228 (10.0)
Found 2 instances vulnerable to CVE-2021-44832 (6.6)
Found 2 instances vulnerable to CVE-2021-45046 (9.0)
Found 2 instances vulnerable to CVE-2021-45105 (5.9)
json への出力には、見つかったすべてのアイテムとホスト情報が含まれます:
{
"hostname": "myserver",
"fqdn": "myserver",
"ip": "10.0.0.1",
"system": "Linux",
"release": "5.4.0-58-generic",
"version": "#64-Ubuntu SMP Wed Dec 9 08:16:25 UTC 2020",
"machine": "x86_64",
"cpu": "x86_64",
"cmdline": "./test_log4shell.py / --exclude-dirs /mnt --same-fs --csv-out --json-out",
"starttime": "2021-12-22 07:07:54",
"items": [
{
"container": "Package",
"path": "/home/hynek/.m2/repository/org/apache/logging/log4j/log4j-core/2.14.1/log4j-core-2.14.1.jar",
"status": "CVE_2021_44228",
"message": "contains Log4J-2.14.1 >= 2.10.0",
"pom_version": "2.14.1"
},
{
"container": "Package",
"path": "/home/hynek/.m2/repository/org/apache/logging/log4j/log4j-core/2.16.0/log4j-core-2.16.0.jar",
"status": "NOTOKAY",
"message": "contains Log4J-2.16.0 == 2.16.0",
"pom_version": "2.16.0"
},
{
"container": "Package",
"path": "/home/hynek/.m2/repository/log4j/log4j/1.2.17/log4j-1.2.17.jar",
"status": "CVE_2021_4104",
"message": "contains Log4J-1.2.17 <= 1.2.17, JMSAppender.class found",
"pom_version": "1.2.17"
},
{
"container": "Package",
"path": "/home/hynek/.m2/repository/log4j/log4j/1.2.12/log4j-1.2.12.jar",
"status": "CVE_2021_4104",
"message": "contains Log4J-1.x <= 1.2.17, JMSAppender.class found",
"pom_version": "1.x"
},
{
"container": "Package",
"path": "/home/hynek/war/elastic-apm-java-aws-lambda-layer-1.28.1.zip:elastic-apm-agent-1.28.1.jar",
"status": "MAYBESAFE",
"message": "contains Log4J-2.12.1 <= 2.0-beta8 (JndiLookup.class not present)",
"pom_version": "2.12.1"
}
]
}
列は次のとおりです:
"datetime","ver","ip","fqdn","OS","Release","arch","container","status","path","message","pom_version","product"
"2022-01-24 10:59:36","1.22pre-20220123","10.0.0.1","mylinux","Linux","5.4.0-58-generic","x86_64","Folder","CVE-2022-23302 (6.6), CVE-2022-23305 (8.1), CVE-2022-23307 (8.1)","/home/hynek/war.bak/reload4j/reload4j-1.2.18.0/org/apache/log4j","contains log4j-1.2.18.0","1.2.18.0","log4j"
"2022-01-24 10:59:36","1.22pre-20220123","10.0.0.1","mylinux","Linux","5.4.0-58-generic","x86_64","Package","OLDSAFE","/home/hynek/war.bak/reload4j/reload4j-1.2.18.2.jar","contains reload4j-1.2.18.2","1.2.18.2","reload4j"
"2022-01-24 10:59:36","1.22pre-20220123","10.0.0.1","mylinux","Linux","5.4.0-58-generic","x86_64","Package","OLDSAFE","/home/hynek/war.bak/reload4j/reload4j-1.2.18.1.jar","contains reload4j-1.2.18.1","1.2.18.1","reload4j"
"2022-01-24 10:59:36","1.22pre-20220123","10.0.0.1","mylinux","Linux","5.4.0-58-generic","x86_64","Package","CVE-2019-17571 (9.8), CVE-2021-4104 (7.5), CVE-2022-23302 (6.6), CVE-2022-23305 (8.1), CVE-2022-23307 (8.1)","/home/hynek/war.bak/reload4j/log4j-1.2.17.jar","contains log4j-1.2.17","1.2.17","log4j"
"2022-01-24 10:59:36","1.22pre-20220123","10.0.0.1","mylinux","Linux","5.4.0-58-generic","x86_64","Package","CVE-2022-23302 (6.6), CVE-2022-23305 (8.1), CVE-2022-23307 (8.1)","/home/hynek/war.bak/reload4j/reload4j-1.2.18.0.jar","contains log4j-1.2.18.0","1.2.18.0","log4j"
| 検出 | CVE | CVSSv3 | 深刻度 | Java | 影響を受ける開始バージョン | 影響を受けるバージョン | 修正バージョン | ライブラリ |
|---|
| ○ | CVE-2021-44228 | 10.0 | 緊急 | 8 | 2.0-beta9 | 2.14.1 | 2.15.0 | log4jv2 |
| ○ | CVE-2017-5645 | 9.8 | 緊急 | 7 | 2.0-alpha1 | 2.8.1 | 2.8.2 | log4jv2 |
| ○ | CVE-2019-17571 | 9.8 | 緊急 | 1.2.0 | 1.2.17 | nofix | log4jv1 | |
| ○ | CVE-2021-45046 | 9.0 | 緊急 | 7/8 | 2.0-beta9 | 2.15.0(2.12.2 を除く) | 2.12.2/2.16.0 | log4jv2 |
| ○ | CVE-2022-23305 | 9.8 | 緊急 | 1.2.0 | 1.2.17 | nofix / 1.2.18.1 | log4jv1, reload4j | |
| ○ | CVE-2022-23307 | 9.8 | 緊急 | 1.2.0 | 1.2.17 | nofix / 1.2.18.1 | log4jv1, reload4j | |
| ○ | CVE-2022-23302 | 8.8 | 高 | 1.0 | 1.2.17 | nofix / 1.2.18.1 | log4jv1, reload4j | |
| ○ | CVE-2021-4104 | 7.5 | 高 | - | 1.0 | 1.2.17 | nofix | log4jv1 |
| ○ | CVE-2021-44832 | 6.6 | 中 | 6/7/8 | 2.0-alpha7 | 2.17.0(2.3.2/2.12.4 を除く) | 2.3.2/2.12.4/2.17.1 | log4jv2 |
| - | CVE-2021-42550 | 6.6 | 中 | - | 1.0 | 1.2.7 | 1.2.8 | logback |
| ○ | CVE-2021-45105 | 5.9 | 中 | 6/7/8 | 2.0-beta9 | 2.16.0(2.12.3 を除く) | 2.3.1/2.12.3/2.17.0 | log4jv2 |
| - | CVE-2020-9488 | 3.7 | 低 | 7/8 | 2.0-alpha1 | 2.13.1 | 2.12.3/2.13.2 | log4jv2 |