Last active
August 29, 2015 14:24
-
-
Save strazzere/13949004b7ceeedbb02e to your computer and use it in GitHub Desktop.
Garage Get
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
package diff.garage; | |
import javax.crypto.Cipher; | |
import javax.crypto.spec.SecretKeySpec; | |
/** | |
* @author <[email protected]> | |
*/ | |
public class notes { | |
/** | |
* For the code from 720a1383fa333d3fe92b35fcedcf1669bcff7a0e3b7e0d70e9e157e694c2672f | |
*/ | |
public static void main(String[] args) { | |
int same_initializer = get_encrypted_array[4]; | |
String decrypted = get_decrypt(same_initializer, same_initializer, same_initializer).intern(); | |
System.out.printf("Code get challenge 1 : %s\n", decrypted); | |
String view_token = send_decrypt(send_encrypted_array[4], send_encrypted_array[4] - 1, send_encrypted_array[4]) | |
.intern(); | |
System.out.printf("VIEW_TOKEN must equal : %s\n", view_token); | |
String top_secret = send_decrypt(-1 + send_encrypted_array[4], send_encrypted_array[4], | |
send_encrypted_array[4] - 1).intern(); | |
System.out.printf("TOPSECRET must equal : %s\n", top_secret); | |
System.out.printf("Final flag : %s\n", decrypt(encrypted_not_base64ed, top_secret)); | |
} | |
// Not used, but preserved, didn't want to use a base64 decoder import | |
private static String base64_encrypted = "q7jwHCFy7ADGQ+ol3V9k225uOOi21J6n8Q974DNoPi6uy+ushhg/L/MVVCdr8393RhbTYs/jP7eDvTEUJUucpg=="; | |
private static byte[] encrypted_not_base64ed = { (byte) 0xAB, (byte) 0xB8, (byte) 0xF0, (byte) 0x1C, (byte) 0x21, | |
(byte) 0x72, (byte) 0xEC, (byte) 0x00, (byte) 0xC6, (byte) 0x43, (byte) 0xEA, (byte) 0x25, | |
(byte) 0xDD, (byte) 0x5F, (byte) 0x64, (byte) 0xDB, (byte) 0x6E, (byte) 0x6E, (byte) 0x38, | |
(byte) 0xE8, (byte) 0xB6, (byte) 0xD4, (byte) 0x9E, (byte) 0xA7, (byte) 0xF1, (byte) 0x0F, | |
(byte) 0x7B, (byte) 0xE0, (byte) 0x33, (byte) 0x68, (byte) 0x3E, (byte) 0x2E, (byte) 0xAE, | |
(byte) 0xCB, (byte) 0xEB, (byte) 0xAC, (byte) 0x86, (byte) 0x18, (byte) 0x3F, (byte) 0x2F, | |
(byte) 0xF3, (byte) 0x15, (byte) 0x54, (byte) 0x27, (byte) 0x6B, (byte) 0xF3, (byte) 0x7F, | |
(byte) 0x77, (byte) 0x46, (byte) 0x16, (byte) 0xD3, (byte) 0x62, (byte) 0xCF, (byte) 0xE3, | |
(byte) 0x3F, (byte) 0xB7, (byte) 0x83, (byte) 0xBD, (byte) 0x31, (byte) 0x14, (byte) 0x25, | |
(byte) 0x4B, (byte) 0x9C, (byte) 0xA6 }; | |
private static String decrypt(byte[] data, String key) { | |
try { | |
SecretKeySpec keySpec = new SecretKeySpec(key.getBytes(), "AES"); | |
Cipher cipher = Cipher.getInstance("AES"); | |
cipher.init(Cipher.DECRYPT_MODE, keySpec); | |
return new String(cipher.doFinal(data), "UTF-8"); | |
} catch (Exception exception) { | |
exception.printStackTrace(); | |
} | |
return ""; | |
} | |
private static final byte[] send_encrypted_array = { 103, -21, 11, -27, 1, -11, 9, 5, -14, -2, 18, -3, -9, 11, 5, | |
-75, 59, 5, -61, 1, 1, 1, 1, 1, 1, -22, 31, -29, 1, 1, 57, -51, 52, -59, 74, -18, -3, 1, -2, 18, 1, | |
-71, 75, -22, -50, 74 }; | |
/* | |
* Yay, dexguard again from 23348d0c83f1cdf602da69a6ce4e7a04dc4328cb79b5c2baf009ea1f966fa4bc | |
*/ | |
private static String send_decrypt(int index_modifier, int length_modifier_initializer, | |
int rolling_modifier_initializer) { | |
int index = 30 - (index_modifier * 27); | |
int decrypted_length = 28 - (length_modifier_initializer * 12); | |
int rolling_modifier = 103 + (rolling_modifier_initializer * 12); | |
byte[] decrypted_array = new byte[decrypted_length]; | |
int max_iterations = decrypted_length - 1; | |
int current_iteration = 0; | |
// We don't really care about this case since it should never happen | |
if (send_encrypted_array == null) { | |
return null; | |
} | |
int x = 0, y = 0; | |
// This could potentially get converted into a for loop, keep it like this for easy of understanding | |
while (true) { | |
// Decompilers likely trip up on this bit | |
index++; | |
decrypted_array[current_iteration] = (byte) rolling_modifier; | |
if (current_iteration == max_iterations) { | |
return new String(decrypted_array, 0); | |
} | |
current_iteration++; | |
// These need to happen after prior checks otherwise we'll hit an index out of bound issue | |
x = rolling_modifier; | |
y = send_encrypted_array[index]; | |
rolling_modifier = x + y; | |
} | |
} | |
private static final byte[] get_encrypted_array = { 106, 115, 110, 51, 0, 2, -2 }; | |
@SuppressWarnings("deprecation") | |
/* | |
* Just your average dexguard stuff :D | |
* | |
* For the code from 720a1383fa333d3fe92b35fcedcf1669bcff7a0e3b7e0d70e9e157e694c2672f | |
*/ | |
private static String get_decrypt(int index_modifier, int length_modifier_initializer, | |
int rolling_modifier_initializer) { | |
int index = 4 - (index_modifier * 3); | |
int decrypted_length = 4 - (length_modifier_initializer * 3); | |
int rolling_modifier = 49 + (rolling_modifier_initializer * 4); | |
byte[] decrypted_array = new byte[decrypted_length]; | |
int max_iterations = decrypted_length - 1; | |
int current_iteration = 0; | |
// We don't really care about this case since it should never happen | |
if (get_encrypted_array == null) { | |
return null; | |
} | |
int x = 0, y = 0; | |
// This could potentially get converted into a for loop, keep it like this for easy of understanding | |
while (true) { | |
// Decompilers likely trip up on this bit | |
decrypted_array[current_iteration] = (byte) rolling_modifier; | |
if (current_iteration == max_iterations) { | |
return new String(decrypted_array, 0); | |
} | |
// These need to happen after prior checks otherwise we'll hit an index out of bound issue | |
x = rolling_modifier; | |
y = get_encrypted_array[index]; | |
current_iteration++; | |
index++; | |
rolling_modifier = 2 + (x + -y); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment