Giter VIP home page Giter VIP logo

local-log4j-vuln-scanner's Introduction

Simple local log4j vulnerability scanner

logo

(Written in Go because, you know, "write once, run anywhere.")

This is a simple tool that can be used to find vulnerable instances of log4j 1.x and 2.x in installations of Java software such as web applications. JAR and WAR archives are inspected and class files that are known to be vulnerable are flagged. The scan happens recursively: WAR files containing WAR files containing JAR files containing vulnerable class files ought to be flagged properly.

Currently recognized vulnerabilities are:

  • CVE-2019-17571 (1.x)
  • CVE-2021-44228
  • CVE-2021-45105
  • CVE-2021-45046 (not reported by default due to lower severity)
  • CVE-2021-44832 (not reported by default due to lower severity)

The scan tool currently checks for known build artifacts that have been obtained through Maven. From-source rebuilds as they are done for Linux distributions may not be recognized.

Also included is a simple patch tool that can be used to patch out bad classes from JAR files by rewriting the ZIP archive structure.

Binaries for x86_64 Windows, Linux, MacOSX for tagged releases are provided via the Releases page.

Using the scanner

$ ./local-log4j-vuln-scanner [--verbose] [--quiet] \
    [--ignore-v1] [--ignore-vulns=...] \
    [--exclude /path/to/exclude …] \
	[--scan-network] \
	[--log /path/to/file.log] \
    /path/to/app1 /path/to/app2 …

The --verbose flag will show every .jar and .war file checked, even if no problem is found.

The --quiet flag will supress output except for indicators of a known vulnerability.

The --ignore-v1 flag will exclude checks for log4j 1.x vulnerabilities.

The --ignore-vulns flag allows excluding checks for specific vulnerabilities. e.g. -ignore-vulns=CVE-2021-45046,CVE-2021-44832. To check for all known vulnerabilities, pass an empty list like so: -ignore-vulns=

The --log flag allows everythig to be written to a log file instead of stdout/stderr.

Use the --exclude flag to exclude subdirectories from being scanned. Can be used multiple times.

The --scan-network flag tells the scanner to search network filesystems (disabled by default). This has not been implemented for Windows.

If class files indicating one of the vulnerabilities are found, messages like the following are printed to standard output:

./local-log4j-vuln-scanner - a simple local log4j vulnerability scanner

Checking for vulnerabilities: CVE-2019-17571, CVE-2021-44228, CVE-2021-45105
examining /path/to/vuln/log4shell-vulnerable-app-0.0.1-SNAPSHOT.war
indicator for vulnerable component found in /path/to/vuln/Downloads/log4shell-vulnerable-app-0.0.1-SNAPSHOT.war::WEB-INF/lib/log4j-core-2.14.1.jar (org/apache/logging/log4j/core/net/JndiManager.class): JndiManager.class log4j 2.14.0-2.14.1 CVE-2021-44228, CVE-2021-45105

Scan finished

Using the patch tool

Caution: Use this at your own risk and keep the original JAR files.

$ ./local-log4j-vuln-patcher log4j-core-2.14.1.jar log4j-core-2.14.1-patched.jar
Filtering out org/apache/logging/log4j/core/pattern/MessagePatternConverter.class (log4j 2.14)
Filtering out org/apache/logging/log4j/core/net/JndiManager.class (log4j 2.14.0-2.14.1)

Writing to log4j-core-2.14.1-patched.jar done

Building from source

Install a Go compiler.

Run the following commands in the checked-out repository:

go build -o local-log4j-vuln-scanner ./scanner
go build -o local-log4j-vuln-patcher ./patcher

(Add the appropriate .exe extension on Windows systems, of course.)

License

GNU General Public License, version 3

Author

Hilko Bengen <[email protected]>

local-log4j-vuln-scanner's People

Contributors

cypriani avatar emrahkaya avatar hawson avatar hillu avatar lbruder avatar ljakob avatar simoesp avatar simon04 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

local-log4j-vuln-scanner's Issues

unable to unzip jar files

While scanning nested .jar files, the scanner exiting with an error:

./local-log4j-vuln-scanner  --exclude /proc  /
local-log4j-vuln-scanner - a simple local log4j vulnerability scanner

OUTPUT
cant't open JAR file: /../../../FOO-1.0.0-BAR.jar (size 19165951): zip: not a valid zip file
….

manual unzipping the file work's fine

unzip -l /../../../FOO-1.0.0-BAR.jar
Archive:  /../../../FOO-1.0.0-BAR.jar
warning [ /../../../FOO-1.0.0-BAR.jar ]:  8500 extra bytes at beginning or within zipfile
  (attempting to process anyway)

False positive log4j-core-2.15.0.jar

Since CVE-2021-44228 is fixed in 2.15.0, this scanner should not report log4j-core-2.15.0.jar

> curl -LO https://repo1.maven.org/maven2/org/apache/logging/log4j/log4j-core/2.15.0/log4j-core-2.15.0.jar

> sha256sum log4j-core-2.15.0.jar 
419a8512895971b7b4f4f33e620d361254e5c9552b904b0474b09ddd4a6a220b  log4j-core-2.15.0.jar

> ./local-log4j-vuln-scanner - a simple local log4j vulnerability scanner
indicator for vulnerable component found in log4j-core-2.15.0.jar (org/apache/logging/log4j/core/net/JndiManager$1.class): log4j 2.13.0-2.15.0
Scan finished

To address this, the scanner could cross-check the hash of MessagePatternConverter from apache/logging-log4j2#608.

Segfaults on CentOS 7/8

go run log4j-vuln-finder.go /
/tmp/go-build257162864/b001/exe/log4j-vuln-finder - a simple local log4j vulnerability scanner

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x4c8075]

goroutine 1 [running]:
main.main.func1(0xc0001cb6a0, 0x11, 0x0, 0x0, 0x5195c0, 0xc000202030, 0x0, 0x0)
        /home/<USER>/local-log4j-vuln-scanner/log4j-vuln-finder.go:120 +0x55
path/filepath.walk(0xc000480f10, 0xf, 0x51a320, 0xc0001fd930, 0x4fe030, 0x0, 0x0)
        /usr/lib/golang/src/path/filepath/path.go:380 +0x213
path/filepath.walk(0xc000480ce0, 0xc, 0x51a320, 0xc0001fc9c0, 0x4fe030, 0x0, 0x0)
        /usr/lib/golang/src/path/filepath/path.go:384 +0x2fe
path/filepath.walk(0xc00013ff16, 0x5, 0x51a320, 0xc00030c8f0, 0x4fe030, 0x0, 0x0)
        /usr/lib/golang/src/path/filepath/path.go:384 +0x2fe
path/filepath.walk(0x7ffdfd65d66e, 0x1, 0x51a320, 0xc00005cdd0, 0x4fe030, 0x0, 0x60)
        /usr/lib/golang/src/path/filepath/path.go:384 +0x2fe
path/filepath.Walk(0x7ffdfd65d66e, 0x1, 0x4fe030, 0x31, 0xc000062f68)
        /usr/lib/golang/src/path/filepath/path.go:406 +0x105
main.main()
        /home/<USER>/local-log4j-vuln-scanner/log4j-vuln-finder.go:119 +0x208
exit status 2

Patcher does not seem to fix WAR files

Hi

I have noticed that upon rerunning the scanner against WAR files that have had the patcher run against them, the same vulnerability is showing up. For example, where ws.war.original.war is the original (unpatched) copy of a WAR file and ws.war is the patched copy:

# ./local-log4j-vuln-scanner-0.8.1 --ignore-v1 --exclude /proc --exclude /run/user /var/lib/docker/overlay2/02ac4e5dc4f93ebd2d37f5df4d517473cbe2384d908fa0c016a5499c51684828/diff/usr/local/tomcat/webapps
local-log4j-vuln-scanner-0.8.1 - a simple local log4j vulnerability scanner

indicator for vulnerable component found in /var/lib/docker/overlay2/02ac4e5dc4f93ebd2d37f5df4d517473cbe2384d908fa0c016a5499c51684828/diff/usr/local/tomcat/webapps/ws.war::WEB-INF/lib/log4j-core-2.3.jar (org/apache/logging/log4j/core/net/JndiManager.class): log4j 2.1-2.3
indicator for vulnerable component found in /var/lib/docker/overlay2/02ac4e5dc4f93ebd2d37f5df4d517473cbe2384d908fa0c016a5499c51684828/diff/usr/local/tomcat/webapps/ws.war.original.war::WEB-INF/lib/log4j-core-2.3.jar (org/apache/logging/log4j/core/net/JndiManager.class): log4j 2.1-2.3

Scan finished

I should expect the vulnerability not to be flagged in the patched version.

Kind regards.

Detection flags jar files with JndiLookup.class removed (but JndiManager.class present)

Thanks for the great tool!
I understand that the detection is done by checking for presence of the JndiManager.class in versions 2.1 and up.

However my understanding is that removing JndiLookup.class should be sufficient to mitigate the issue. I know that there is some conflicting information regarding this out there (whether to remove both the lookup and the manager class or only the lookup), but based on the official communication by apache removing the JndiLookup.class should be sufficient:

Otherwise, in any release other than 2.16.0, you may remove the JndiLookup class from the classpath: zip -q -d log4j-core-*.jar org/apache/logging/log4j/core/lookup/JndiLookup.class

https://logging.apache.org/log4j/2.x/security.html#CVE-2021-45046

Is there any concrete information out there that JndiManager.class really needs to be removed too? If not it could make sense to change the detection to be based on the Lookup's class presence for accurate results

ignore-v1 not working

Hi,

the switch seems not to be active in 0.6

flag provided but not defined: -ignore-v1
Usage of ./files/local-log4j-vuln-scanner:
  -exclude value
        paths to exclude
  -log string
        log file to write output to
  -verbose
        log every archive file considered

Thanks in advance.

