Codebase list reaver / master src / globule.c
master

Tree @master (Download .tar.gz)

globule.c @masterraw · history · blame

  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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
/*
 * Reaver - Global variable access functions
 * Copyright (c) 2011, Tactical Network Solutions, Craig Heffner <[email protected]>
 *
 *  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
 *
 *
 *  In addition, as a special exception, the copyright holders give
 *  permission to link the code of portions of this program with the
 *  OpenSSL library under certain conditions as described in each
 *  individual source file, and distribute linked combinations
 *  including the two.
 *  You must obey the GNU General Public License in all respects
 *  for all of the code used other than OpenSSL. *  If you modify
 *  file(s) with this exception, you may extend this exception to your
 *  version of the file(s), but you are not obligated to do so. *  If you
 *  do not wish to do so, delete this exception statement from your
 *  version. *  If you delete this exception statement from all source
 *  files in the program, then also delete it here.
 */

#include "globule.h"

struct globals *globule;

int globule_init()
{
	int ret = 0;

	globule = malloc(sizeof(struct globals));
	if(globule)
	{
		memset(globule, 0, sizeof(struct globals));
		ret = 1;
		globule->resend_timeout_usec = 200000;
		globule->output_fd = -1;

	}

	return ret;
}
void globule_deinit()
{
	int i = 0;

	if(globule)
	{
		for(i=0; i<P1_SIZE; i++)
                {
                        if(globule->p1[i]) free(globule->p1[i]);
                }
                for(i=0; i<P2_SIZE; i++)
                {
                        if(globule->p2[i]) free(globule->p2[i]);
                }

		if(globule->wps) wps_deinit(globule->wps);
		if(globule->handle) pcap_close(globule->handle);
		if(globule->pin) free(globule->pin);
		if(globule->iface) free(globule->iface);
		if(globule->ssid) free(globule->ssid);
		if(globule->session) free(globule->session);
		if(globule->static_p1) free(globule->static_p1);
		if(globule->static_p2) free(globule->static_p2);
		if(globule->fp) fclose(globule->fp);
		if(globule->exec_string) free(globule->exec_string);

		if(globule->output_fd != -1) close(globule->output_fd);

		free(globule);
	}
}

void set_log_file(FILE *fp)
{
	globule->fp = fp;
}
FILE *get_log_file(void)
{
	return globule->fp;
}

void set_last_wps_state(int state)
{
	globule->last_wps_state = state;
}
int get_last_wps_state()
{
	return globule->last_wps_state;
}

void set_session(char *value)  
{ 
	if(globule->session) free(globule->session);
	globule->session = (value) ? strdup(value) : NULL;
}
char *get_session()    
{
	return globule->session;  
} 

void set_p1_index(int index)
{
	if(index < P1_SIZE)
	{
		globule->p1_index = index;
	}
}
int get_p1_index()
{
	return globule->p1_index;
}

void set_p2_index(int index)
{
	if(index < P2_SIZE)
	{
		globule->p2_index = index;
	}
}
int get_p2_index()
{
	return globule->p2_index;
}

void set_p1(int index, char *value)
{
	if(index < P1_SIZE)
	{
		if(globule->p1[index]) free(globule->p1[index]);
		globule->p1[index] = (value) ? strdup(value) : NULL;
	}
}
char *get_p1(int index)
{
	if(index < P1_SIZE)
	{
		return globule->p1[index];
	}
	return NULL;
}

void set_p2(int index, char *value)
{
	if(index < P2_SIZE)
	{
		if(globule->p2[index]) free(globule->p2[index]);
		globule->p2[index] = (value) ? strdup(value) : NULL;
	}
}
char *get_p2(int index)
{
	if(index < P2_SIZE)
	{
		return globule->p2[index];
	}
	return NULL;
}

void set_key_status(enum key_state status)
{
	globule->key_status = status;
}
enum key_state get_key_status()
{
	return globule->key_status;
}

void set_delay(int delay)
{
	globule->delay = delay;
}
int get_delay()
{
	return globule->delay;
}

void set_fail_delay(int delay)
{
	globule->fail_delay = delay;
}
int get_fail_delay()
{
	return globule->fail_delay;
}

