Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,93 @@
import javax.xml.bind.DatatypeConverter;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
* "Main Program" that does the parallel processing
*/
public class ParallelBruteForce {
public static void main(String[] args) throws NoSuchAlgorithmException {
//the hashes to be cracked
String[] hashes = {"1115dd800feaacefdf481f1f9070374a2a81e27880f187396db67958b207cbad",
"3a7bd3e2360a3d29eea436fcfb7e44c735d117c42d1c1835420b6b9942dd4f1b",
"74e1bb62f8dabb8125a58852b63bdf6eaef667cb56ac7f7cdba6d7305c50a22f"};
//An ExecutorService is a high-level parallel programming facility, that can execute a number of tasks
//the FixedThreadPool is an ExecutorService that uses a configurable number of parallel threads
ExecutorService executorService = Executors.newFixedThreadPool(3);
//Submit one Task per hash to the thread po
for (String hash : hashes) {
executorService.submit(new Forcer(hash));
}
//An ExecutorSerice must be shut down properly (this also causes the program to await termination of
// all pending tasks in the thread pool)
executorService.shutdown();
}
}
/**
* The Class that contains the actual brute-forcing task.
* <p>
* It implements the build-in Interface "Runnable", so it can be run on a Thread or a Thread-Execution-Facility
* (such as an ExecutorService).
*/
class Forcer implements Runnable {
private static final int LENGTH = 5;
//These will sore the hash to be cracked in both bytes (required for comparison) and String representation
// (required for output)
private final byte[] crackMe;
private final String crackMeString;
//The MessageDigest does the SHA-256 caclulation. Note that this may throw a NoSuchAlgorithmException when there
// is no SHA-256 implementation in the local standard libraries (but that algorithm is mandatory, so this code
// probably will never throw that Excpetion
private final MessageDigest digest = MessageDigest.getInstance("SHA-256");
public Forcer(String crackMe) throws NoSuchAlgorithmException {
this.crackMeString = crackMe;
this.crackMe = DatatypeConverter.parseHexBinary(crackMe);
}
@Override
public void run() {
String match = "";
//all loops use this array for their counters. This is very dirty and should never be done in production!
char[] chars = new char[LENGTH];
//used for short-stopping when a match is found - one could abuse the match-variable for this, but this is
// much clearer
boolean done = false;
for (chars[0] = 'a'; chars[0] <= 'z' && !done; chars[0]++) {
for (chars[1] = 'a'; chars[1] <= 'z' && !done; chars[1]++) {
for (chars[2] = 'a'; chars[2] <= 'z' && !done; chars[2]++) {
for (chars[3] = 'a'; chars[3] <= 'z' && !done; chars[3]++) {
for (chars[4] = 'a'; chars[4] <= 'z' && !done; chars[4]++) {
//the String creation is necessary to get the encoding right
String canidate = new String(chars);
//genenrate SHA-256 hash using Java's standard facilities
byte[] hash = digest.digest(canidate.getBytes());
if (Arrays.equals(hash, crackMe)) {
match = canidate;
done = true;
}
}
}
}
}
}
System.out.println(String.format("Hash %s has the following match : %s", crackMeString, match));
}
}

View file

@ -0,0 +1,82 @@
import javax.xml.bind.DatatypeConverter;
import java.security.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.*;
public class ParallelBruteForce {
public static void main(String[] args) {
try {
String[] hashes = {
"1115dd800feaacefdf481f1f9070374a2a81e27880f187396db67958b207cbad",
"3a7bd3e2360a3d29eea436fcfb7e44c735d117c42d1c1835420b6b9942dd4f1b",
"74e1bb62f8dabb8125a58852b63bdf6eaef667cb56ac7f7cdba6d7305c50a22f"};
ParallelBruteForce pbf = new ParallelBruteForce(5, hashes);
pbf.findPasswords();
} catch (Exception e) {
e.printStackTrace();
}
}
private ParallelBruteForce(int length, String[] hashes) {
this.length = length;
this.hashes = hashes;
digests = new byte[hashes.length][];
for (int i = 0; i < hashes.length; ++i)
digests[i] = DatatypeConverter.parseHexBinary(hashes[i]);
}
private void findPasswords() throws Exception {
count.set(length);
int processors = Runtime.getRuntime().availableProcessors();
ExecutorService svc = Executors.newFixedThreadPool(processors);
List<Future<?>> tasks = new ArrayList<>();
for (int i = 0; i < 26; ++i)
tasks.add(svc.submit(new PasswordFinder((byte)(97 + i))));
for (Future<?> task : tasks)
task.get();
svc.shutdown();
}
private static boolean nextPassword(byte[] passwd, int start) {
int len = passwd.length;
for (int i = len - 1; i >= start; --i) {
if (passwd[i] < 122) {
++passwd[i];
return true;
}
passwd[i] = 97;
}
return false;
}
private class PasswordFinder implements Runnable {
private byte ch;
private MessageDigest md = MessageDigest.getInstance("SHA-256");
private PasswordFinder(byte c) throws NoSuchAlgorithmException {
ch = c;
}
public void run() {
byte[] passwd = new byte[length];
Arrays.fill(passwd, (byte)97);
passwd[0] = ch;
while (count.get() > 0) {
byte[] digest = md.digest(passwd);
for (int m = 0; m < hashes.length; ++m) {
if (Arrays.equals(digest, digests[m])) {
count.decrementAndGet();
System.out.println("password: " + new String(passwd) + ", hash: " + hashes[m]);
break;
}
}
if (!nextPassword(passwd, 1))
break;
}
}
}
private int length;
private String[] hashes;
private byte[][] digests;
private AtomicInteger count = new AtomicInteger();
}