Can't read magic from JAR file member

With the latest version of the tool I am getting lots of warning messages to STDOUT (not STDERR) like these. Does the tool need to warn about not being able to read magic?

can't read magic from JAR file member: /opt/android-studio/lib/batik-codec-1.12.0-8.jar (org/apache/batik/ext/awt/image/codec/properties): EOF
can't read magic from JAR file member: /opt/android-studio/lib/istack-commons-runtime-3.0.7.jar (.gitkeep): EOF
can't read magic from JAR file member: /opt/android-studio/lib/resources_en.jar (fileTemplates/internal/CMakeLists.txt.cmake.ft): EOF
can't read magic from JAR file member: /opt/android-studio/lib/spellchecker.jar (com/intellij/spellchecker/excluded.dic): EOF
can't read magic from JAR file member: /opt/android-studio/lib/tips-intellij-idea-community-193.4.jar (tips/bundle.version): EOF
can't read magic from JAR file member: /opt/android-studio/lib/xmlpull-1.1.3.1.jar (XMLPULL_1_1_3_1_VERSION): EOF
can't read magic from JAR file member: /opt/android-studio/lib/xpp3_min-1.1.4c.jar (XPP3_1.1.4c_MIN_VERSION): EOF

command line option for jar file matching

In the scanner, the file name extensions are hard-coded to jar/war/ear; at least rar (resource adapter archive) is missing.
It would be a great improvement to configure the file names to match on the command line, e.g., log4j-vuln-scanner --jarfiles jar,war,ear,rar

Strange "indicator" message from scanner

Hi

The scanner (both versions 0.8.1 and 0.9) gives a strange "indicator" message for one of our JARs:

indicator for vulnerable component found in _<path>_/neo4j-logging-4.3.2.jar (org/neo4j/logging/shaded/log4j/core/net/JndiManager.class): JndiManager class missing new error message string literal

Is this working as intended?

This is probably strongly related to issue #34 .

Kind regards.

New magic number check failure

Hi

Using release 0.9, the scanner is now giving very many "can't read magic from JAR file member" messages. This did not happen in release 0.8.1. I'm not sure that the fix that went into 0.9 is working as you intended.

Kind regards.

Usage instructions?

Possibly due to my own lack of experience with go, but the Readme instructs using ./log4j-vuln-scanner but there is no executable by that name in this repo. Is this something that would be created in a previous step?

In the 0.4 release there is a ".macos" file. However, this is not a standard extension for macos executables. Should this be run without that extension?

How to use filter.go

With Windows 10, running "go run main.go <filepath>" (within scanner) does well.
With Windows 10, running "go run main.go -help" (within scanner) does well.
With Windows 10, running "go run filter.go" fails with "package command-line-arguments is not a main package".
With Windows 10, running "go run filter.go -help" fails with "package command-line-arguments is not a main package".
Pardon I'm a newbie. Any hints?

Scans network shares on macOS

Because Apple is dumb, they've placed both the Data partition and network shares in /System/Volumes

Can we add a flag to have it not scan network shares?

Unable to scan network filesystems

We are using your scanner tool to scan user home directories which are hosted on AFS, this used to work perfectly but the latest version now seems to ignore them. For example:

"""
./local-log4j-vuln-scanner /afs/example.org/user/bob
local-log4j-vuln-scanner - a simple local log4j vulnerability scanner

Checking for vulnerabilities: CVE-2019-17571, CVE-2021-44228, CVE-2021-45105
Skipping /afs/example.org/user/bob: pseudo or network filesystem

Scan finished
"""

I can see this affecting other sites which similarly use NFS or samba for user home directories. Could the skipping of network file please be made optional.

Thanks,

Stephen Quinney

Flagging 1.X Versions

Is it intended that this utility will flag 1.X versions? It has been stated that "As log4j 1.x does NOT offer a look-up mechanism, it does NOT suffer from CVE-2021-44228". Does this mean that 1.X versions can and should be disregarded?

Thx

Even with exclude, tool scans folders

Issue is that the walking of the root includes mounted drives, which causes it to walk very large filesystems, and this caused OOM on our servers.

installation with go install

Could you please add a feature to install the scanner using "go install" ?

eg:
go install github.com/hillu/local-log4j-vuln-scanner@latest

x86 support?

Sorry, really new to Go. I can't seem to get this to work on windows x86 machines. I repeatedly get a message, This executable is not compatible with the version of windows you are running. It is only happening on win7 x86 intel machines. Am I just missing something obvious?

(-)-exclude flag

There is a "problem" with excluding paths in Linux (maybe intended, but then needs to be added to help):

Usage can be:
[-]-exclude[=]/path/to/exclude
[-]-exclude[=]/path/to/exclude/*
What does not work is:
[-]-exclude[=]/path/to/exclude/ # when path ends with "/" is not excluded (often when auto-completion is used)

Help is not clear as well:

-exclude value
paths to exclude

Actually it is only one path_ but you can specify exclude multiple times.

BTW: Thanks for the scanner!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.