forked from ZerBea/hcxtools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wlancow2hcxpmk.c
273 lines (230 loc) · 5.59 KB
/
wlancow2hcxpmk.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
#define _GNU_SOURCE
#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
#if defined(__APPLE__) || defined(__OpenBSD__)
#include <libgen.h>
#else
#include <stdio_ext.h>
#endif
#include <curl/curl.h>
#include "include/version.h"
#include "common.h"
#define COWPATTY_SIGNATURE 0x43575041L
struct cow_head
{
uint32_t magic;
uint8_t reserved1[3];
uint8_t essidlen;
uint8_t essid[32];
};
typedef struct cow_head cow_head_t;
#define COWHEAD_SIZE (sizeof(cow_head_t))
/*===========================================================================*/
/* globale Konstante */
static const uint8_t zeroessid[] =
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
#define ZEROESSID_SIZE sizeof(zeroessid)
/*===========================================================================*/
static void cowinfo(FILE *fhcowin)
{
int rd;
cow_head_t cowh;
char networkname[34];
rd = fread(&cowh, COWHEAD_SIZE, 1, fhcowin);
if(rd != 1)
{
fprintf(stderr, "error reading cowpatty file header\n");
return;
}
if(cowh.magic != COWPATTY_SIGNATURE)
{
fprintf(stderr, "signature doesn't match\n");
return;
}
if((cowh.essidlen == 0) && (memcmp(&cowh.essid, &zeroessid, ZEROESSID_SIZE) == 0) && (cowh.reserved1[2] == 1))
{
printf("Multi-ESSID file detected\n");
return;
}
if((cowh.essidlen == 0) || (cowh.essidlen > 32))
{
fprintf(stderr, "wrong essidlen\n");
return;
}
memset(&networkname, 0, 34);
memcpy(&networkname, &cowh.essid, cowh.essidlen);
printf("essid: %s\n", networkname);
return;
}
/*===========================================================================*/
static void cowprocess(FILE *fhcowin, FILE *fhpwout, FILE *fhpmkpwout, FILE *fhpmkout, const int mode)
{
int rd, c;
uint8_t pwlen = 0;
cow_head_t cowh;
uint8_t recsize;
uint8_t cowrec[100];
char passwort[66];
rd = fread(&cowh, COWHEAD_SIZE, 1, fhcowin);
if(rd != 1)
{
fprintf(stderr, "error reading cowpatty file header\n");
return;
}
if(cowh.magic != COWPATTY_SIGNATURE)
{
fprintf(stderr, "signature doesn't match\n");
return;
}
if((cowh.essidlen == 0) && (memcmp(&cowh.essid, &zeroessid, ZEROESSID_SIZE) == 0) && (cowh.reserved1[2] == 1))
printf("Multi-ESSID file detected\n");
else if((cowh.essidlen == 0) || (cowh.essidlen > 32))
{
fprintf(stderr, "wrong essidlen\n");
return;
}
while( fread(&recsize, sizeof(uint8_t), 1, fhcowin) ==1)
{
if((recsize < 33) || (recsize > 92))
{
fprintf(stderr, "error reading record size\n");
return;
}
recsize--;
rd = fread(&cowrec, sizeof(uint8_t), recsize, fhcowin);
if(rd != recsize)
{
fprintf(stderr, "error reading record size\n");
return;
}
pwlen = recsize -32;
memset(&passwort, 0, 66);
memcpy(&passwort, &cowrec, pwlen);
if(fhpwout != NULL)
fprintf(fhpwout, "%s\n", passwort);
if(fhpmkpwout != NULL)
{
for(c = pwlen; c < recsize; c++)
fprintf(fhpmkpwout, "%02x", cowrec[c]);
fprintf(fhpmkpwout, ":%s\n", passwort);
}
if(fhpmkout != NULL)
{
for(c = pwlen; c < recsize; c++)
fprintf(fhpmkout, "%02x", cowrec[c]);
fprintf(fhpmkout, "\n");
}
if(mode == 's')
{
for(c = pwlen; c < recsize; c++)
fprintf(stdout, "%02x", cowrec[c]);
fprintf(stdout, "\n");
}
}
return;
}
/*===========================================================================*/
__attribute__ ((noreturn))
static void usage(char *eigenname)
{
printf("%s %s (C) %s ZeroBeat\n"
"usage: %s <options>\n"
"options:\n"
"-i <file> : input cowpatty hashfile\n"
"-w <file> : output passwordlist file\n"
"-W <file> : output pmk:password file\n"
"-p <file> : output pmk file\n"
"-s : print pmk's to stdout\n"
"-h : this help file\n"
"\n", eigenname, VERSION, VERSION_JAHR, eigenname);
exit(EXIT_FAILURE);
}
/*===========================================================================*/
int main(int argc, char *argv[])
{
int auswahl;
uint8_t mode = 0;
char *cowinname = NULL;
char *pwoutname = NULL;
char *pmkpwoutname = NULL;
char *pmkoutname = NULL;
FILE *fhcowin = NULL;
FILE *fhpwout = NULL;
FILE *fhpmkpwout = NULL;
FILE *fhpmkout = NULL;
setbuf(stdout, NULL);
while ((auswahl = getopt(argc, argv, "i:w:W:p:shv")) != -1)
{
switch (auswahl)
{
case 'i':
cowinname = optarg;
if((fhcowin = fopen(cowinname, "rb")) == NULL)
{
fprintf(stderr, "error opening cowpatty hashfile file %s\n", cowinname);
exit(EXIT_FAILURE);
}
break;
case 'w':
pwoutname = optarg;
if((fhpwout = fopen(pwoutname, "a+")) == NULL)
{
fprintf(stderr, "error opening file %s\n", pwoutname);
exit(EXIT_FAILURE);
}
break;
case 'W':
pmkpwoutname = optarg;
if((fhpmkpwout = fopen(pmkpwoutname, "a+")) == NULL)
{
fprintf(stderr, "error opening file %s\n", pmkpwoutname);
exit(EXIT_FAILURE);
}
break;
case 'p':
pmkoutname = optarg;
if((fhpmkout = fopen(pmkoutname, "a+")) == NULL)
{
fprintf(stderr, "error opening file %s\n", pmkoutname);
exit(EXIT_FAILURE);
}
break;
case 's':
mode = 's';
break;
default:
usage(basename(argv[0]));
}
}
if(fhcowin == NULL)
{
fprintf(stderr, "no cowpatty hashfile selected\n");
exit(EXIT_FAILURE);
}
if((mode != 's') && (fhpwout == NULL) && (fhpmkpwout == NULL) && (fhpmkout == NULL))
{
cowinfo(fhcowin);
fclose(fhcowin);
return EXIT_SUCCESS;
}
cowprocess(fhcowin, fhpwout, fhpmkpwout, fhpmkout, mode);
if(fhpwout != NULL)
fclose(fhpwout);
if(fhpmkpwout != NULL)
fclose(fhpmkpwout);
if(fhpmkout != NULL)
fclose(fhpmkout);
if(fhcowin != NULL)
fclose(fhcowin);
return EXIT_SUCCESS;
}