-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkey.c
More file actions
235 lines (171 loc) · 4.56 KB
/
key.c
File metadata and controls
235 lines (171 loc) · 4.56 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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/*
* Cracking Engine
* Copyright (C) Bernardo Reino (aka Lepton) (lepton@runbox.com)
* 20021120
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
*/
#include "global.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
void KEY_text(BYTE *stream, char *dst, unsigned int len) {
while(len --)
*(dst ++) = K_CHARSET[(int)*(stream ++)];
}
/*
* Check if Hash(K) matches a Hash from the Password List
*/
int KEY_find(char *K, int K_Len, CODE_BLOCK_PTR H) {
PasswordElement *ptr;
BYTE mod_index;
unsigned int found;
found = 0;
PasswordCount ++;
mod_index = H[0] & 0xff;
for(ptr = PasswordList[mod_index].next; ptr; ptr = ptr->next)
if(*ptr->login && xtn_cmp(H, ptr->data)) {
if(verbose) {
fprintf(stderr, "found: login(%s), passwd(", ptr->login);
print_key(stderr, K, K_Len);
fprintf(stderr, ")\n");
}
if(pot_file || !verbose) {
fprintf(pot, "%s:", ptr->login);
print_key(pot, K, K_Len);
fprintf(pot, "\n");
}
ptr->login[0] = '\0'; /* mark login as cracked.. */
PasswordLeft --;
found ++;
//return 1;
}
return found;
}
void KEY_zero(BYTE *K, unsigned int Len) {
while(Len --)
*(K ++) = 0;
}
signed int KEY_next(BYTE *K, unsigned int Len) {
signed int j = Len - 1;
while(j >= 0) {
if(++ K[j] >= K_CHARSET_LEN) {
K[j --] = 0;
} else
break;
}
return j;
}
void KEY_rand(BYTE *K, unsigned int Len) {
unsigned int j;
for(j = 0; j < Len; j ++) {
K[j] = rand() % K_CHARSET_LEN;
}
}
/*
* compute hash(passwd) and search in the list..
*/
int KEY_cmp(char *passwd, int len) {
CODE_BLOCK_PTR R;
R = xtn_crypt(passwd, len, K_ACTIVE);
return KEY_find(passwd, len, R);
}
int KEY_word(char *passwd, int len, int xtd) {
static char sym_tbl[] = " 0123456789^!\"$%&/()=?'`+-*{}[]#.,;:_-~<>|@";
static int sym_len = sizeof(sym_tbl);
char aux[MAX_PASS_LEN+1];
int j;
strncpy(aux, passwd, MAX_PASS_LEN);
aux[MAX_PASS_LEN] = '\0';
if(KEY_cmp(aux, len))
return 1;
for(j = 0; j < len; j ++)
aux[j] = tolower(aux[j]);
if(KEY_cmp(aux, len))
return 1;
aux[0] = toupper(aux[0]);
if(KEY_cmp(aux, len))
return 1;
for(j = 0; j < len; j ++)
aux[j] = toupper(aux[j]);
if(KEY_cmp(aux, len))
return 1;
if((xtd) && (len < MAX_PASS_LEN - 1)) {
int i;
strncpy(aux, passwd, MAX_PASS_LEN);
aux[MAX_PASS_LEN] = '\0';
/* prefix symbol */
aux[len + 1] = '\0';
for(i = 0; i < sym_len; i ++) {
aux[len] = sym_tbl[i];
if(KEY_word(aux, len+1, 0)) /* recursive */
return 1;
}
/* suffix symbol */
memcpy(aux + 1, passwd, len);
for(i = 0; i < sym_len; i ++) {
aux[0] = sym_tbl[i];
if(KEY_word(aux, len+1, 0)) /* recursive */
return 1;
}
}
return 0;
}
int KEY_login(char *passwd, int len, int xtd) {
static char sym_tbl[] = "0123456789^!\"$%&/()=?'`+-*{}[]#.,;:_-~<>|@";
static int sym_len = sizeof(sym_tbl);
char aux[MAX_PASS_LEN+1];
int j;
strncpy(aux, passwd, MAX_PASS_LEN);
aux[MAX_PASS_LEN] = '\0';
if(KEY_cmp(aux, len))
return 1;
for(j = 0; j < len; j ++)
aux[j] = tolower(aux[j]);
if(KEY_cmp(aux, len))
return 1;
aux[0] = toupper(aux[0]);
if(KEY_cmp(aux, len))
return 1;
for(j = 0; j < len; j ++)
aux[j] = toupper(aux[j]);
if(KEY_cmp(aux, len))
return 1;
if((xtd) && (len < MAX_PASS_LEN - 1)) {
int i;
/* prefix symbol */
aux[len + 1] = '\0';
for(i = 0; i < sym_len; i ++) {
aux[len] = sym_tbl[i];
if(KEY_login(aux, len+1, 0))
return 1;
}
/* suffix symbol */
memcpy(aux + 1, passwd, len);
for(i = 0; i < sym_len; i ++) {
aux[0] = sym_tbl[i];
if(KEY_login(aux, len+1, 0))
return 1;
}
}
if((xtd) && (2*len < MAX_PASS_LEN - 1)) {
/* double login */
strcpy(aux, passwd);
strcat(aux, passwd);
if(KEY_login(aux, 2*len, 0))
return 1;
}
return 0;
}