package project.core; import java.text.DecimalFormat; public class Brute_Force { /* * CURRENTLY CRACKS: * Letters, Numbers and Symbols. * * TODO: * Implement matching lower/upper case option. * Transfer to GPU for faster computations. * -> Implement a GUI / data logging system. (Files) * Implement common words / phrases + dictionary */ /* Possible characters / numbers for the password to brute force */ private static final String[] VALID_SYMBOLS = { // Symbols "-", "_", ".", "<", ">", // Numbers "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", // Uppercase/Lowercase "A", "a", "B", "b", "C", "c", "D", "d", "E", "e", "F", "f", "G", "g", "H", "h", "I", "i", "J", "j", "K", "k", "L", "l", "M", "m", "N", "n", "O", "o", "P", "p", "Q", "q", "R", "r", "S", "s", "T", "t", "U", "u", "V", "v", "W", "w", "X", "x", "Y", "y", "Z", "z", }; /* Array for our computations */ private static String[] COMPUTATED_DATA = new String[VALID_SYMBOLS.length]; /* Computation slot indexes */ private static int a, ab, abc, abcd, abcde, abcdef, abcdefg, abcdefgh, abcdefghi, abcdefghij; /* The time we started*/ private static long start_time = 0; /* * Password we want to crack. (10 letters max) * In most cases this wouldn't be available.. this algorithm * is capable of computing and producing the password at some point. * TYPE: BRUTE FORCE. Possible to bypass a login / authorization by * brute forcing the required password >:D */ private static final String PASS_TO_BRUTE_FORCE = "123456789"; /** * Main Entry Point Into Application. * http://www.en.wikipedia.org/wiki/Brute-force_attack * http://www.en.wikipedia.org/wiki/Password_cracking * Translated to Java by Gabriel Bailey. * @param args The arguments passed by the user.. */ public static void main(String[] args) { start_time = System.currentTimeMillis(); /* Begin the brute force search */ boolean tmp = false; try { tmp = bruteForce(PASS_TO_BRUTE_FORCE, PASS_TO_BRUTE_FORCE.length()); } catch (InterruptedException e) { e.printStackTrace(); } log("Time took: " + (System.currentTimeMillis() - start_time)/1000 + " seconds"); log("Success For Brute Force: (" + PASS_TO_BRUTE_FORCE + ") == " + tmp); } /* * The actual method translated to java. */ static boolean bruteForce(final String password, int size) throws InterruptedException { /* Display some details */ log("Initialize Brute Force Algorithm..."); log("Targeted Password: " + password); log("Password length: " + size); /* Obtain our starting time for later computations */ Thread.sleep(3000); start_time = System.currentTimeMillis(); if (size == 1) { // Cracked 'z' in 0ms. for (a = 0; a < VALID_SYMBOLS.length; a++) { COMPUTATED_DATA[a] = appendLetter(a); if (password.equals(COMPUTATED_DATA[a])) { log("Pass Cracked: " + COMPUTATED_DATA[a]); return true; } else { debug(COMPUTATED_DATA[a]); } } } else if (size == 2) { // Cracked 'zz' in 250ms. for (a = 0; a < VALID_SYMBOLS.length; a++) { for (ab = 0; ab < VALID_SYMBOLS.length; ab++) { COMPUTATED_DATA[a] = appendLetter(a) + appendLetter(ab); if (password.equals(COMPUTATED_DATA[a])) { log("Pass Cracked: " + COMPUTATED_DATA[a]); return true; } else { debug(COMPUTATED_DATA[a]); } } } } else if (size == 3) { // Cracked 'bye' in 265ms. for (a = 0; a < VALID_SYMBOLS.length; a++) { for (ab = 0; ab < VALID_SYMBOLS.length; ab++) { for (abc = 0; abc < VALID_SYMBOLS.length; abc++) { COMPUTATED_DATA[a] = appendLetter(a) + appendLetter(ab) + appendLetter(abc); if (password.equals(COMPUTATED_DATA[a])) { log("Pass Cracked: " + COMPUTATED_DATA[a]); return true; } else { debug(COMPUTATED_DATA[a]); } } } } } else if (size == 4) { // Cracked 'rofl' in 6.7 seconds. for (a = 0; a < VALID_SYMBOLS.length; a++) { for (ab = 0; ab < VALID_SYMBOLS.length; ab++) { for (abc = 0; abc < VALID_SYMBOLS.length; abc++) { for (abcd = 0; abcd < VALID_SYMBOLS.length; abcd++) { COMPUTATED_DATA[a] = appendLetter(a) + appendLetter(ab) + appendLetter(abc) + appendLetter(abcd); if (password.equals(COMPUTATED_DATA[a])) { log("Pass Cracked: " + COMPUTATED_DATA[a]); return true; } else { debug(COMPUTATED_DATA[a]); } } } } } } else if (size == 5) { // Cracked 'lmfao' in for (a = 0; a < VALID_SYMBOLS.length; a++) { for (ab = 0; ab < VALID_SYMBOLS.length; ab++) { for (abc = 0; abc < VALID_SYMBOLS.length; abc++) { for (abcd = 0; abcd < VALID_SYMBOLS.length; abcd++) { for (abcde = 0; abcde < VALID_SYMBOLS.length; abcde++) { COMPUTATED_DATA[a] = appendLetter(a) + appendLetter(ab) + appendLetter(abc) + appendLetter(abcd) + appendLetter(abcde); if (password.equals(COMPUTATED_DATA[a])) { log("Pass Cracked: " + COMPUTATED_DATA[a]); return true; } else { debug(COMPUTATED_DATA[a]); } } } } } } } else if (size == 6) { // Cracked 'abcdef' in 1 minute. for (a = 0; a < VALID_SYMBOLS.length; a++) { for (ab = 0; ab < VALID_SYMBOLS.length; ab++) { for (abc = 0; abc < VALID_SYMBOLS.length; abc++) { for (abcd = 0; abcd < VALID_SYMBOLS.length; abcd++) { for (abcde = 0; abcde < VALID_SYMBOLS.length; abcde++) { for (abcdef = 0; abcdef < VALID_SYMBOLS.length; abcdef++) { COMPUTATED_DATA[a] = appendLetter(a) + appendLetter(ab) + appendLetter(abc) + appendLetter(abcd) + appendLetter(abcde) + appendLetter(abcdef); if (password.equals(COMPUTATED_DATA[a])) { log("Pass Cracked: " + COMPUTATED_DATA[a]); return true; } else { debug(COMPUTATED_DATA[a]); } } } } } } } } else if (size == 7) { for (a = 0; a < VALID_SYMBOLS.length; a++) { for (ab = 0; ab < VALID_SYMBOLS.length; ab++) { for (abc = 0; abc < VALID_SYMBOLS.length; abc++) { for (abcd = 0; abcd < VALID_SYMBOLS.length; abcd++) { for (abcde = 0; abcde < VALID_SYMBOLS.length; abcde++) { for (abcdef = 0; abcdef < VALID_SYMBOLS.length; abcdef++) { for (abcdefg = 0; abcdefg < VALID_SYMBOLS.length; abcdefg++) { COMPUTATED_DATA[a] = appendLetter(a) + appendLetter(ab) + appendLetter(abc) + appendLetter(abcd) + appendLetter(abcde) + appendLetter(abcdef) + appendLetter(abcdefg); if (password.equals(COMPUTATED_DATA[a])) { log("Pass Cracked: " + COMPUTATED_DATA[a]); return true; } else { debug(COMPUTATED_DATA[a]); } } } } } } } } } else if (size == 8) { for (a = 0; a < VALID_SYMBOLS.length; a++) { for (ab = 0; ab < VALID_SYMBOLS.length; ab++) { for (abc = 0; abc < VALID_SYMBOLS.length; abc++) { for (abcd = 0; abcd < VALID_SYMBOLS.length; abcd++) { for (abcde = 0; abcde < VALID_SYMBOLS.length; abcde++) { for (abcdef = 0; abcdef < VALID_SYMBOLS.length; abcdef++) { for (abcdefg = 0; abcdefg < VALID_SYMBOLS.length; abcdefg++) { for (abcdefgh = 0; abcdefgh < VALID_SYMBOLS.length; abcdefgh++) { COMPUTATED_DATA[a] = appendLetter(a) + appendLetter(ab) + appendLetter(abc) + appendLetter(abcd) + appendLetter(abcde) + appendLetter(abcdef) + appendLetter(abcdefg) + appendLetter(abcdefgh); if (password.equals(COMPUTATED_DATA[a])) { log("Pass Cracked: " + COMPUTATED_DATA[a]); return true; } else { debug(COMPUTATED_DATA[a]); } } } } } } } } } } else if (size == 9) { for (a = 0; a < VALID_SYMBOLS.length; a++) { for (ab = 0; ab < VALID_SYMBOLS.length; ab++) { for (abc = 0; abc < VALID_SYMBOLS.length; abc++) { for (abcd = 0; abcd < VALID_SYMBOLS.length; abcd++) { for (abcde = 0; abcde < VALID_SYMBOLS.length; abcde++) { for (abcdef = 0; abcdef < VALID_SYMBOLS.length; abcdef++) { for (abcdefg = 0; abcdefg < VALID_SYMBOLS.length; abcdefg++) { for (abcdefgh = 0; abcdefgh < VALID_SYMBOLS.length; abcdefgh++) { for (abcdefghi = 0; abcdefghi < VALID_SYMBOLS.length; abcdefghi++) { COMPUTATED_DATA[a] = appendLetter(a) + appendLetter(ab) + appendLetter(abc) + appendLetter(abcd) + appendLetter(abcde) + appendLetter(abcdef) + appendLetter(abcdefg) + appendLetter(abcdefgh) + appendLetter(abcdefghi); if (password.equals(COMPUTATED_DATA[a])) { log("Pass Cracked: " + COMPUTATED_DATA[a]); return true; } else { debug(COMPUTATED_DATA[a]); } } } } } } } } } } } else if (size == 10) { for (a = 0; a < VALID_SYMBOLS.length; a++) { for (ab = 0; ab < VALID_SYMBOLS.length; ab++) { for (abc = 0; abc < VALID_SYMBOLS.length; abc++) { for (abcd = 0; abcd < VALID_SYMBOLS.length; abcd++) { for (abcde = 0; abcde < VALID_SYMBOLS.length; abcde++) { for (abcdef = 0; abcdef < VALID_SYMBOLS.length; abcdef++) { for (abcdefg = 0; abcdefg < VALID_SYMBOLS.length; abcdefg++) { for (abcdefgh = 0; abcdefgh < VALID_SYMBOLS.length; abcdefgh++) { for (abcdefghi = 0; abcdefghi < VALID_SYMBOLS.length; abcdefghi++) { for (abcdefghij = 0; abcdefghij < VALID_SYMBOLS.length; abcdefghij++) { COMPUTATED_DATA[a] = appendLetter(a) + appendLetter(ab) + appendLetter(abc) + appendLetter(abcd) + appendLetter(abcde) + appendLetter(abcdef) + appendLetter(abcdefg) + appendLetter(abcdefgh) + appendLetter(abcdefghi) + appendLetter(abcdefghij); if (password.equals(COMPUTATED_DATA[a])) { log("Pass Cracked: " + COMPUTATED_DATA[a]); return true; } else { debug(COMPUTATED_DATA[a]); } } } } } } } } } } } } return false; } /* * Printing a informative statement to the console. */ private static void log(String string) { System.out.println("[Brute Force] "+string); } /* * Printing a debug statement to the console. */ static int message_index = 0; final static DecimalFormat format = new DecimalFormat("###,###,###,###,###"); private static void debug(String string) { System.out.println("[Brute Force Computation (# "+(format.format(message_index++))+")]: " + string); } /* * Obtaining a random letter from the VALID_SYMBOLS. */ private static String appendLetter(int i) { // new Random().nextInt(VALID_SYMBOLS.length)]; return VALID_SYMBOLS[i]; } }