void set_validate_fcs(int validate)
{
	globule->validate_fcs = validate;
}
int get_validate_fcs(void)
{
	return globule->validate_fcs;
}

void set_recurring_delay(int delay)
{
	globule->recurring_delay = delay;
}
int get_recurring_delay()
{
	return globule->recurring_delay;
}

void set_recurring_delay_count(int value)
{
	globule->recurring_delay_count = value;
}
int get_recurring_delay_count()
{
	return globule->recurring_delay_count;
}

void set_lock_delay(int value)
{
	globule->lock_delay = value;
}
int get_lock_delay()
{
	return globule->lock_delay;
}

void set_ignore_locks(int value)
{
	globule->ignore_locks = value;
}
int get_ignore_locks()
{
	return globule->ignore_locks;
}

void set_eap_terminate(int value)
{
	globule->eap_terminate = value;
}
int get_eap_terminate()
{
	return globule->eap_terminate;
}

void set_max_pin_attempts(int value)
{
	globule->max_pin_attempts = value;
}
int get_max_pin_attempts()
{
	return globule->max_pin_attempts;
}

void set_max_num_probes(int value)
{
	globule->max_num_probes = value;
}
int get_max_num_probes()
{
	return globule->max_num_probes;
}

void set_rx_timeout(int value)
{
	globule->rx_timeout = value;
}
int get_rx_timeout()
{
	return globule->rx_timeout;
}

void set_timeout_is_nack(int value)
{
	globule->timeout_is_nack = value;
}
int get_timeout_is_nack()
{
	return globule->timeout_is_nack;
}

void set_m57_timeout(int value)
{
	globule->m57_timeout = value;
}
int get_m57_timeout()
{
	return globule->m57_timeout;
}

void set_out_of_time(int value)
{
	globule->out_of_time = value;
}
int get_out_of_time()
{
	return globule->out_of_time;
}

void set_debug(enum debug_level value)
{
	globule->debug = value;
	if(value == DEBUG) wpa_debug_level = MSG_DEBUG;
}
enum debug_level get_debug()
{
	return globule->debug;
}

void set_eapol_start_count(int value)
{
	globule->eapol_start_count = value;
}
int get_eapol_start_count()
{
	return globule->eapol_start_count;
}

void set_fixed_channel(int value)
{
	globule->fixed_channel = value;
}
int get_fixed_channel()
{
	return globule->fixed_channel;
}

void set_auto_channel_select(int value)
{
	globule->auto_channel_select = value;
}
int get_auto_channel_select()
{
	return globule->auto_channel_select;
}

void set_wifi_band(int value)
{
	globule->wifi_band = value;
}
int get_wifi_band()
{
	return globule->wifi_band;
}

void set_opcode(enum wsc_op_code value)
{
	globule->opcode = value;
}
enum wsc_op_code get_opcode()
{
	return globule->opcode;
}

void set_eap_id(uint8_t value)
{
	globule->eap_id = value;
}
uint8_t get_eap_id()
{
	return globule->eap_id;
}

void set_ap_capability(uint16_t value)
{
	globule->ap_capability = value;
}
uint16_t get_ap_capability()
{
	return globule->ap_capability;
}

void set_channel(int channel)
{
	globule->channel = channel;
}
int get_channel(void)
{
	return globule->channel;
}

void set_bssid(unsigned char *value)
{
	memcpy(globule->bssid, value, MAC_ADDR_LEN);
}
unsigned char *get_bssid()
{
	return globule->bssid;
}

void set_mac(unsigned char *value)
{
	memcpy(globule->mac, value, MAC_ADDR_LEN);
}
unsigned char *get_mac()
{
	return globule->mac;
}

void set_ssid(char *value)
{
	if(globule->ssid)
	{
		free(globule->ssid);
		globule->ssid = NULL;
	}

	if(value)
	{
		if(strlen(value) > 0)
		{
			globule->ssid = strdup(value);
		}
	}
}
char *get_ssid()
{
	return globule->ssid;
}

void set_iface(char *value)
{
	if(value)
	{
		if(globule->iface)
		{
			free(globule->iface);
		}

		globule->iface = strdup(value);
	}
	else if(globule->iface)
	{
		free(globule->iface);
		globule->iface = NULL;
	}
}
char *get_iface()
{
	return globule->iface;
}

