12
12
#include <string.h>
13
13
#include <sys/stat.h>
14
14
#include <unistd.h>
15
+ #include <regex.h>
15
16
16
17
#if defined (__APPLE__ ) || defined(__OpenBSD__ )
17
18
#include <sys/socket.h>
@@ -113,8 +114,10 @@ static int essidlenmin;
113
114
static int essidlenmax ;
114
115
static int filteressidlen ;
115
116
static char * filteressidptr ;
117
+ static regex_t essidregex ;
116
118
static int filteressidpartlen ;
117
119
static char * filteressidpartptr ;
120
+ static char * filteressidregexptr ;
118
121
119
122
static char * filtervendorptr ;
120
123
static char * filtervendorapptr ;
@@ -157,6 +160,7 @@ static void closelists(void)
157
160
{
158
161
if (hashlist != NULL ) free (hashlist );
159
162
if (ouilist != NULL ) free (ouilist );
163
+ if (filteressidregexptr != NULL ) regfree (& essidregex );
160
164
if (ctxhmac != NULL )
161
165
{
162
166
EVP_MAC_CTX_free (ctxhmac );
@@ -268,6 +272,7 @@ if(essidlenmin != 0) fprintf(stdout, "filter by ESSID len min.......: %d\n", e
268
272
if (essidlenmax != 32 ) fprintf (stdout , "filter by ESSID len max.......: %d\n" , essidlenmax );
269
273
if (filteressidptr != NULL ) fprintf (stdout , "filter by ESSID...............: %s\n" , filteressidptr );
270
274
if (filteressidpartptr != NULL ) fprintf (stdout , "filter by part of ESSID.......: %s\n" , filteressidpartptr );
275
+ if (filteressidregexptr != NULL ) fprintf (stdout , "filter by ESSID RegEx.........: %s\n" , filteressidregexptr );
271
276
if (flagfiltermacap == true)
272
277
{
273
278
vendor = getvendor (filtermacap );
@@ -608,6 +613,7 @@ static void writejohnrecord(FILE *fh_john, hashlist_t *zeiger)
608
613
{
609
614
static wpakey_t * wpak ;
610
615
static int i ;
616
+ static char essid [ESSID_LEN_MAX + 1 ];
611
617
static unsigned char * hcpos ;
612
618
static hccap_t hccap ;
613
619
@@ -626,6 +632,12 @@ if(filteressidpartptr != NULL)
626
632
{
627
633
if (ispartof (filteressidpartlen , (uint8_t * )filteressidpartptr , zeiger -> essidlen , zeiger -> essid ) == false) return ;
628
634
}
635
+ if (filteressidregexptr != NULL )
636
+ {
637
+ strncpy (essid , (char * )zeiger -> essid , zeiger -> essidlen );
638
+ essid [zeiger -> essidlen ] = '\0' ;
639
+ if (regexec (& essidregex , essid , 0 , NULL , 0 ) == REG_NOMATCH ) return ;
640
+ }
629
641
if ((filtervendorptr != NULL ) || (filtervendorapptr != NULL ) || (filtervendorclientptr != NULL ))
630
642
{
631
643
if (isoui (zeiger -> ap , zeiger -> client ) == false) return ;
@@ -675,7 +687,7 @@ if(hccap.keyver == 1) fprintf(fh_john, "::WPA");
675
687
else fprintf (fh_john , "::WPA2" );
676
688
if ((zeiger -> mp & 0x7 ) == 0 ) fprintf (fh_john , ":not verified" );
677
689
else fprintf (fh_john , ":verified" );
678
- fprintf (fh_john , ":converted by hcxhastool \n" );
690
+ fprintf (fh_john , ":converted by hcxhashtool \n" );
679
691
johneapolwrittencount ++ ;
680
692
return ;
681
693
}
@@ -725,6 +737,7 @@ typedef struct hccap_s hccap_t;
725
737
726
738
static wpakey_t * wpak ;
727
739
static hccap_t hccap ;
740
+ static char essid [ESSID_LEN_MAX + 1 ];
728
741
729
742
if (zeiger -> type == HCX_TYPE_PMKID ) return ;
730
743
if ((zeiger -> essidlen < essidlenmin ) || (zeiger -> essidlen > essidlenmax )) return ;
@@ -742,6 +755,12 @@ if(filteressidpartptr != NULL)
742
755
{
743
756
if (ispartof (filteressidpartlen , (uint8_t * )filteressidpartptr , zeiger -> essidlen , zeiger -> essid ) == false) return ;
744
757
}
758
+ if (filteressidregexptr != NULL )
759
+ {
760
+ strncpy (essid , (char * ) zeiger -> essid , zeiger -> essidlen );
761
+ essid [zeiger -> essidlen ] = '\0' ;
762
+ if (regexec (& essidregex , essid , 0 , NULL , 0 ) == REG_NOMATCH ) return ;
763
+ }
745
764
if ((filtervendorptr != NULL ) || (filtervendorapptr != NULL ) || (filtervendorclientptr != NULL ))
746
765
{
747
766
if (isoui (zeiger -> ap , zeiger -> client ) == false) return ;
@@ -829,6 +848,7 @@ static void writehccapxrecord(FILE *fh_hccapx, hashlist_t *zeiger)
829
848
{
830
849
static wpakey_t * wpak ;
831
850
static hccapx_t hccapx ;
851
+ static char essid [ESSID_LEN_MAX + 1 ];
832
852
833
853
if (zeiger -> type == HCX_TYPE_PMKID ) return ;
834
854
if ((zeiger -> essidlen < essidlenmin ) || (zeiger -> essidlen > essidlenmax )) return ;
@@ -846,6 +866,12 @@ if(filteressidpartptr != NULL)
846
866
{
847
867
if (ispartof (filteressidpartlen , (uint8_t * )filteressidpartptr , zeiger -> essidlen , zeiger -> essid ) == false) return ;
848
868
}
869
+ if (filteressidregexptr != NULL )
870
+ {
871
+ strncpy (essid , (char * ) zeiger -> essid , zeiger -> essidlen );
872
+ essid [zeiger -> essidlen ] = '\0' ;
873
+ if (regexec (& essidregex , essid , 0 , NULL , 0 ) == REG_NOMATCH ) return ;
874
+ }
849
875
if ((filtervendorptr != NULL ) || (filtervendorapptr != NULL ) || (filtervendorclientptr != NULL ))
850
876
{
851
877
if (isoui (zeiger -> ap , zeiger -> client ) == false) return ;
@@ -989,6 +1015,7 @@ return;
989
1015
static void writepmkideapolhashline (FILE * fh_pmkideapol , hashlist_t * zeiger )
990
1016
{
991
1017
static int p ;
1018
+ static char essid [ESSID_LEN_MAX + 1 ];
992
1019
993
1020
if ((zeiger -> essidlen < essidlenmin ) || (zeiger -> essidlen > essidlenmax )) return ;
994
1021
if (((zeiger -> type & hashtype ) != HCX_TYPE_PMKID ) && ((zeiger -> type & hashtype ) != HCX_TYPE_EAPOL )) return ;
@@ -1005,6 +1032,14 @@ if(filteressidpartptr != NULL)
1005
1032
{
1006
1033
if (ispartof (filteressidpartlen , (uint8_t * )filteressidpartptr , zeiger -> essidlen , zeiger -> essid ) == false) return ;
1007
1034
}
1035
+ if (filteressidregexptr != NULL )
1036
+ {
1037
+ strncpy (essid , (char * ) zeiger -> essid , zeiger -> essidlen );
1038
+ essid [zeiger -> essidlen ] = '\0' ;
1039
+ //p = regexec(&essidregex, essid, 0, NULL, 0);
1040
+ //printf("%d\n", p);
1041
+ if (regexec (& essidregex , essid , 0 , NULL , 0 ) == REG_NOMATCH ) return ;
1042
+ }
1008
1043
if ((filtervendorptr != NULL ) || (filtervendorapptr != NULL ) || (filtervendorclientptr != NULL ))
1009
1044
{
1010
1045
if (isoui (zeiger -> ap , zeiger -> client ) == false) return ;
@@ -1266,6 +1301,7 @@ static uint8_t keyver;
1266
1301
static uint8_t keyinfo ;
1267
1302
static uint64_t rc ;
1268
1303
static char * vendor ;
1304
+ static char essid [ESSID_LEN_MAX + 1 ];
1269
1305
1270
1306
if ((zeiger -> essidlen < essidlenmin ) || (zeiger -> essidlen > essidlenmax )) return ;
1271
1307
if (((zeiger -> type & hashtype ) != HCX_TYPE_PMKID ) && ((zeiger -> type & hashtype ) != HCX_TYPE_EAPOL )) return ;
@@ -1282,6 +1318,12 @@ if(filteressidpartptr != NULL)
1282
1318
{
1283
1319
if (ispartof (filteressidpartlen , (uint8_t * )filteressidpartptr , zeiger -> essidlen , zeiger -> essid ) == false) return ;
1284
1320
}
1321
+ if (filteressidregexptr != NULL )
1322
+ {
1323
+ strncpy (essid , (char * ) zeiger -> essid , zeiger -> essidlen );
1324
+ essid [zeiger -> essidlen ] = '\0' ;
1325
+ if (regexec (& essidregex , essid , 0 , NULL , 0 ) == REG_NOMATCH ) return ;
1326
+ }
1285
1327
if ((filtervendorptr != NULL ) || (filtervendorapptr != NULL ) || (filtervendorclientptr != NULL ))
1286
1328
{
1287
1329
if (isoui (zeiger -> ap , zeiger -> client ) == false) return ;
@@ -2359,6 +2401,7 @@ fprintf(stdout, "%s %s (C) %s ZeroBeat\n"
2359
2401
"--essid-partx=<part of ESSID>: filter by part of ESSID (case insensitive)\n"
2360
2402
" locale and wide characters are ignored\n"
2361
2403
"--essid-list=<file> : filter by ESSID file\n"
2404
+ "--essid-regex=<regex> : filter ESSID by regular expression\n"
2362
2405
"--mac-ap=<MAC> : filter AP by MAC\n"
2363
2406
" format: 001122334455, 00:11:22:33:44:55, 00-11-22-33-44-55 (hex)\n"
2364
2407
"--mac-client=<MAC> : filter CLIENT by MAC\n"
@@ -2480,6 +2523,7 @@ static const struct option long_options[] =
2480
2523
{"essid-part" , required_argument , NULL , HCX_FILTER_ESSID_PART },
2481
2524
{"essid-partx" , required_argument , NULL , HCX_FILTER_ESSID_PARTX },
2482
2525
{"essid-list" , required_argument , NULL , HCX_FILTER_ESSID_LIST_IN },
2526
+ {"essid-regex" , required_argument , NULL , HCX_FILTER_ESSID_REGEX },
2483
2527
{"mac-ap" , required_argument , NULL , HCX_FILTER_MAC_AP },
2484
2528
{"mac-client" , required_argument , NULL , HCX_FILTER_MAC_CLIENT },
2485
2529
{"mac-list" , required_argument , NULL , HCX_FILTER_MAC_LIST_IN },
@@ -2542,6 +2586,7 @@ macinstring = NULL;
2542
2586
pmkinstring = NULL ;
2543
2587
filteressidptr = NULL ;
2544
2588
filteressidpartptr = NULL ;
2589
+ filteressidregexptr = NULL ;
2545
2590
filtervendorptr = NULL ;
2546
2591
filtervendorapptr = NULL ;
2547
2592
filtervendorclientptr = NULL ;
@@ -2700,6 +2745,16 @@ while((auswahl = getopt_long (argc, argv, short_options, long_options, &index))
2700
2745
essidinname = optarg ;
2701
2746
break ;
2702
2747
2748
+ case HCX_FILTER_ESSID_REGEX :
2749
+ filteressidregexptr = optarg ;
2750
+ p1 = regcomp (& essidregex , filteressidregexptr , REG_EXTENDED );
2751
+ if (p1 )
2752
+ {
2753
+ fprintf (stderr , "Could not compile regex\n" );
2754
+ exit (EXIT_FAILURE );
2755
+ }
2756
+ break ;
2757
+
2703
2758
case HCX_HASH_MIN :
2704
2759
lcmin = strtol (optarg , NULL , 10 );
2705
2760
break ;
0 commit comments