Skip to content

Instantly share code, notes, and snippets.

@codelion
Forked from jsyeo/Main.java
Last active September 7, 2015 02:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codelion/20c091367c6589568eb2 to your computer and use it in GitHub Desktop.
Save codelion/20c091367c6589568eb2 to your computer and use it in GitHub Desktop.
Reflection
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class Reflection {
public static void vulnerableMethod() {
}
public void reflectVulnerableMethod() throws ClassNotFoundException, NoSuchMethodException, SecurityException,
IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Class<?> klazz = Class.forName("Reflection"); // [Reflection] []
Class<?> klazz2 = Class.forName("java.lang.Integer"); // [Reflection, java.lang.Integer] []
Method m1 = klazz.getMethod("vulnerableMethod"); // [Reflection, java.lang.Integer] [vulnerableMethod]
Method m2 = klazz.getMethod("vulernableMethod2") // [Reflection, java.lang.Integer] [vulnerableMethod, vulnerbleMethod2]
m2.invoke(null); // [Refelection.vulnerableMethod, java.lang.Integer.vulernerableMethod]
m1.invoke(null); // [Refelection.vulnerableMethod, java.lang.Integer.vulernerableMethod]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment