
로컬 파일 시스템에서 CVE-2021-44228(일명 Log4Shell)에 취약할 수 있는 Log4j .jar 파일을 스캔하는 Bash 및 PowerShell 스크립트입니다.
이 저장소에는 CVE-2021-44228(일명 Log4Shell)에 취약할 수 있는 .jar 파일을 식별하는 데 도움이 되는 스크립트가 포함되어 있습니다.
이 스크립트는 특정 경로에서 파일 시스템 내의 .jar 파일을 찾고, 발견된 각 .jar 파일(파일명과 관계없이)의 SHA-256 해시를 계산하여 사용자가 제공한 SHA-256 해시 목록과 비교합니다.
알려진 해시 파일은 공식 Log4j 릴리스에 대해 계산된 것으로, https://github.com/mubix/CVE-2021-44228-Log4Shell-Hashes 에서 제공됩니다. 이 저장소에 포함된 해시 파일도 이곳에서 가져왔습니다.
참고: 시스템에서 사용 중인 Log4j .jar 파일이 (예를 들어) 소스 코드에서 컴파일되었거나, 벤더가 어떤 유형의 사용자 정의를 적용했거나, Log4j 클래스가 더 큰 .jar 파일에 포함되어 수정된 경우, 해당 파일의 SHA-256 해시는 공식 Log4j 릴리스의 해시와 다르므로 스크립트가 이를 식별할 수 없습니다.
log4shell_hash_check.sh <path> <sha256file>
E.g.: sudo ./log4shell_hash_check.sh / sha256sum.txt
sudo ./log4shell_hash_check.sh ./ sha256sum.txt
sudo ./log4shell_hash_check.sh /opt/tomcat/ sha256sum.txt
log4shell_hash_check.ps1 -path <path> -hashfile <sha256file>
E.g.: .\log4shell_hash_check.ps1 -path c:\ -hashfile sha256sum.txt
.\log4shell_hash_check.ps1 -path .\ -hashfile sha256sum.txt
.\log4shell_hash_check.ps1 -path c:\opt\tomcat\ -hashfile sha256sum.txt
OccamSec $ ./log4shell_hash_check.sh ./ log4j_2.x_sha256sum.txt
Please be patient, scanning the file system for .jar files starting at ./
.//apache-log4j-2.13.1-bin/log4j-flume-ng-2.13.1.jar
.//apache-log4j-2.13.1-bin/log4j-core-2.13.1.jar
[CUT]
.//apache-log4j-2.13.1-bin/log4j-mongodb2-2.13.1.jar
.//apache-log4j-2.13.1-bin/log4j-to-slf4j-2.13.1-sources.jar
.//apache-log4j-2.13.1-bin/log4j-to-slf4j-2.13.1-javadoc.jar
.//apache-log4j-2.13.1-bin/log4j-appserver-2.13.1-javadoc.jar
.//apache-log4j-2.13.1-bin/log4j-appserver-2.13.1-sources.jar
Checking hash 6f38a25482d82cd118c4255f25b9d78d96821d22bab498cdce9cda7a563ca992 .//apache-log4j-2.13.1-bin/log4j-core-2.13.1.jar
>>> MATCH: 6f38a25482d82cd118c4255f25b9d78d96821d22bab498cdce9cda7a563ca992 .//apache-log4j-2.13.1-bin/log4j-core-2.13.1.jar
Checking hash eafab7995f042e0386e08fa5e299d63465b63f1e4e5cb754612c68d52b72516d .//apache-log4j-2.13.1-bin/log4j-appserver-2.13.1-sources.jar
List of .jar files found under ./ (if any) saved as ./jarfiles.txt
List of .jar files matching user-provided Log4j hashes (if any) saved as ./matchinglog4j.txt
이 스크립트는 특정 경로에서 파일 시스템 내의 .jar 파일을 찾고, 이 파일들에 JndiLookup 클래스가 포함되어 있는지 검사합니다. 만약 포함되어 있다면, 스크립트는 .jar 파일의 매니페스트에서 정보를 추출하여 해당 .jar 파일에 Log4j 릴리스가 포함되어 있는지, 그리고 취약한지 여부를 판단하는 데 도움을 줍니다. 마지막으로, 완전성을 위해 SHA-256 해시를 계산합니다.
사용자가 이 스크립트를 "Log4Shell 해시 검사" 스크립트의 보조 도구로 사용할지, 아니면 독립형 도구로 사용할지는 사용자가 결정할 사항입니다.
log4shell_jndilookup_finder.sh <path>
E.g.: sudo ./log4shell_jndilookup_finder.sh /
sudo ./log4shell_jndilookup_finder.sh ./
sudo ./log4shell_jndilookup_finder.sh /opt/tomcat/
log4shell_jndilookup_finder.ps1 -path <path>
E.g.: .\log4shell_jndilookup_finder.ps1 -path c:\
.\log4shell_jndilookup_finder.ps1 -path .\
.\log4shell_jndilookup_finder.ps1 -path c:\opt\tomcat\
OccamSec $ ./log4shell_jndilookup_finder.sh ./
Please be patient, scanning the file system for .jar files starting at ./
.//apache-log4j-2.13.1-bin/log4j-flume-ng-2.13.1.jar
.//apache-log4j-2.13.1-bin/log4j-core-2.13.1.jar
[CUT]
.//apache-log4j-2.13.1-bin/log4j-mongodb2-2.13.1.jar
.//apache-log4j-2.13.1-bin/log4j-to-slf4j-2.13.1-sources.jar
.//apache-log4j-2.13.1-bin/log4j-to-slf4j-2.13.1-javadoc.jar
.//apache-log4j-2.13.1-bin/log4j-appserver-2.13.1-javadoc.jar
.//apache-log4j-2.13.1-bin/log4j-appserver-2.13.1-sources.jar
-------------------------------------------
>>> JndiLookup.class found in: .//apache-log4j-2.13.1-bin/log4j-core-2.13.1.jar
PACKAGE INFORMATION:
Automatic-Module-Name: org.apache.logging.log4j.core
Bundle-Name: Apache Log4j Core
Bundle-SymbolicName: org.apache.logging.log4j.core
Implementation-Title: Apache Log4j Core
Implementation-URL: https://logging.apache.org/log4j/2.x/log4j-core/
Implementation-Vendor-Id: org.apache.logging.log4j
Specification-Title: Apache Log4j Core
VERSION INFORMATION:
Bundle-Version: 2.13.1
Implementation-Version: 2.13.1
Log4jReleaseVersion: 2.13.1
Specification-Version: 2.13.1
SHA-256 hash:
6f38a25482d82cd118c4255f25b9d78d96821d22bab498cdce9cda7a563ca992 *.//apache-log4j-2.13.1-bin/log4j-core-2.13.1.jar
List of .jar files found under ./ (if any) saved as ./jarfiles.txt
Details about .jar files containing 'JndiLookup.class' (if any) saved as ./jndilookup_jarfiles.txt