Skip to content

Commit

Permalink
Support --report-dir option with --report-json option. No error repor…
Browse files Browse the repository at this point in the history
…t for broken symlink except explicitly specified input path. v2.6.1
  • Loading branch information
xeraph committed Dec 23, 2021
1 parent 283792f commit 3d82e03
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 22 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
log4j2-scan is a single binary command-line tool for CVE-2021-44228 vulnerability scanning and mitigation patch. It also supports nested JAR file scanning and patch. It also detects CVE-2021-45046 (log4j 2.15.0), CVE-2021-45105 (log4j 2.16.0), CVE-2021-4104 (log4j 1.x), and CVE-2021-42550 (logback 0.9-1.2.7) vulnerabilities.

### Download
* [log4j2-scan 2.6.0 (Windows x64, 7z)](https://github.com/logpresso/CVE-2021-44228-Scanner/releases/download/v2.6.0/logpresso-log4j2-scan-2.6.0-win64.7z)
* [log4j2-scan 2.6.0 (Windows x64, zip)](https://github.com/logpresso/CVE-2021-44228-Scanner/releases/download/v2.6.0/logpresso-log4j2-scan-2.6.0-win64.zip)
* [log4j2-scan 2.6.1 (Windows x64, 7z)](https://github.com/logpresso/CVE-2021-44228-Scanner/releases/download/v2.6.1/logpresso-log4j2-scan-2.6.1-win64.7z)
* [log4j2-scan 2.6.1 (Windows x64, zip)](https://github.com/logpresso/CVE-2021-44228-Scanner/releases/download/v2.6.1/logpresso-log4j2-scan-2.6.1-win64.zip)
* If you get `VCRUNTIME140.dll not found` error, install [Visual C++ Redistributable](https://docs.microsoft.com/en-US/cpp/windows/latest-supported-vc-redist?view=msvc-170).
* If native executable doesn't work, use the JAR instead. 32bit is not supported.
* 7zip is available from www.7zip.org, and is open source and free.
* [log4j2-scan 2.6.0 (Linux x64)](https://github.com/logpresso/CVE-2021-44228-Scanner/releases/download/v2.6.0/logpresso-log4j2-scan-2.6.0-linux.tar.gz)
* [log4j2-scan 2.6.0 (Linux aarch64)](https://github.com/logpresso/CVE-2021-44228-Scanner/releases/download/v2.6.0/logpresso-log4j2-scan-2.6.0-linux-aarch64.tar.gz)
* [log4j2-scan 2.6.1 (Linux x64)](https://github.com/logpresso/CVE-2021-44228-Scanner/releases/download/v2.6.1/logpresso-log4j2-scan-2.6.1-linux.tar.gz)
* [log4j2-scan 2.6.1 (Linux aarch64)](https://github.com/logpresso/CVE-2021-44228-Scanner/releases/download/v2.6.1/logpresso-log4j2-scan-2.6.1-linux-aarch64.tar.gz)
* If native executable doesn't work, use the JAR instead. 32bit is not supported.
* [log4j2-scan 2.6.0 (Mac OS)](https://github.com/logpresso/CVE-2021-44228-Scanner/releases/download/v2.6.0/logpresso-log4j2-scan-2.6.0-darwin.zip)
* [log4j2-scan 2.6.0 (Any OS, 620KB)](https://github.com/logpresso/CVE-2021-44228-Scanner/releases/download/v2.6.0/logpresso-log4j2-scan-2.6.0.jar)
* [log4j2-scan 2.6.1 (Mac OS)](https://github.com/logpresso/CVE-2021-44228-Scanner/releases/download/v2.6.1/logpresso-log4j2-scan-2.6.1-darwin.zip)
* [log4j2-scan 2.6.1 (Any OS, 620KB)](https://github.com/logpresso/CVE-2021-44228-Scanner/releases/download/v2.6.1/logpresso-log4j2-scan-2.6.1.jar)

### Build
* [How to build Native Image](https://github.com/logpresso/CVE-2021-44228-Scanner/wiki/FAQ#how-to-build-native-image)
Expand All @@ -22,7 +22,7 @@ Just run log4j2-scan.exe or log4j2-scan with target directory path. The logpress

Usage
```
Logpresso CVE-2021-44228 Vulnerability Scanner 2.6.0 (2021-12-23)
Logpresso CVE-2021-44228 Vulnerability Scanner 2.6.1 (2021-12-23)
Usage: log4j2-scan [--scan-log4j1] [--fix] target_path1 target_path2
-f [config_file_path]
Expand Down Expand Up @@ -104,7 +104,7 @@ On Linux
```
On UNIX (AIX, Solaris, and so on)
```
java -jar logpresso-log4j2-scan-2.6.0.jar [--fix] target_path
java -jar logpresso-log4j2-scan-2.6.1.jar [--fix] target_path
```

If you add `--fix` option, this program will copy vulnerable original JAR file to .bak file, and create new JAR file without `org/apache/logging/log4j/core/lookup/JndiLookup.class` entry. All .bak files are archived into the single zip file which is named by `log4j2_scan_backup_yyyyMMdd_HHmmss.zip`, then deleted safely. In most environments, JNDI lookup feature will not be used. However, you must use this option at your own risk. You can easily restore original vulnerable JAR files using `--restore` option.
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.logpresso</groupId>
<artifactId>log4j2-scanner</artifactId>
<version>2.6.0</version>
<version>2.6.1</version>
<packaging>jar</packaging>
<name>Logpresso Log4j2 Scanner</name>

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/logpresso/scanner/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,6 @@ public static Configuration parseArguments(String[] args) throws Exception {

i++;
} else if (args[i].equals("--report-dir")) {
c.reportCsv = true;

if (args.length > i + 1) {
String pattern = args[i + 1];
if (pattern.startsWith("--"))
Expand Down Expand Up @@ -330,6 +328,9 @@ else if (!reportFile.isDirectory())
if (c.reportPath != null && (!c.reportCsv && !c.reportJson))
c.reportCsv = true;

if (c.reportDir != null && (!c.reportCsv && !c.reportJson))
c.reportCsv = true;

// verify drive letters
c.verifyDriveLetters();

Expand Down
18 changes: 11 additions & 7 deletions src/main/java/com/logpresso/scanner/Detector.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ public List<ReportEntry> getReportEntries(File f) {
}

protected void scanJarFile(File jarFile, boolean fix) {
scanJarFile(jarFile, fix, Charset.forName("utf-8"));
}

protected void scanJarFile(File jarFile, boolean fix, Charset charset) {
InputStream is = null;

Charset altCharset = null;
Expand All @@ -125,8 +129,8 @@ protected void scanJarFile(File jarFile, boolean fix) {
DetectResult result = null;

try {
it = openZipFileIterator(jarFile, is, 0);
result = scanStream(jarFile, it, new ArrayList<String>(), Charset.forName("cp437"), 0);
it = openZipFileIterator(jarFile, is, charset, 0);
result = scanStream(jarFile, it, new ArrayList<String>(), Charset.forName("utf-8"), 0);
} catch (IllegalArgumentException e) {
// second try with system encoding or alternative encoding
altCharset = Charset.defaultCharset();
Expand All @@ -137,7 +141,7 @@ protected void scanJarFile(File jarFile, boolean fix) {
IoUtils.ensureClose(is);
is = new FileInputStream(jarFile);

it = openZipFileIterator(jarFile, is, 0);
it = openZipFileIterator(jarFile, is, charset, 0);
result = scanStream(jarFile, it, new ArrayList<String>(), altCharset, 0);
}

Expand Down Expand Up @@ -174,16 +178,16 @@ else if (result.isPotentiallyVulnerable())
}
}

private ZipFileIterator openZipFileIterator(File jarFile, InputStream is, int depth) throws IOException {
private ZipFileIterator openZipFileIterator(File jarFile, InputStream is, Charset charset, int depth) throws IOException {
// Try to avoid 'only DEFLATED entries can have EXT descriptor' error
// See https://bugs.openjdk.java.net/browse/JDK-8143613
try {
return new ZipFileIterator(new ZipArchiveInputStream(new DummyInputStream(is)));
} catch (Exception e) {
if (depth == 0)
return new ZipFileIterator(jarFile);
return new ZipFileIterator(jarFile, charset);

return new ZipFileIterator(new ZipInputStream(new DummyInputStream(is)));
return new ZipFileIterator(new ZipInputStream(new DummyInputStream(is), charset));
}
}

Expand Down Expand Up @@ -244,7 +248,7 @@ private DetectResult scanStream(File jarFile, ZipFileIterator it, List<String> p
if (ZipUtils.isScanTarget(entry.getName(), config.isScanZip())) {
ZipFileIterator nestedIt = null;
try {
nestedIt = openZipFileIterator(jarFile, is, depth + 1);
nestedIt = openZipFileIterator(jarFile, is, charset, depth + 1);
pathChain.add(entry.getName());

DetectResult nestedResult = scanStream(jarFile, nestedIt, pathChain, charset, depth + 1);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/logpresso/scanner/Log4j2Scanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import com.logpresso.scanner.utils.ZipUtils;

public class Log4j2Scanner {
public static final String VERSION = "2.6.0";
public static final String VERSION = "2.6.1";
public static final String RELEASE_DATE = "2021-12-23";
public static final String BANNER = "Logpresso CVE-2021-44228 Vulnerability Scanner " + VERSION + " (" + RELEASE_DATE + ")";

Expand Down Expand Up @@ -428,7 +428,7 @@ private void traverse(File f, int depth) {

String path = f.getAbsolutePath();

if (!f.exists()) {
if (depth == 0 && !f.exists()) {
reportError(f, "File not found");
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
Expand All @@ -21,8 +22,8 @@ public class ZipFileIterator implements Closeable {
private ZipEntry firstEntry;
private ZipEntry nextEntry;

public ZipFileIterator(File file) throws IOException {
this.zipFile = new ZipFile(file);
public ZipFileIterator(File file, Charset charset) throws IOException {
this.zipFile = new ZipFile(file, charset);
e = zipFile.entries();
if (e.hasMoreElements()) {
firstEntry = e.nextElement();
Expand Down

0 comments on commit 3d82e03

Please sign in to comment.