Skip to content
Snippets Groups Projects
Commit e3a4e66a authored by ChouTatsumi's avatar ChouTatsumi
Browse files

complete PWD4 crack

parent 72f3b755
Branches
No related tags found
No related merge requests found
......@@ -2,3 +2,4 @@
**/test.*
**/*.exe
**/*.o
**/cheat
\ No newline at end of file
......@@ -6,10 +6,11 @@
#include "sha256.h"
// constants
#define BUFFERSIZE 256
#define INPUTSIZE 10000
#define PWD4_FILENAME "pwd4sha256"
#define PWD6_FILENAME "pwd6sha256"
#define OUTPUT_FILENAME "found_pwds.txt"
#define PWD4_NUMBERS 10
#define PWD_NUMBERS 30
......@@ -23,9 +24,9 @@
#define ASCII_LOWERCASE_TO 122
// methods reference
void check_guess(BYTE guess[],
BYTE pwd[PWD_NUMBERS][SHA256_BLOCK_SIZE], int checked[]);
void check_n_guess(BYTE guess[], BYTE pwd[][SHA256_BLOCK_SIZE], int n,
void check_guess(char guess[], BYTE pwd[PWD_NUMBERS][SHA256_BLOCK_SIZE],
int checked[]);
void check_n_guess(char guess[], BYTE pwd[][SHA256_BLOCK_SIZE], int n,
int checked[]);
void int_array_init(int array[], int n);
......@@ -50,7 +51,7 @@ int main(int argc, char** argv) {
exit(0);
}
strcpy((char*)&pwd[i], (char*)&buffer);
memcpy(pwd[i], buffer, SHA256_BLOCK_SIZE);
}
fclose(fp);
......@@ -65,39 +66,60 @@ int main(int argc, char** argv) {
exit(0);
}
strcpy((char*)&pwd[i], (char*)&buffer);
memcpy(pwd[i], buffer, SHA256_BLOCK_SIZE);
}
fclose(fp);
// create guess and check it
// crazy test
BYTE guess[5] = {"aaaa"};
// guess[4] = '\0';
int checked[10];
int_array_init(checked, 10);
check_n_guess(guess, pwd, 10, checked);
// int first, second, third, fourth;
// for (first = ASCII_FROM; first <= ASCII_TO; first++) {
// guess[0] = first;
// for (second = ASCII_FROM; second <= ASCII_TO; second++) {
// guess[1] = second;
// for (third = ASCII_FROM; third <= ASCII_TO; third++) {
// guess[2] = third;
// for (fourth = ASCII_FROM; fourth <= ASCII_TO; fourth++) {
// guess[3] = fourth;
// check_n_guess(guess, pwd, 10, checked);
// }
// }
// }
// }
SHA256_CTX ctx;
BYTE buf[SHA256_BLOCK_SIZE];
// open output file
fp = fopen(OUTPUT_FILENAME, "w");
// violent crack PWD4
char guess[5];
guess[4] = '\0';
int checked[PWD4_NUMBERS];
int_array_init(checked, PWD4_NUMBERS);
int first, second, third, fourth;
for (first = ASCII_FROM; first <= ASCII_TO; first++) {
guess[0] = first;
for (second = ASCII_FROM; second <= ASCII_TO; second++) {
guess[1] = second;
for (third = ASCII_FROM; third <= ASCII_TO; third++) {
guess[2] = third;
for (fourth = ASCII_FROM; fourth <= ASCII_TO; fourth++) {
guess[3] = fourth;
// generate hash and check
sha256_init(&ctx);
sha256_update(&ctx, (BYTE*)guess, 4);
sha256_final(&ctx, buf);
for (int i = 0; i < PWD4_NUMBERS; i++) {
if (!checked[i] && !memcmp(pwd[i], buf, SHA256_BLOCK_SIZE)) {
checked[i] = 1;
printf("%s %d\n", guess, i + 1);
fprintf(fp, "%s %d\n", guess, i + 1);
}
}
}
}
}
}
// crack PWD6
fclose(fp);
} else if (argc == 2) {
// This part for good guess
} else if (argc == 3) {
FILE* fp;
BYTE buffer[BUFFERSIZE];
FILE* wfp;
BYTE buffer[SHA256_BLOCK_SIZE];
// read password file and store hashes passwords
fp = fopen(argv[2], "rb");
......@@ -108,6 +130,7 @@ int main(int argc, char** argv) {
fseek(fp, 0, SEEK_END);
pwdsize = ftell(fp);
fseek(fp, 0, SEEK_SET);
pwdcount = pwdsize / SHA256_BLOCK_SIZE;
if (pwdsize % SHA256_BLOCK_SIZE) {
......@@ -134,32 +157,49 @@ int main(int argc, char** argv) {
// read guess from file and check guess
fp = fopen(argv[1], "r");
wfp = fopen(OUTPUT_FILENAME, "w");
char input[INPUTSIZE];
SHA256_CTX ctx;
BYTE buf[SHA256_BLOCK_SIZE];
// create flag arrays to avoid repeat check
int checked[pwdcount];
int_array_init(checked, pwdcount);
while (fgets((char*)&buffer, BUFFERSIZE, fp) != NULL) {
while (fgets(input, INPUTSIZE, fp) != NULL) {
// get rid of \n for buffer
buffer[strlen((char*)&buffer) - 1] = '\0';
check_n_guess(buffer, pwd, pwdcount, checked);
buffer[strlen(input) - 1] = '\0';
// generate hash and check
sha256_init(&ctx);
sha256_update(&ctx, (BYTE*)input, 4);
sha256_final(&ctx, buf);
for (int i = 0; i < pwdcount; i++) {
if (!checked[i] && !memcmp(pwd[i], buf, SHA256_BLOCK_SIZE)) {
checked[i] = 1;
printf("%s %d\n", input, i + 1);
fprintf(wfp, "%s %d\n", input, i + 1);
}
}
}
fclose(fp);
fclose(wfp);
}
return 0;
}
void check_guess(BYTE guess[], BYTE pwd[PWD_NUMBERS][SHA256_BLOCK_SIZE],
void check_guess(char guess[], BYTE pwd[PWD_NUMBERS][SHA256_BLOCK_SIZE],
int checked[]) {
SHA256_CTX ctx;
BYTE buf[SHA256_BLOCK_SIZE];
size_t guess_len = strlen((char*)&guess);
size_t guess_len = strlen(guess);
int i;
sha256_init(&ctx);
sha256_update(&ctx, guess, guess_len);
sha256_update(&ctx, (BYTE*)guess, guess_len);
sha256_final(&ctx, buf);
if (guess_len == 4) {
......@@ -182,27 +222,6 @@ void check_guess(BYTE guess[], BYTE pwd[PWD_NUMBERS][SHA256_BLOCK_SIZE],
}
}
void check_n_guess(BYTE guess[], BYTE pwd[][SHA256_BLOCK_SIZE], int n,
int checked[]) {
SHA256_CTX ctx;
BYTE buf[SHA256_BLOCK_SIZE];
size_t guess_len = strlen((char*)&guess);
int i;
sha256_init(&ctx);
sha256_update(&ctx, guess, guess_len);
sha256_final(&ctx, buf);
for (i = 0; i < n; i++) {
printf("%d %s %s\n", checked[i], buf, pwd[i]);
if (!checked[i] && !memcmp(pwd[i], buf, SHA256_BLOCK_SIZE)) {
checked[i] = 1;
printf("%s %d\n", guess, i + 1);
}
}
}
void int_array_init(int array[], int n) {
for (int i = 0; i < n; i++) array[i] = 0;
}
\ No newline at end of file
1472 6
1482 7
1995 2
1gae 9
2goo 10
esit 3
sp*t 1
spOt 4
spot 5
xunz 8
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment