-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcracker.cpp
More file actions
183 lines (167 loc) · 3.66 KB
/
cracker.cpp
File metadata and controls
183 lines (167 loc) · 3.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <omp.h>
#include <FL/fl_ask.H>
#include <FL/Fl_Text_Display.H>
#include <FL/Fl_Text_Buffer.H>
#include "cracker.h"
#include "pot.h"
extern bool addnl;
extern Fl_Text_Buffer *buff;
extern Fl_Text_Display *output;
extern Pot *pot;
bool addnl;
bool Cracker::import_hashes() {
H = 0;
FILE *fd = fopen(filename, "r");
if(fd == NULL) {
fl_message("Check your file's path");
return 1;
}
do {
int c = getc(fd);
if(c == '\n') H++;
} while(!feof(fd));
fseek(fd, 0, SEEK_SET);
type = 0;//TODO parse the type for sha1
char **tmphashlist = new char *[H];
for(int i = 0; i < H; ++i) {
tmphashlist[i] = new char[33];
fread(tmphashlist[i], 33, 1, fd);
tmphashlist[i][32] = '\0';
}
fclose(fd);
FILE *found = fopen("rc.pot", "r");
if(found == NULL) {
found = fopen("rc.pot", "a+");
}
int size = 0;
int h = 0;
do {
int c = getc(found);
++size;
if(c == '\n') h++;
} while(!feof(found));
fseek(found, 0, SEEK_SET);
char *buff = new char[size];
fread(buff, size, 1, found);
fclose(found);
int a = 0;
//We only do this to get the value 'a' used to allocate arrays, and we'll repeat the procedure to fill these up.
for(int i = 0; i < H; i++) {
bool add = true;
char *buff2 = new char[size];
strcpy(buff2, buff);
for(int j = 0; j < h; j++) {
char pothash[33];
if(j == 0) {
strcpy(pothash, strtok(buff2, ":"));
strtok(NULL, "\n");
}
else {
strcpy(pothash, strtok(NULL, ":"));
strtok(NULL, "\n");
}
if(strcmp(pothash, tmphashlist[i]) == 0)
add = false;
}
if(add) {
a++;
}
delete buff2;
}
if(a == 0) {
fl_message("There is no reminding hash to crack in the list.");
delete filename;
delete [] tmphashlist;
delete buff;
return 1;
}
hashlist = new char *[a];
md5 = new unsigned int *[a];
a = 0;
for(int i = 0; i < H; i++) {
bool add = true;
char *buff2 = new char[size];
strcpy(buff2, buff);
for(int j = 0; j < h; j++) {
char pothash[32];
if(j == 0) {
strcpy(pothash, strtok(buff2, ":"));
strtok(NULL, "\n");
}
else {
strcpy(pothash, strtok(NULL, ":"));
strtok(NULL, "\n");
}
if(strcmp(pothash, tmphashlist[i]) == 0)
add = false;
}
delete buff2;
if(add) {
hashlist[a] = new char[32];
strcpy(hashlist[a], tmphashlist[i]);
md5[a] = new unsigned int[4];
for(int j=0; j < 4; j++) {
char tmp2[9], tmp3[9];
strcpy(tmp2, &hashlist[a][j*8]);
tmp2[8] = 0;
//little endian byteorder
for(int k=0; k<8; k++) {
tmp3[k] = tmp2[7-k];
}
tmp3[8] = 0;
for(int k=0; k<8; k+=2) {
char c = tmp3[k];
tmp3[k] = tmp3[k+1];
tmp3[k+1] = c;
}
md5[a][j] = strtoul((char*)tmp3, NULL, 16);
//printf("%d", md5[a][j]);
}
//printf("\n");
//printf("%s\n", hashlist[a]);
a++;
}
}
H = a;
delete [] tmphashlist;
return 0;
}
uint32_t hash[4];
bool Cracker::hash_check(char *message) {
memset(hash, 0, sizeof(hash));
md5_hash((unsigned char*) message, strlen(message), hash);
bool done = true;
for(int h=0; h<H; ++h) {
if(md5[h]) {
done = false;
if(memcmp(hash, md5[h], sizeof(hash)) == 0) {
/*display related*/
const char *previous = buff->text();
char tmp[strlen(message) + 33];//pass + md5hash + nl;
char *p = tmp;
strcpy(p, hashlist[h]);
p += strlen(hashlist[h]);
strcpy(p, ":");
p ++;
strcpy(p, message);
p += strlen(message);
strcpy(p, "\n");
output->insert(tmp);
output->show_insert_position();
pot->save(hashlist[h], message);
md5[h] = NULL;
//delete md5[h];
}
}
}
return done;
}
Cracker::~Cracker() {
if(crack && H > 0) {
delete [] hashlist;
delete [] md5;
}
}