Scan all AWS EC2 instances in a region for potentially vulnerable log4j versions

ec2-log4j-scan

Scan all AWS EC2 instances in a region for potentially vulnerable log4j versions.

This is a clumsy but effective tool which takes output from the AWS CLI about running EC2 instances and tries (in parallel) to check each running instance via ssh for the log4j versions that are vulnerable to CVE-2021-44228.

Quick guide

These instructions assume a macOS or Linux-ish environment. Windows folks should be able to follow along, but names and locations may be slightly different.

Get and install the AWS CLI v2. Get and install Go.

At a terminal:

  • Run aws configure and supply your (sufficiently privileged!) AWS key ID and secret access key, along with your favorite region.
  • Optionally run mkdir -p go/bin if you don't already have a handy place where Go binaries will be installed.
  • Run go install github.com/charrington-strib/ec2-log4j-scan@latest -- This will create go/bin/ec2-log4j-scan
  • Configure your environment:
    • The utility will search for private key files in ~/.ssh/ -- if you store them elsewhere, run export SSH_KEY_LOCATION=/path/to/keys
    • The utility assumes keys end with .pem -- if you use something else, run export SSH_KEY_EXT=.ext
    • The utility will try the username ubuntu by default -- to specify your own username, run export SSH_DEFAULT_USERNAME=geoffrey
    • The utility will use the standard SSH port of 22 -- but you can override this with export SSH_DEFAULT_PORT=2222
    • The AWS CLI will use your default AWS region; to set a specific region, run export AWS_REGION=xx-region-1
  • Run aws ec2 describe-instances --query "Reservations[].Instances[].{i:InstanceId,s:State.Name,k:KeyName,d:PublicDnsName}" | go/bin/ec2-log4j-scan

If you have a bunch of instances, you will probably see errors. If you have security groups that block inbound ssh, you will definitely see errors. The utility uses the standard output separation of stderr and stdout, so if you are trying to get the lay of the land, you can ignore errors by adding 2>/dev/null to the end of your invocation.

Theory

The general premise of this utility isn't to be precise or perfect, but to scan hundreds or thousands of instances in a more-or-less automated and non-invasive way. For the first pass, it will scan /proc looking for any running process that looks like a Java binary. This involves checking the full path of the running executable using readlink and comparing with common java-ish strings: jre, jvm, jdk, etc. This is intentionally lazy and broad. For any instances that match, it will then search the root partition for .jar files; with those, it will extract the manifest data looking for telltale Log4J version strings that are vulnerable.

Currently this extraction is done on the instance. If the instance lacks the unzip utility, it may be possible to add a fallback where the jar file is downloaded via ssh, but this would not be practical at a large scale. We may also be able to use the jar utility if that's present, but that violates the goal of being minimally invasive, as it will extract to storage.

We currently don't assume the name of the jar file is accurate or honest. It's possible this is being too paranoid, but the jar file specification says that the filenames are not semantically important, and therefore we can't assume they haven't been renamed. We also don't handle the case where the jar file was manually built rather than being the upstream jar version, and therefore may not include the specific manifest information, but at this point that's a hard bell to unring.

TODO

One future improvement may be to gather sha1 sums of all known-vulnerable jar files and include that as an optional detection step. This should be reasonably simple to extend from the current regex-based matching.

Similar Resources

CLI client (and Golang module) for deps.dev API. Free access to dependencies, licenses, advisories, and other critical health and security signals for open source package versions.

CLI client (and Golang module) for deps.dev API. Free access to dependencies, licenses, advisories, and other critical health and security signals for open source package versions.

depsdev CLI client (and Golang module) for deps.dev API. Free access to dependencies, licenses, advisories, and other critical health and security sig

May 11, 2023

Scans and catches callbacks of systems that are impacted by Log4J Log4Shell vulnerability across specific headers.

Scans and catches callbacks of systems that are impacted by Log4J Log4Shell vulnerability across specific headers.

Log4ShellScanner Scans and catches callbacks of systems that are impacted by Log4J Log4Shell vulnerability across specific headers. Very Beta Warning!

Jun 17, 2022

Divd 2021 00038 log4j scanner

divd-2021-00038--log4j-scanner This scanner will recursively scan paths including archives for vulnerable log4j versions and org/apache/logging/log4j/

Nov 9, 2022

Log4j 2 (CVE-2021-44228) vulnerability scanner for Windows OS

Log4j 2 (CVE-2021-44228) vulnerability scanner for Windows OS

log4j-scanner Log4j 2 (CVE-2021-44228) vulnerability scanner for Windows OS. Example Usage Usage .\log4j-scanner.exe Terminal is used to output resul

Dec 13, 2021

Scanner to send specially crafted requests and catch callbacks of systems that are impacted by Log4J Log4Shell vulnerability (CVE-2021-44228)

scan4log4shell Scanner to send specially crafted requests and catch callbacks of systems that are impacted by Log4J Log4Shell vulnerability CVE-2021-4

Sep 17, 2022

Tool to check whether one of your applications is affected by a vulnerability in log4j: CVE-2021-44228

Tool to check whether one of your applications is affected by a vulnerability in log4j: CVE-2021-44228

log4shell.tools log4shell.tools is a tool allows you to run a test to check whether one of your applications is affected by a vulnerability in log4j:

Nov 2, 2022

Just simple log4j scanner With Golang

Just simple log4j scanner With Golang

Summary Yesterdy which is Decemeber 12, 2021. One of my friend send me a message on twitter that he want me to write a script that brute force list of

Dec 26, 2022

Utility to safely fetch Java class files being served by LDAP servers. Includes deobfuscator for common Log4J URL obfuscation techniques

ldap-get Utility to safely fetch Java class files being served by LDAP servers,

Nov 9, 2022

Hotdog is a set of OCI hooks used to inject the Log4j Hot Patch into containers.

Hotdog Hotdog is a set of OCI hooks used to inject the Log4j Hot Patch into containers. How it works When runc sets up the container, it invokes hotdo

Nov 12, 2022
Find vulnerable versions of Log4j on Linux

log4jtool Find vulnerable versions of Log4j on Linux This tool does not change a

Jan 14, 2022
Simple local scanner for vulnerable log4j instances

Simple local log4j vulnerability scanner (Written in Go because, you know, "write once, run anywhere.") This is a simple tool that can be used to find

Dec 21, 2022
Scans files for .jars potentially vulnerable to Log4Shell (CVE-2021-44228) by inspecting the class paths inside the .jar.

log4shelldetect Scans a file or folder recursively for jar files that may be vulnerable to Log4Shell (CVE-2021-44228) by inspecting the class paths in

Dec 15, 2022
Look for JAR files that vulnerable to Log4j RCE (CVE‐2021‐44228)
Look for JAR files that vulnerable to Log4j RCE (CVE‐2021‐44228)

Look4jar Look for JAR files that vulnerable to Log4j RCE (CVE‐2021‐44228) Objectives It differs from some other tools that scan for vulnerable remote

Dec 25, 2022
Application trying to detect processes vulnerable to log4j JNDI exploit

Log4j JNDI Jar Detector Purpose This application is able to detect jars used by

Jan 25, 2022
Log4j detector and reporting server for scalable detection of vulnerable running processes.

Log4j Detector A client and reporting server to identify systems vulnerable to Log4j at scale. This work is based on Stripe's Remediation Tools, but w

Apr 8, 2022
Log4j-scanner tools - Support for multiple scan method

Log4j-scanner URL mode (fuzzing url with header, payload) go run . url -h Usage

Sep 7, 2022
Auto scan log4j bug with excel of server list

Log4JCheck Auto scan log4j bug with excel of server list. Please read https://ww

Dec 24, 2021
A vulnerable graphQL application, for testing purposes

Vulnerable-GoQL Vulnerable-GoQL is an web API which implements main security breach.

Jul 31, 2021
Finds an identifiable hash value for each version of GitLab vulnerable to CVE-2021-22205

Finds an identifiable hash value for each version of GitLab vulnerable to CVE-2021-22205

Sep 20, 2022