Skip to content

Commit d06dcc5

Browse files
committed
Added Hostname to csv report
1 parent 8b3f6e3 commit d06dcc5

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
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 vulnerability (log4j 2.15.0).
44

55
### Download
6-
* [log4j2-scan 1.6.1 (Windows x64)](https://github.com/logpresso/CVE-2021-44228-Scanner/releases/download/v1.6.1/logpresso-log4j2-scan-1.6.1-win64.7z)
6+
* [log4j2-scan 1.6.2 (Windows x64)](https://github.com/logpresso/CVE-2021-44228-Scanner/releases/download/v1.6.2/logpresso-log4j2-scan-1.6.2-win64.7z)
77
* If native executable doesn't work, use the JAR instead. 32bit is not supported.
8-
* [log4j2-scan 1.6.1 (Linux x64)](https://github.com/logpresso/CVE-2021-44228-Scanner/releases/download/v1.6.1/logpresso-log4j2-scan-1.6.1-linux.tar.gz)
8+
* [log4j2-scan 1.6.2 (Linux x64)](https://github.com/logpresso/CVE-2021-44228-Scanner/releases/download/v1.6.2/logpresso-log4j2-scan-1.6.2-linux.tar.gz)
99
* If native executable doesn't work, use the JAR instead. 32bit is not supported.
10-
* [log4j2-scan 1.6.1 (Any OS, 10KB)](https://github.com/logpresso/CVE-2021-44228-Scanner/releases/download/v1.6.1/logpresso-log4j2-scan-1.6.1.jar)
10+
* [log4j2-scan 1.6.2 (Any OS, 10KB)](https://github.com/logpresso/CVE-2021-44228-Scanner/releases/download/v1.6.2/logpresso-log4j2-scan-1.6.2.jar)
1111

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

1818
Usage
1919
```
20-
Logpresso CVE-2021-44228 Vulnerability Scanner 1.6.1 (2021-12-16)
20+
Logpresso CVE-2021-44228 Vulnerability Scanner 1.6.2 (2021-12-16)
2121
Usage: log4j2-scan [--fix] target_path
2222
2323
--fix
@@ -60,7 +60,7 @@ On Linux
6060
```
6161
On UNIX (AIX, Solaris, and so on)
6262
```
63-
java -jar logpresso-log4j2-scan-1.6.1.jar [--fix] target_path
63+
java -jar logpresso-log4j2-scan-1.6.2.jar [--fix] target_path
6464
```
6565

6666
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. In most environments, JNDI lookup feature will not be used. However, you must use this option at your own risk. It is necessary to shutdown any running JVM process before applying patch. Start affected JVM process after fix.

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<modelVersion>4.0.0</modelVersion>
77
<groupId>com.logpresso</groupId>
88
<artifactId>log4j2-scanner</artifactId>
9-
<version>1.6.1</version>
9+
<version>1.6.2</version>
1010
<packaging>jar</packaging>
1111
<name>Logpresso Log4j2 Scanner</name>
1212

src/main/java/com/logpresso/scanner/Log4j2Scanner.java

+16-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import java.util.zip.ZipOutputStream;
3535

3636
public class Log4j2Scanner {
37-
private static final String BANNER = "Logpresso CVE-2021-44228 Vulnerability Scanner 1.6.1 (2021-12-16)";
37+
private static final String BANNER = "Logpresso CVE-2021-44228 Vulnerability Scanner 1.6.2 (2021-12-16)";
3838

3939
public enum Status {
4040
NOT_VULNERABLE, MITIGATED, POTENTIALLY_VULNERABLE, VULNERABLE;
@@ -401,12 +401,17 @@ private void writeReportFile() {
401401
FileOutputStream csvStream = null;
402402
try {
403403
csvStream = new FileOutputStream(f);
404-
String header = String.format("Path,Entry,Version,Status,Fixed%n");
404+
String header = String.format("Hostname,Path,Entry,Version,Status,Fixed%n");
405405
csvStream.write(header.getBytes("utf-8"));
406406

407+
String hostname = getHostname();
408+
if (hostname == null)
409+
hostname = "";
410+
407411
for (File file : fileReports.keySet()) {
408412
for (ReportEntry entry : fileReports.get(file)) {
409413
String line = entry.getCsvLine();
414+
line = hostname + "," + line;
410415
csvStream.write(line.getBytes("utf-8"));
411416
}
412417
}
@@ -1090,4 +1095,13 @@ private void ensureClose(ZipFile zipFile) {
10901095
}
10911096
}
10921097
}
1098+
1099+
private static String getHostname() {
1100+
// Try to fetch hostname without DNS resolving for closed network
1101+
if (isWindows) {
1102+
return System.getenv("COMPUTERNAME");
1103+
} else {
1104+
return System.getenv("HOSTNAME");
1105+
}
1106+
}
10931107
}

0 commit comments

Comments
 (0)