How to load LoadClass () from an external project assembly?

I'm trying to create an exploit, I want to load a class from outside the netbeans project from a subclass of the cash register that was supposed to be final.

I can load the LegitClass tone from the source package badclassloaderusing:

claz = "badclassloader.LegitClass"
loadClass = this.getClass().getClassLoader().loadClass(claz);
(LegitClass)loadClass.newInstance();

Now I want to download MalClass, which lives in another project and package "Mal Package"

  • How do I get Mal.MalClassin the way for a method LoadClass()to search?

I tried the following:

    private void loadLibrary() {
    if (library != null) {
        AccessController.doPrivileged(new PrivilegedAction() {
            @Override
            public Object run() {
                System.loadLibrary("Path/to/Project/mal.jar");
                return null;
            }
        });
    }
}

but firstly, I received Directory separator should not appear in library name. So this is clearly not the case, I'm sure that I have something significant here.

+3
source share
1 answer

Create a new custom class loader ...

URLClassLoader cl = new URLClassLoader(
        new URL[]{new File("Path/to/Project/mal.jar").toURI().toURL()}
    );

Download the class from the class loader ...

Class clazz = cl.loadClass("Mal.MalClass");

...

Object obj = clazz.newInstance();

. . Class, , interface, , Class , . , ...

0

All Articles