diff --git a/.idea/modules.xml b/.idea/modules.xml
index f3ce226..97c3b48 100644
--- a/.idea/modules.xml
+++ b/.idea/modules.xml
@@ -2,7 +2,7 @@
-
+
\ No newline at end of file
diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml
deleted file mode 100644
index 2b63946..0000000
--- a/.idea/uiDesigner.xml
+++ /dev/null
@@ -1,124 +0,0 @@
-
-
-
-
- -
-
-
- -
-
-
- -
-
-
- -
-
-
- -
-
-
-
-
-
- -
-
-
-
-
-
- -
-
-
-
-
-
- -
-
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
- -
-
-
- -
-
-
- -
-
-
- -
-
-
-
-
- -
-
-
- -
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
deleted file mode 100644
index 35eb1dd..0000000
--- a/.idea/vcs.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/Prod_1_2.iml b/Prod_1_1.iml
similarity index 100%
rename from Prod_1_2.iml
rename to Prod_1_1.iml
diff --git a/out/production/Prod_1_1/SimpleCracker.class b/out/production/Prod_1_1/SimpleCracker.class
new file mode 100644
index 0000000..ca1b432
Binary files /dev/null and b/out/production/Prod_1_1/SimpleCracker.class differ
diff --git a/out/production/Prod_1_2/common-passwords.txt b/out/production/Prod_1_1/common-passwords
similarity index 100%
rename from out/production/Prod_1_2/common-passwords.txt
rename to out/production/Prod_1_1/common-passwords
diff --git a/out/production/Prod_1_1/shadow-simple b/out/production/Prod_1_1/shadow-simple
new file mode 100644
index 0000000..a898aa9
--- /dev/null
+++ b/out/production/Prod_1_1/shadow-simple
@@ -0,0 +1,10 @@
+user0:qtoUil1J:3DACEF3B08BDAEFF0F9402FAB9270F67
+user1:LqVLX/PV:6A3DFBD5580F3A5A421CB37F4D4B7725
+user2:Ckf4mO9I:61C42F5C40F727B657CC8402359E4A17
+user3:x62ZrMwu:0174A2A91EA1881A5BC582AEF37E6F35
+user4:2VF0AblA:D08C5912FB8E6B0A9530C5FDDACA734D
+user5:CEhrE/C7:6D48564E27D9B4626A3ADBA5F369B0F3
+user6:cWGoHf89:A4EBD768B02F3418FEF93DCD152A9F85
+user7:tqKaVL4O:7F8032B62525D9FAF339CE4128579566
+user8:T7cTnZz0:4AFB9E06F08F664F367F5E2244666FC0
+user9:60O7QHXH:92AC0B3C76BD44C8768355FB0349AA19
\ No newline at end of file
diff --git a/out/production/Prod_1_2/Cracker.class b/out/production/Prod_1_2/Cracker.class
deleted file mode 100644
index 04c9e10..0000000
Binary files a/out/production/Prod_1_2/Cracker.class and /dev/null differ
diff --git a/out/production/Prod_1_2/MD5Shadow.class b/out/production/Prod_1_2/MD5Shadow.class
deleted file mode 100644
index a8eb80e..0000000
Binary files a/out/production/Prod_1_2/MD5Shadow.class and /dev/null differ
diff --git a/out/production/Prod_1_2/shadow b/out/production/Prod_1_2/shadow
deleted file mode 100644
index 9b0acf0..0000000
--- a/out/production/Prod_1_2/shadow
+++ /dev/null
@@ -1,10 +0,0 @@
-user0:$1$IHQqp.5e$iBRGUi.ZZtXDXvcFHyEE20:17801:0:99999:7:::
-user1:$1$EZ66DAJc$28BvFjvBnA/DDokoiPAls1:17801:0:99999:7:::
-user2:$1$9veighCQ$pVSDQYcJ.pAYprwPkcqAm1:17801:0:99999:7:::
-user3:$1$QAsKJurv$k6nqPmZAEHBI5NfQ0HUpa/:17801:0:99999:7:::
-user4:$1$EW3CpL8A$QPwa4cl809qiEXOAr.MaJ1:17801:0:99999:7:::
-user5:$1$OpC0/rME$LC7SumvOZ9ZLilH3./aJQ.:17801:0:99999:7:::
-user6:$1$wCquloBw$y2MjiyvGMNunrRcZLRO5j/:17801:0:99999:7:::
-user7:$1$.Coe4fHg$DhwAgs6gFdTK0PwyufA.00:17801:0:99999:7:::
-user8:$1$MCpfHPHC$I1B0MMpUOEtGCBi5IHql//:17801:0:99999:7:::
-user9:$1$n13aYQ9M$dJOH0drziInPCx6FnHnex0:17801:0:99999:7:::
diff --git a/src/MD5Shadow.java b/src/MD5Shadow.java
deleted file mode 100644
index 7323c97..0000000
--- a/src/MD5Shadow.java
+++ /dev/null
@@ -1,199 +0,0 @@
-/*******
-* Prepared for Project 1, CS 645, Fall 2020, NJIT
-*******/
-
-
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-
-public class MD5Shadow
-{
-
- /** magic is 1 for MD5 */
- private static String magic = "$1$";
-
- /** Characters for base64 encoding */
- private static String char64 = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
-
- private static byte[] Concat(byte[] array1, byte[] array2)
- {
- byte[] concat = new byte[array1.length + array2.length];
- for (int i = 0; i < concat.length; i++)
- {
- if (i < array1.length)
- {
- concat[i] = array1[i];
- }
- else
- {
- concat[i] = array2[i - array1.length];
- }
- }
- return concat;
- }
-
- private static byte[] PartialConcat(byte[] array1, byte[] array2, int max)
- {
- byte[] concat = new byte[array1.length + max];
-
- for (int i = 0; i < concat.length; i++)
- {
- if (i < array1.length)
- {
- concat[i] = array1[i];
- }
- else
- {
- concat[i] = array2[i - array1.length];
- }
- }
- return concat;
- }
-
- //This method would convert an value to the Base64 string
- private static String to64(int value, int length)
- {
- StringBuffer result;
-
- result = new StringBuffer();
- while (--length >= 0)
- {
- int ind = value & 0x3f;
- result.append(char64.substring(ind, ind + 1));
- value >>= 6;
- }
- return (result.toString());
- }
-
- public static String crypt(String password, String salt)
- {
- int saltEnd;
- int value;
- int i;
-
- byte[] pwBytes = null;
- byte[] saltBytes = null;
- byte[] ctx = null;
- byte[] ctx2 = null;
-
- StringBuilder result;
- MessageDigest hashGenerator = null;
- try
- {
- //initialize the MD5 hash generator
- hashGenerator = MessageDigest.getInstance("MD5");
- }
- catch (NoSuchAlgorithmException ex)
- {
- ex.printStackTrace();
- }
-
-////////////////////////////////////////Some safety checks.... can be omitted..................
- // Skip magic if it exists with the salt..... checking for accidentally using along with magic
- if (salt.startsWith(magic))salt = salt.substring(magic.length());
-
- // Remove password hash if present..... checking for accidentally using along with pw
- if ((saltEnd = salt.lastIndexOf('$')) != -1)salt = salt.substring(0, saltEnd);
-
- // Shorten the salt to 8 characters if it is longer.......... assuming the salt must be 8 chars long
- if (salt.length() > 8)
- {
- salt = salt.substring(0, 8);
- }
-///////////////////////////////////////////////////////////////////////////////////////////////
-
- ctx = (password + magic + salt).getBytes();
- ctx2 = hashGenerator.digest((password + salt + password).getBytes());
-
-
- /////////I am commenting out this one.... But for longer passwords, it should have to be enabled....
-
-// for (ind = password.length(); ind > 0; ind -= 16)
-// {
-// if (ind > 16)
-// {
-// ctx = Concat(ctx, ctx2);
-// }
-// else
-// {
-// ctx = PartialConcat(ctx, ctx2, ind);
-// }
-// }
-
- ctx = PartialConcat(ctx, ctx2, password.length());
-
-
- pwBytes = password.getBytes();
-
- //This is the equivalent of the while loop in the C code
- for (i = password.length(); i > 0; i >>= 1)
- {
- if ((i & 1) == 1)
- {
- ctx = Concat(ctx, new byte[]{0});
- }
- else
- {
- ctx = Concat(ctx, new byte[]{pwBytes[0]});
- }
- }
-
- ctx2 = hashGenerator.digest(ctx);
-
- byte[] ctx1;
-
-
- saltBytes = salt.getBytes();
-
- // Do some scramblings or mutations?!!
- for (i = 0; i < 1000; i++)
- {
- ctx1 = new byte[]
- {
- };
- if ((i & 1) == 1)
- {
- ctx1 = Concat(ctx1, pwBytes);
- }
- else
- {
- ctx1 = Concat(ctx1, ctx2);
- }
- if (i % 3 != 0)
- {
- ctx1 = Concat(ctx1, saltBytes);
- }
- if (i % 7 != 0)
- {
- ctx1 = Concat(ctx1, pwBytes);
- }
- if ((i & 1) != 0)
- {
- ctx1 = Concat(ctx1, ctx2);
- }
- else
- {
- ctx1 = Concat(ctx1, pwBytes);
- }
- ctx2 = hashGenerator.digest(ctx1);
- }
- result = new StringBuilder();
-
- // Do the shifting and add the Base64 converted hash to the result string
- value = ((ctx2[0] & 0xff) << 16) | ((ctx2[6] & 0xff) << 8) | (ctx2[12] & 0xff);
- result.append(to64(value, 4));
- value = ((ctx2[1] & 0xff) << 16) | ((ctx2[7] & 0xff) << 8) | (ctx2[13] & 0xff);
- result.append(to64(value, 4));
- value = ((ctx2[2] & 0xff) << 16) | ((ctx2[8] & 0xff) << 8) | (ctx2[14] & 0xff);
- result.append(to64(value, 4));
- value = ((ctx2[3] & 0xff) << 16) | ((ctx2[9] & 0xff) << 8) | (ctx2[15] & 0xff);
- result.append(to64(value, 4));
- value = ((ctx2[4] & 0xff) << 16) | ((ctx2[10] & 0xff) << 8) | (ctx2[5] & 0xff);
- result.append(to64(value, 4));
- value = ctx2[11] & 0xff;
- result.append(to64(value, 2));
-
-// return magic + salt + "$" + result.toString();
- return result.toString();
- }
-}
diff --git a/src/Cracker.java b/src/SimpleCracker.java
similarity index 69%
rename from src/Cracker.java
rename to src/SimpleCracker.java
index e1560d3..f02421e 100644
--- a/src/Cracker.java
+++ b/src/SimpleCracker.java
@@ -1,10 +1,11 @@
import java.io.*;
import java.math.BigInteger;
+import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Scanner;
import java.util.HashSet;
-public class Cracker {
+public class SimpleCracker {
public static String toHex(byte[] bytes) {
BigInteger bi = new BigInteger(1, bytes);
@@ -14,7 +15,7 @@ public static String toHex(byte[] bytes) {
public static void main(String[] args) throws IOException, NoSuchAlgorithmException {
// read common passwords file into a set
- File commonPasswordsFile = new File("common-passwords.txt");
+ File commonPasswordsFile = new File("common-passwords");
Scanner scanner = new Scanner(commonPasswordsFile);
HashSet commonPasswords = new HashSet<>();
while (scanner.hasNextLine()) {
@@ -23,18 +24,21 @@ public static void main(String[] args) throws IOException, NoSuchAlgorithmExcept
scanner.close();
// read shadow file and try to crack passwords
- File shadowFile = new File("shadow");
+ File shadowFile = new File("shadow-simple");
scanner = new Scanner(shadowFile);
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
String[] parts = line.split(":");
String username = parts[0];
- String[] hashParts = parts[1].split("\\$");
- String salt = hashParts[2];
- String expectedHash = hashParts[3];
+ String salt = parts[1];
+ String expectedHash = parts[2];
for (String password : commonPasswords) {
- String actualHash = MD5Shadow.crypt(password,salt);
+ String candidate = salt + password;
+ MessageDigest md = MessageDigest.getInstance("MD5");
+ byte[] candidateBytes = candidate.getBytes();
+ byte[] hashBytes = md.digest(candidateBytes);
+ String actualHash = toHex(hashBytes);
if (actualHash.equals(expectedHash)) {
System.out.println(username + ":" + password);
break;
diff --git a/src/common-passwords.txt b/src/common-passwords
similarity index 100%
rename from src/common-passwords.txt
rename to src/common-passwords
diff --git a/src/shadow b/src/shadow
deleted file mode 100644
index 9b0acf0..0000000
--- a/src/shadow
+++ /dev/null
@@ -1,10 +0,0 @@
-user0:$1$IHQqp.5e$iBRGUi.ZZtXDXvcFHyEE20:17801:0:99999:7:::
-user1:$1$EZ66DAJc$28BvFjvBnA/DDokoiPAls1:17801:0:99999:7:::
-user2:$1$9veighCQ$pVSDQYcJ.pAYprwPkcqAm1:17801:0:99999:7:::
-user3:$1$QAsKJurv$k6nqPmZAEHBI5NfQ0HUpa/:17801:0:99999:7:::
-user4:$1$EW3CpL8A$QPwa4cl809qiEXOAr.MaJ1:17801:0:99999:7:::
-user5:$1$OpC0/rME$LC7SumvOZ9ZLilH3./aJQ.:17801:0:99999:7:::
-user6:$1$wCquloBw$y2MjiyvGMNunrRcZLRO5j/:17801:0:99999:7:::
-user7:$1$.Coe4fHg$DhwAgs6gFdTK0PwyufA.00:17801:0:99999:7:::
-user8:$1$MCpfHPHC$I1B0MMpUOEtGCBi5IHql//:17801:0:99999:7:::
-user9:$1$n13aYQ9M$dJOH0drziInPCx6FnHnex0:17801:0:99999:7:::
diff --git a/src/shadow-simple b/src/shadow-simple
new file mode 100644
index 0000000..a898aa9
--- /dev/null
+++ b/src/shadow-simple
@@ -0,0 +1,10 @@
+user0:qtoUil1J:3DACEF3B08BDAEFF0F9402FAB9270F67
+user1:LqVLX/PV:6A3DFBD5580F3A5A421CB37F4D4B7725
+user2:Ckf4mO9I:61C42F5C40F727B657CC8402359E4A17
+user3:x62ZrMwu:0174A2A91EA1881A5BC582AEF37E6F35
+user4:2VF0AblA:D08C5912FB8E6B0A9530C5FDDACA734D
+user5:CEhrE/C7:6D48564E27D9B4626A3ADBA5F369B0F3
+user6:cWGoHf89:A4EBD768B02F3418FEF93DCD152A9F85
+user7:tqKaVL4O:7F8032B62525D9FAF339CE4128579566
+user8:T7cTnZz0:4AFB9E06F08F664F367F5E2244666FC0
+user9:60O7QHXH:92AC0B3C76BD44C8768355FB0349AA19
\ No newline at end of file