-
Notifications
You must be signed in to change notification settings - Fork 21
/
autocrack.c
352 lines (321 loc) · 9.93 KB
/
autocrack.c
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
/*
* Autocrack - automatically crack everything throught CPU and GPU
* Copyright (C) 2012 Massimo Dragano <[email protected]>
*
* Autocrack 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 3 of the License, or
* (at your option) any later version.
*
* Autocrack 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 Autocrack. If not, see <http://www.gnu.org/licenses/>.
*/
#include "autocrack.h"
struct _globals globals;
int main(int argc, char *argv[])
{
// init memory
memset(&globals,0,sizeof(struct _globals));
globals.online = globals.rain = globals.dict = globals.gpu = true;
globals.log_level = info;
globals.err_buff = malloc((MAX_BUFF+1)*sizeof(char));
report_error(NULL,0,0,debug);
P_path(argv[0]);
signal(SIGINT, signal_handler);
// handle args
option_handler(argc,argv);
// start engine
engine();
if(globals.log_level >= info)
print_hash_list();
destroy_all();
exit(EXIT_SUCCESS);
}
void option_handler(int argc, char *argv[])
{
static struct option long_options[] =
{
/* These options set a flag. */
{"local", no_argument, NULL, 'l'},
{"no-rain", no_argument, NULL, 'r'},
{"no-dict", no_argument, NULL, 'd'},
{"no-gpu", no_argument, NULL, 'g'},
{"no-cow", no_argument, NULL, 'C'},
{"no-john",no_argument, NULL, 'J'},
{"verbose", no_argument, NULL, 'v'},
{"quiet", no_argument, NULL, 'q'},
{"debug", no_argument, NULL, 'D'},
/* These options don't set a flag. */
{"hash", required_argument, NULL, 'H'},
{"type", required_argument, NULL, 't'},
{"infile", required_argument, NULL, 'i'},
{"outfile", required_argument, NULL, 'o'},
{"capture", required_argument, NULL, 'c'},
{"wordlist", required_argument, NULL, 'w'},
{"essid", required_argument, NULL, 'e'},
{"rt-root", required_argument, NULL, 'R'},
{"onlinedb", required_argument, NULL, 'O'},
{"help", no_argument, NULL, 'h'},
{NULL, no_argument, NULL, 0}
};
int option_index, c;
bool bad_option,exit_now;
option_index = 0;
exit_now = bad_option = false;
c = getopt_long(argc, argv, "vqDH:t:i:o:c:w:e:R:O:hlrdgCJ", long_options, &option_index);
if(c == -1) // no option given, threat as "--help"
{
usage(argv[0]);
exit_now = true;
}
else
{
//parsing options, thus to handle special cases like help and print info without waste CPU time for other options.
while(c!=-1 && bad_option==false && exit_now == false)
{
switch(c)
{
case 't':
if( strlen(optarg) == 4 && (!strncmp(optarg,"list",4) || !strncmp(optarg,"LIST",4)))
{
exit_now = true;
print_type_list();
}
break;
case 'h':
usage(argv[0]);
exit_now = true;
break;
case 'v':
if( globals.log_level < verbose3 )
globals.log_level++;
else if( globals.log_level == debug )
{
report_error("already in debug mode.",0,0,warning);
}
else if( globals.log_level == verbose3 )
{
report_error("maximum verbose level reached.",0,0,info);
report_error("use --debug or -D if you want more output",0,0,info);
}
break;
case 'q':
if(globals.log_level > info)
globals.log_level -= info; // keep the previous verbosity offset
else
globals.log_level = quiet;
break;
case 'D':
globals.log_level = debug;
break;
case 'H':
case 'i':
case 'o':
case 'c':
case 'w':
case 'e':
case 'R':
case 'l':
case 'r':
case 'd':
case 'g':
case 'O':
case 'C':
case 'J':
case 0:
break;
default:
bad_option = true;
}
c = getopt_long(argc, argv, "vqDH:t:i:o:c:w:e:R:O:hlrdgCJ", long_options, &option_index);
}
}
if((exit_now | bad_option ) == false)
{
//ok, we will do something, start the network check thread.
globals.tpool = malloc(sizeof(struct t_info));
pthread_create(&(globals.tpool->thread), NULL, P_online, NULL);
optind = 1;
c = getopt_long(argc, argv, "vqDH:t:i:o:c:w:e:R:O:hlrdgCJ", long_options, &option_index);
while(c!=-1)
{
switch(c)
{
case 0:
break;
case 'H':
add_hash(NONE,optarg);
break;
case 't':
add_hash(P_type(optarg),NULL);
break;
case 'i':
P_infile(optarg);
break;
case 'o':
P_outfile(optarg);
break;
case 'c':
P_capture(optarg);
break;
case 'w':
P_wordlist(optarg);
break;
case 'e':
P_essid(optarg);
break;
case 'R':
if(globals.rain==true)
P_rt_root(optarg);
break;
case 'O':
if(globals.online == true)
P_odb(optarg);
break;
case 'l':
globals.online = false;
report_error("switching OFF all online features.",0,0,verbose);
break;
case 'r':
globals.rain = false;
report_error("switching OFF rainbowtable features.",0,0,verbose);
break;
case 'd':
globals.dict = false;
report_error("switching OFF dictionary features.",0,0,verbose);
break;
case 'g':
globals.gpu = false;
report_error("switching OFF GPU features.",0,0,verbose);
break;
case 'C':
if(globals.bins.cow!=NULL)
free((void *) globals.bins.cow);
globals.bins.cow = NULL;
report_error("use this function only for testing.",0,0,warning);
break;
case 'J':
if(globals.bins.jtr!=NULL)
free((void *) globals.bins.jtr);
globals.bins.jtr = NULL;
report_error("use this function only for testing.",0,0,warning);
break;
}
c = getopt_long(argc, argv, "vqDH:t:i:o:c:w:e:R:O:hlrdgCJ", long_options, &option_index);
}
//option check
if((globals.rain == false && globals.dict == false && globals.online == false) ||
(globals.hash_list == NULL && globals.wpa_list == NULL ))
{
// parser functions have yet printed something, otherwise user have specified only flags options
// cancel network check, we are going to exit
if(pthread_kill(globals.tpool->thread,0) == 0) // thread is running
pthread_cancel(globals.tpool->thread);
bad_option = true;
pthread_join(globals.tpool->thread,NULL);
}
else if(globals.online==false) // if user disable network features or a problem shut it off.
{
if(pthread_kill(globals.tpool->thread,0) == 0) // thread is running
pthread_cancel(globals.tpool->thread);
P_hash_list();
P_wpa_list();
P_defaults();
pthread_join(globals.tpool->thread,NULL);
}
else
{
// fix missing option and other stuff, stealing a little extra CPU time while online check finish
P_hash_list();
P_wpa_list();
P_defaults();
for(option_index=0;pthread_kill(globals.tpool->thread,0) == 0 && option_index<NET_CHK_TIMEOUT;option_index++)
usleep(1000);
if(option_index == NET_CHK_TIMEOUT)
{
option_index = ETIMEDOUT;
pthread_cancel(globals.tpool->thread);
pthread_join(globals.tpool->thread,NULL);
}
else //network checker done, join and take errno
{
report(debug,"i've wait network check for %d ms",option_index);
pthread_join(globals.tpool->thread, (void **) &option_index);
}
if(option_index!=0)
{
report_error("network check fails.",0,0,error);
if(option_index == -1)
report_error("failed to resolve IP for mom Google.",0,0,error);
else
{
errno = option_index;
report_error("parser_online()",1,0,warning);
}
report_error("switching OFF online features.",0,0,info);
globals.online = false;
}
}
free(globals.tpool);
globals.tpool=NULL;
}
if(bad_option == true)
{
usage(argv[0]);
destroy_all();
exit(EXIT_FAILURE);
}
else if(exit_now == true)
{
destroy_all();
exit(EXIT_SUCCESS);
}
return;
}
void usage(char *bin_name)
{
int i;
char *developers[] = DEVELOPERS ,
*msg =
"\nUsage:\t%s [-hHioOtcwReldDvq] options"/* executable name */
"\n "
"\n option argument description"
"\n ---------------+---------------+----------------------------------"
"\n -h, --help none display this help"
"\n -H, --hash HASH perform a single hash crack."
"\n -t, --type TYPE specify the single hash type. give \"list\" for a list of supported hash."
"\n -i, --infile FILE pass a hashlist file in format $TYPE$HASH."
"\n -o, --oufile FILE write all founded passwrods and passpharses to FILE."
"\n -c, --capture FILE tcpdump file which contains the wpa handshake."
"\n -w, --wordlist FILE wordlist to use in dictionary attacks."
"\n -R, --rt-root DIR rainbow table root directory."
"\n -O, --onlinedb FILE database file for online attacks."
"\n -e, --essid ESSID the essid of the AP."
"\n -l, --local none disable online functions."
"\n -r, --no-rain none disable rainbowtable attacks."
"\n -d, --no-dict none disable dictionary attacks."
"\n -g, --no-gpu none disable GPU features."
"\n -q, --quiet none suppress all the output"
"\n -D, --debug none enable debug output."
"\n -v, --verbose none produce more output."
"\n ---------------+---------------+----------------------------------"
"\n %s - v%s - %s" /*PROGRAM_NAME - vVERSION - RELEASE_DATE*/
"\n "
"\n NOTES:"
"\n the option \"--essid\" is only required if you want to manually"
"\n specify the access points to test."
"\n if this option is not used we will parse the pcap files,"
"\n obtaining the valid ESSIDs."
"\n "
"\n Main developers:";
/*print help*/
printf(msg,basename(bin_name),PACKAGE,VERSION,RELEASE_DATE);
for(i=0;developers[i] != NULL;i++)
printf("\n\t\t%s",developers[i]);
printf("\n");
}