void set_pin(char *value)
{
	if(globule->pin) free(globule->pin);
	globule->pin = (value) ? strdup(value) : NULL;
}
char *get_pin()
{
	return globule->pin;
}

void set_static_p1(char *value)
{
	if(globule->static_p1) free(globule->static_p1);
	globule->static_p1 = (value) ? strdup(value) : NULL;
}

char *get_static_p1(void)
{
	return globule->static_p1;
}

void set_static_p2(char *value)
{
	if(globule->static_p2) free(globule->static_p2);
	globule->static_p2 = (value) ? strdup(value) : NULL;
}

char *get_static_p2(void)
{
	return globule->static_p2;
}

void set_pin_string_mode(int value)
{
	globule->use_pin_string = value;
}

int get_pin_string_mode(void)
{
	return globule->use_pin_string;
}

void set_win7_compat(int value)
{
	globule->win7_compat = value;
}

int get_win7_compat(void)
{
	return globule->win7_compat;
}

void set_dh_small(int value)
{
	globule->dh_small = value;
}
int get_dh_small(void)
{
	return globule->dh_small;
}

void set_external_association(int value)
{
	globule->external_association = value;
}
int get_external_association(void)
{
	return globule->external_association;
}

void set_nack_reason(enum nack_code value)
{
	globule->nack_reason = value;
}
enum nack_code get_nack_reason()
{
	return globule->nack_reason;
}

void set_handle(pcap_t *value)
{
	globule->handle = value;
}
pcap_t *get_handle()
{
	return globule->handle;
}

void set_wps(struct wps_data *value)
{
	globule->wps = value;
}
struct wps_data *get_wps()
{
	return globule->wps;
}

void set_ap_htcaps(unsigned char *value, int len)
{
	free(globule->htcaps);
	globule->htcaps = malloc(len);
	globule->htcaps_len = len;
	memcpy(globule->htcaps, value, len);
}

unsigned char *get_ap_htcaps(int *len)
{
	*len = globule->htcaps_len;
	return globule->htcaps;
}

void set_ap_rates(unsigned char *value, int len)
{
	if(globule->ap_rates)
	{
		free(globule->ap_rates);
		globule->ap_rates_len = 0;
	}

	globule->ap_rates = malloc(len);
	if(globule->ap_rates)
	{
		memcpy(globule->ap_rates, value, len);
		globule->ap_rates_len = len;
	}
}

unsigned char *get_ap_rates(int *len)
{
	*len = globule->ap_rates_len;
	return globule->ap_rates;
}

void set_ap_ext_rates(unsigned char *value, int len)
{
	if(globule->ap_ext_rates)
	{
		free(globule->ap_ext_rates);
		globule->ap_ext_rates_len = 0;
	}

	globule->ap_ext_rates = malloc(len);
	if(globule->ap_ext_rates)
	{
		memcpy(globule->ap_ext_rates, value, len);
		globule->ap_ext_rates_len = len;
	}
}

unsigned char *get_ap_ext_rates(int *len)
{
	*len = globule->ap_ext_rates_len;
	return globule->ap_ext_rates;
}

void set_exec_string(char *string)
{
	if(globule->exec_string)
	{
		free(globule->exec_string);
		globule->exec_string = NULL;
	}

	if(string)
	{
		globule->exec_string = strdup(string);
	}
}
char *get_exec_string(void)
{
	return globule->exec_string;
}

void set_oo_send_nack(int value)
{
	globule->oo_send_nack = value;
}
int get_oo_send_nack(void)
{
	return globule->oo_send_nack;
}

void set_vendor(int is_set, const unsigned char* v) {
	globule->vendor_oui[0] = is_set;
	if(is_set) memcpy(globule->vendor_oui+1, v, 3);
}
unsigned char *get_vendor(void) {
	if(!globule->vendor_oui[0]) return 0;
	return globule->vendor_oui+1;
}

void set_repeat_m6(int val) {
	globule->repeat_m6 = val;
}

int get_repeat_m6(void) {
	return globule->repeat_m6;
}

int get_output_fd(void) { return globule->output_fd; }

#include "pcapfile.h"
void set_output_fd(int fd) {
	globule->output_fd = fd;
	if (fd != -1) pcapfile_write_header(fd);
}