Created
August 24, 2016 20:46
-
-
Save alexanderhenne/bf7879348838826751bc1f8031347d74 to your computer and use it in GitHub Desktop.
Obtains the IP and port a stub of the RAT OSCelestial is configured to use
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sun.misc.BASE64Decoder; | |
import java.io.*; | |
public class OSCelestialCrack { | |
public String[] ips; | |
public String port; | |
public String id; | |
private String stubConfigFile; | |
private String hostsConfigFile; | |
public OSCelestialCrack(String stubConfigFile, String hostsConfigFile) throws NullPointerException, IOException { | |
this.stubConfigFile = stubConfigFile; | |
this.hostsConfigFile = hostsConfigFile; | |
crack(); | |
} | |
private void crack() throws NullPointerException, IOException { | |
String stubConfig = readFile(stubConfigFile); | |
String hostsConfig = readFile(hostsConfigFile); | |
String[] stubConfigBits = stubConfig.split(":"); | |
String key = stubConfigBits[1]; | |
stubConfig = decode(stubConfigBits[0], key); | |
stubConfigBits = stubConfig.split(":"); | |
port = stubConfigBits[0]; | |
id = stubConfigBits[1]; | |
hostsConfig = decode(hostsConfig, key); | |
ips = hostsConfig.split("\\r?\\n"); | |
} | |
private static String readFile(String file) throws IOException { | |
StringWriter writer = new StringWriter(); | |
try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"))) { | |
int n; | |
char[] buffer = new char[1024]; | |
while ((n = reader.read(buffer)) != -1) { | |
writer.write(buffer, 0, n); | |
} | |
return writer.toString(); | |
} | |
} | |
private static String decode(String s, String key) throws IOException { | |
return new String(xorWithKey(base64Decode(s), key.getBytes())); | |
} | |
private static byte[] base64Decode(String s) throws IOException { | |
return new BASE64Decoder().decodeBuffer(s); | |
} | |
private static byte[] xorWithKey(byte[] s, byte[] key) throws IOException { | |
byte[] out = new byte[s.length]; | |
for (int i = 0; i < s.length; ++i) { | |
out[i] = (byte) (s[i] ^ key[i % key.length]); | |
} | |
return out; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment