Created
October 13, 2014 09:21
-
-
Save volpino/2edea8503822aefb4c9e to your computer and use it in GitHub Desktop.
Numdroid cracker - ASIS CTF Finals 2014
This file contains hidden or 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 sample; | |
import java.util.*; | |
public class ArrayTools | |
{ | |
public static Integer[] Range(final int n, final int n2) { | |
final Integer[] array = new Integer[n2 - n]; | |
for (int i = 0; i < array.length; ++i) { | |
array[i] = n + i; | |
} | |
return array; | |
} | |
public static <T> void each(final List<T> list, final EachAction<T> eachAction) { | |
final Iterator<T> iterator = list.iterator(); | |
while (iterator.hasNext()) { | |
eachAction.action((T)((Object)iterator.next())); | |
} | |
} | |
public static <T> void each(final T[] array, final EachAction<T> eachAction) { | |
for (int length = array.length, i = 0; i < length; ++i) { | |
eachAction.action(array[i]); | |
} | |
} | |
public static <T> void each_with_index(final T[] array, final EachIndexAction<T> eachIndexAction) { | |
for (int i = 0; i < array.length; ++i) { | |
eachIndexAction.action(i, array[i]); | |
} | |
} | |
public static <T, S> List<S> map(final List<T> list, final MapAction<T, S> mapAction) { | |
final ArrayList<S> list2 = new ArrayList<S>(); | |
final Iterator<T> iterator = list.iterator(); | |
while (iterator.hasNext()) { | |
list2.add((S) mapAction.action((T)((Object)iterator.next()))); | |
} | |
return list2; | |
} | |
public static <T, S> List<S> map(final T[] array, final MapAction<T, S> mapAction) { | |
final ArrayList<S> list = new ArrayList<S>(); | |
for (int length = array.length, i = 0; i < length; ++i) { | |
list.add((S) mapAction.action(array[i])); | |
} | |
return list; | |
} | |
public static <T> List<T> select(final List<T> list, final SelectAction<T> selectAction) { | |
final ArrayList<T> list2 = new ArrayList<T>(); | |
for (final T t : list) { | |
if (selectAction.action(t)) { | |
list2.add((T) t); | |
} | |
} | |
return list2; | |
} | |
public static <T> List<T> select(final T[] array, final SelectAction<T> selectAction) { | |
final ArrayList<T> list = new ArrayList<T>(); | |
for (final T t : array) { | |
if (selectAction.action(t)) { | |
list.add((T) t); | |
} | |
} | |
return list; | |
} | |
} |
This file contains hidden or 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 sample; | |
public interface EachAction<T> { | |
void action(T p0); | |
} |
This file contains hidden or 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 sample; | |
public interface EachIndexAction<T> { | |
void action(int p0, T p1); | |
} |
This file contains hidden or 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 sample; | |
public interface MapAction<T, S> { | |
S action(T p0); | |
} |
This file contains hidden or 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 sample; | |
public interface SelectAction<T> { | |
boolean action(T p0); | |
} |
This file contains hidden or 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 sample; | |
import java.security.*; | |
import java.util.*; | |
public class Verify | |
{ | |
private static String OneWayFunction(final String s) { | |
final MessageDigest instance; | |
final byte[] digest; | |
final List<byte[]> map = ArrayTools.map( | |
ArrayTools.select( | |
ArrayTools.map( | |
new String[] {"MD5", "SHA-1", "SHA-256", "SHA-384", "SHA-512" }, | |
new MapAction<String, byte[]>() { | |
public byte[] action(final String algorithm) { | |
final byte[] digest; | |
try { | |
final MessageDigest instance = MessageDigest.getInstance(algorithm); | |
instance.update(s.getBytes()); | |
digest = instance.digest(); | |
} | |
catch (NoSuchAlgorithmException ex) { | |
System.out.println("NOT FOUND " + algorithm); | |
return null; | |
} | |
return digest; | |
} | |
}), | |
new SelectAction<byte[]>() { | |
public boolean action(final byte[] array) { | |
return array != null; | |
} | |
}), | |
new MapAction<byte[], byte[]>() { | |
public byte[] action(final byte[] array) { | |
final byte[] array2 = new byte[8]; | |
for (int i = 0; i < array2.length / 2; ++i) { | |
array2[i] = array[i]; | |
} | |
for (int j = 0; j < array2.length / 2; ++j) { | |
array2[j + array2.length / 2] = array[-2 + (array.length - j)]; | |
} | |
return array2; | |
} | |
}); | |
final byte[] input = new byte[8 * map.size()]; | |
for (int i = 0; i < input.length; ++i) { | |
input[i] = map.get(i % map.size())[i / map.size()]; | |
} | |
try { | |
instance = MessageDigest.getInstance("MD5"); | |
instance.update(input); | |
digest = instance.digest(); | |
} | |
catch (NoSuchAlgorithmException e) { | |
return ""; | |
} | |
StringBuilder hexString = new StringBuilder(); | |
for (int i = 0; i < digest.length; i++) { | |
if ((0xff & digest[i]) < 0x10) { | |
hexString.append("0" + Integer.toHexString((0xFF & digest[i]))); | |
} else { | |
hexString.append(Integer.toHexString(0xFF & digest[i])); | |
} | |
} | |
final String string2; | |
string2 = hexString.toString(); | |
return string2; | |
} | |
public static String isOk(final String s) { | |
String substring = s; | |
if (s.length() > 7) { | |
substring = s.substring(0, 7); | |
} | |
final String oneWayFunction = OneWayFunction(substring); | |
//System.out.println("digest: " + substring + " => " + oneWayFunction); | |
return oneWayFunction; | |
} | |
public static void main(String args[]) { | |
for (int i=0; i<9999999; i++) { | |
//DebugTools.log("digest: " + substring + " => " + oneWayFunction); | |
String trying = String.format("%d", i); | |
//System.out.println(trying); | |
String oneWayFunction = isOk(trying); | |
if (oneWayFunction.equals("be790d865f2cea9645b3f79c0342df7e")) { | |
System.out.println("FOUND!! " + trying); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment