#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <platon/hash/md5.h>
#include <platon/str/strplus.h>
/* Compilation agains libplaton library:
gcc -pedantic -L ../../platon/ -I ../../ -o md5scan md5scan.c -lplaton
*/
#define BUFSIZE 1000
#define MAX_PASSWORDS 200
/* Function int main(int argc, char **argv) {{{ */
int main(int argc, char **argv)
{
MD5_CTX context;
char *passwords[MAX_PASSWORDS][16];
char *hash;
char buf[BUFSIZE];
char *ptr, md5str[16];
FILE *f;
int pw_len, buf_base;
register int i, j, pw_cnt, line;
long int cnt;
if (argc <= 2) {
printf("Usage: %s <password_file> <word-list-file_1> ... <word-list-file_N>\n", argv[0]);
return 1;
}
if ((f = fopen(argv[1], "r")) == NULL) {
printf("Cannot open password file '%s'.\n", argv[i]);
return 2;
}
printf("[%02d/%02d] Loading passwords from '%s'...\n", 1, argc - 1, argv[1]);
for (line = 0, pw_cnt = 0; fgets(buf, BUFSIZE - 1, f) != NULL; line++) {
buf[BUFSIZE-1] = '\0';
str_trim(buf);
if (strlen(buf) <= 0) {
printf(" Skipping empty line %d, continuing on next...\n", line + 1);
continue;
}
for (ptr = buf; ptr - buf != 32; ptr += 2) {
if (! isxdigit(ptr[0]) || !isxdigit(ptr[1])) {
printf("Bad input on line %d: %s\n", line + 1, buf);
return 4;
}
sscanf(ptr, "%2x", md5str + (ptr - buf) / 2);
}
if (i >= MAX_PASSWORDS) {
printf("Sorry MAX_PASSWORDS reached, cannot continue. Recompilation required.\n");
return 8;
}
memcpy(passwords[pw_cnt], md5str, 16);
pw_cnt++;
}
printf(" Loading passwords finished, %d passwords loaded from %d lines.\n", pw_cnt, line);
if (pw_cnt == 0) {
printf("No passwords in password file.");
return 16;
}
for (i = 2; i < argc; i++) {
if ((f = fopen(argv[i], "r")) == NULL) {
printf("Cannot open word list file '%s'. File skipped.\n", argv[i]);
continue;
}
printf("[%02d/%02d] Processing word list '%s'...\n", i, argc - 1, argv[i]);
fflush(stdout);
for (cnt = 0; fgets(buf, 20, f) != NULL; ) {
for (pw_len = strlen(buf) - 1;
pw_len >= 0 && isspace(buf[pw_len]); pw_len--) {
buf[pw_len] = '\0';
}
pw_len++;
if (! pw_len) {
continue;
}
cnt++;
MD5Init (&context);
MD5Update (&context, buf, pw_len);
MD5Final (md5str, &context);
for (j = 0; j < pw_cnt; j++) {
if (! memcmp(passwords[j], md5str, 16)) {
register int k;
printf("Found: MD5('%s') = '", buf);
for (k = 0; k < 16; k++) {
printf("%02x", (unsigned char ) md5str[k]);
}
putchar('\'');
putchar('\n');
}
}
}
printf(" %ld passwords checked.\n", cnt);
fclose(f);
}
return 0;
} /* }}} */
Platon Group <platon@platon.sk> http://platon.sk/
|