Submit solution
Points:
7
Time limit:
2.5s
Memory limit:
64M
Author:
Problem type
Allowed languages
Java
Please call the method flag()
in the class Secret
.
Download the Java agent here.
Download the source code of the agent here.
You can test locally using the command java -javaagent:p3_agent.jar YourClass
.
Source Code
File: Agent.java
import java.lang.instrument.*;
import java.lang.reflect.ReflectPermission;
import java.security.ProtectionDomain;
import java.security.*;
class SecurityIsGood extends RuntimeException {}
public class Agent {
public static void premain(final String agentArgs, final Instrumentation inst) {
Thread thread = Thread.currentThread();
inst.addTransformer(new ClassFileTransformer() {
@Override
public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined,
ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException {
if (className.equals("Secret")) {
thread.getUncaughtExceptionHandler().uncaughtException(thread, new SecurityIsGood());
}
return classfileBuffer;
}
});
thread.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread t, Throwable e) {
if (e instanceof SecurityIsGood) {
System.exit(7);
}
e.printStackTrace();
System.exit(1);
}
});
System.setSecurityManager(new SecurityManager());
}
}
File: Secret.java
public class Secret {
static public void flag() {
System.out.println("CTF-00000000000000000000000000000000");
}
};
Comments