I have a program that I'm writing, where I'm attempting to take an encrypted class file, decrypt it while loading into memory(not decrypting it on the drive), and execute parts of the class. I'm able to do this with static methods, however, I'd like to find out if it's possible to do this
I also wanted to just specify, I am not writing anything malicious. I'm actually doing this as an attempt to understand reflection, and possibly using it as a form of source code protection. Payload just seemed like a gratifying name for my proof of concept.
@SuppressWarnings("resource")
Scanner scan = new Scanner(System.in);
System.out.print("Enter password:");
String pass = scan.nextLine();
MessageDigest md5 = MessageDigest.getInstance("md5");
byte[] keyBytes = md5.digest(pass.getBytes("UTF-8"));
SecretKeySpec key = new SecretKeySpec(keyBytes, "AES");
IvParameterSpec ivSpec = new IvParameterSpec(iv);
InputStream in = Master.class.getClassLoader().getResourceAsStream("Payload\\ENC\\Payload.class");
int read = 0;
byte[] buffer = new byte[1024];
ByteArrayOutputStream boas = new ByteArrayOutputStream();
while ((read = in.read(buffer)) != -1)
{
boas.write(buffer, 0, read);
}
byte[] encrypted = boas.toByteArray();
try
{
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5padding");
cipher.init(Cipher.DECRYPT_MODE, key, ivSpec);
byte[] decrypted = cipher.doFinal(encrypted);
PayloadLoader loader = new PayloadLoader(Thread.currentThread().getContextClassLoader(), decrypted);
Class<?> c = loader.loadClass("Payload.Payload");
Method main = c.getMethod("main", String[].class);
main.invoke(null, (Object) args);
}
catch (Exception e)
{
e.printStackTrace();
System.out.println("Invalid Password");
}
Above is where it is loaded into memory and executed. Instead of invoking a Main method however, I'd like to create an instance of this thread, and start it. Below is the basic thread itself
private Thread t;
private String threadName;
Payload(String name){
threadName = name;
if(config.DEBUG)
System.out.println("Creating Thread - " + threadName);
}
public void setName(String name){
threadName = name;
}
public void run()
{
if(config.DEBUG)
System.out.println("Running Thread - " + threadName);
}
public void start()
{
if(config.DEBUG)
System.out.println("Starting Thread - " + threadName);
if(t == null)
{
t = new Thread (this, threadName);
t.start();
}
}
My question is, would it be possible to create this object, and start the thread itself? This is the main thing I'm trying to accomplish, as I hope to have this multithreaded.
Aucun commentaire:
Enregistrer un commentaire