关联漏洞
描述
Scan systems and docker images for potential log4j vulnerabilities. Able to patch (remove JndiLookup.class) from layered archives. Will detect in-depth (layered archives jar/zip/tar/war and scans for vulnerable Log4J versions (CVE-2021-44228, CVE-2021-45046 and CVE-2021-45105). Binaries for Windows, Linux and OsX, but can be build on each platform supported by supported Golang.
介绍
# divd-2021-00038--log4j-scanner
This scanner will recursively scan paths including archives for vulnerable log4j versions and `org/apache/logging/log4j/core/lookup/JndiLookup.class` files.
Currently the allow list defines non exploitable versions, in this case log4j-core 2.17.0 and 2.12.3.

# Features
* scans recursively through all archives in archives in archives in archives etc
* scan for known log4j libraries (sha256 hash)
* scan for JndiLookup.class files
* fast
* show related CVE's found by version
* detects class files with different extensions (eg .ezclass)
* scans through all layers of local- and remote docker images
* *binary* versions available for Windows, Linux and MacOS
* includes *patching*, which will delete (again recursively) the JndiLookup class
# References
| CVE | References |
|-----|------------|
| CVE-2021-44228 | https://www.cve.org/CVERecord?id=CVE-2021-44228 |
| CVE-2021-45046 | https://www.cve.org/CVERecord?id=CVE-2021-45046 |
| CVE-2021-45105 | https://www.cve.org/CVERecord?id=CVE-2021-45105 |
| CVE-2021-44832 | https://www.cve.org/CVERecord?id=CVE-2021-44832 |
# Scanning
## Usage
### Windows
```bash
$ divd-2021-00038--log4j-scanner.exe {target-path}
```
### Linux / OSX / FreeBSD
```bash
$ divd-2021-00038--log4j-scanner {target-path}
```
### Docker containers
Using the tool you can now also scan containers:
```bash
$ ./divd-2021-00038--log4j-scanner scan-image logstash:7.16.1
```
or local images:
```bash
$ ./divd-2021-00038--log4j-scanner scan-image --local {sha256|pattern}
$ ./divd-2021-00038--log4j-scanner scan-image --local log4shell:latest
$ ./divd-2021-00038--log4j-scanner scan-image --local 4949add9e671
# scan all local images
$ ./divd-2021-00038--log4j-scanner scan-image --local
```
You can also patch the image:
```bash
$ docker save log4shell > ./log4shell-image.tar
$ ./divd-2021-00038--log4j-scanner ./log4shell-image.tar
$ ./divd-2021-00038--log4j-scanner patch ./log4shell-image.tar
$ cat ./log4shell-image.tar.patch | docker load
```
Comparing both tars will give the following differences:
```
Binary files ../2/BOOT-INF/lib/log4j-core-2.14.1.jar and ./BOOT-INF/lib/log4j-core-2.14.1.jar differ
Binary files ../2/app/spring-boot-application.jar and ./app/spring-boot-application.jar differ
Binary files ../2/b0d66ac73d47865118cfb9a1244f1508d94ea938da1eb78c2db20bd2e1a6629a/layer.tar and ./b0d66ac73d47865118cfb9a1244f1508d94ea938da1eb78c2db20bd2e1a6629a/layer.tar differ
Only in ./org/apache/logging/log4j/core/lookup: JndiLookup.class
```
# Patching
We've added preleminary support for recursively patching files. This is very experimental, be careful with this feature. Currently patching only works with
the archive (jar / tar ) file. The patch will create a new `.patch`` file that needs to replace the original file. This is on purpose a manual process, as it needs to be timed with restarting services. Make sure you'll create a backup of the original file before replacing it. After patching you can scan again to make sure you didn't miss any files. Currently plain .class files in folders won't be patched, as they can be removed safe manually.
The `.patch` file will be exactly the same as the original file, without `JndiLookup.class`. This should be sufficient to mitigate this issue, while waiting for upgrades. Make sure to make backups and test thoroughly.
Patch will refuse to run on folders, as a precaution. Just point patch to the vulnerable archive.
## Usage
### Windows
```bash
$ divd-2021-00038--log4j-scanner.exe patch {target-path}
```
### Linux / OSX / FreeBSD
```bash
divd-2021-00038--log4j-scanner patch {target-path}
```
## Build from source
Requirements:
- [Go 1.16 or newer](https://golang.org/dl/)
### For development
```bash
$ git clone "https://github.com/dtact/divd-2021-00038--log4j-scanner.git"
$ go build -o ./.builds/divd-2021-00038--log4j-scanner ./main.go
```
# Copyright and license
Code and documentation copyright 2021 Remco Verhoef (DTACT).
Code released under the MIT license.
文件快照
[4.0K] /data/pocs/5efc5d40bc059e1a2f7df46041dd2642cfb71464
├── [4.0K] app
│ ├── [ 27K] app.go
│ ├── [ 210] config.go
│ ├── [ 298] db.go
│ ├── [2.1K] options.go
│ ├── [ 11K] patch.go
│ ├── [ 205] result.go
│ ├── [9.2K] scan.go
│ ├── [6.9K] scan_image_other.go
│ └── [ 283] scan_image_windows.go
├── [4.0K] build
│ └── [ 457] constants.go
├── [4.0K] cmd
│ └── [7.7K] cmd.go
├── [5.1K] CODE_OF_CONDUCT.md
├── [3.3K] go.mod
├── [106K] go.sum
├── [4.0K] images
│ ├── [4.3M] log4j-solr.gif
│ └── [321K] log4j-solr.png
├── [1.1K] LICENSE
├── [ 231] main.go
├── [1.9K] Makefile
└── [4.0K] README.md
4 directories, 20 files
备注
1. 建议优先通过来源进行访问。
2. 如果因为来源失效或无法访问,请发送邮箱到 f.jinxu#gmail.com 索取本地快照(把 # 换成 @)。
3. 神龙已为您对POC代码进行快照,为了长期维护,请考虑为本地POC付费,感谢您的支持。