aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDavid M. Syzdek <david@syzdek.net>2023-01-06 03:18:27 -0900
committerDavid M. Syzdek <david@syzdek.net>2023-01-06 03:18:27 -0900
commitb78e7a6b0212f54ea09ad63ec8cb126c3732c9b5 (patch)
tree95b471dcacdd74a4ed340685b3d3c638671b6c8c
parent27b32e23dfc9bd3001e31de1b653a2ece9f82fbf (diff)
downloadotputils-b78e7a6b0212f54ea09ad63ec8cb126c3732c9b5.tar.gz
otputils-b78e7a6b0212f54ea09ad63ec8cb126c3732c9b5.tar.bz2
otputils-b78e7a6b0212f54ea09ad63ec8cb126c3732c9b5.tar.xz
otputils-b78e7a6b0212f54ea09ad63ec8cb126c3732c9b5.zip
otp-altdict: adding ability to specify case combinations
-rw-r--r--src/otp-altdict.c188
1 files changed, 175 insertions, 13 deletions
diff --git a/src/otp-altdict.c b/src/otp-altdict.c
index 4d24099..1f5314b 100644
--- a/src/otp-altdict.c
+++ b/src/otp-altdict.c
@@ -99,6 +99,14 @@
99 99
100#define MY_DFLT_WORD_MAXLEN 4 100#define MY_DFLT_WORD_MAXLEN 4
101 101
102#define MY_CASE_LOWER 0x01
103#define MY_CASE_UPPER 0x02
104#define MY_CASE_CAPITALIZE 0x04
105#define MY_CASE_CAMEL 0x08
106#define MY_CASE_INVERT_CAMEL 0x10
107#define MY_CASE_FIRST 0x20
108#define MY_CASE_SECOND 0x40
109
102 110
103///////////////// 111/////////////////
104// // 112// //
@@ -115,7 +123,9 @@ struct _my_config
115 int fd; 123 int fd;
116 int allow_hex; 124 int allow_hex;
117 int allow_dups; 125 int allow_dups;
126 int word_case;
118 int ignore_warnings; 127 int ignore_warnings;
128 int pad_int;
119 size_t word_maxlen; 129 size_t word_maxlen;
120 size_t buff_len; 130 size_t buff_len;
121 size_t buff_off; 131 size_t buff_off;
@@ -194,6 +204,13 @@ my_buff_process_word(
194 const char * word ); 204 const char * word );
195 205
196 206
207static int
208my_buff_process_word_hash(
209 my_config_t * cnf,
210 const char * word,
211 int word_len );
212
213
197static void 214static void
198my_verbose( 215my_verbose(
199 my_config_t * cnf, 216 my_config_t * cnf,
@@ -220,12 +237,6 @@ my_word_cmp_obj(
220///////////////// 237/////////////////
221#pragma mark - Functions 238#pragma mark - Functions
222 239
223
224//---------------//
225// main function //
226//---------------//
227#pragma mark main function
228
229int 240int
230main( 241main(
231 int argc, 242 int argc,
@@ -239,7 +250,7 @@ main(
239 char * endptr; 250 char * endptr;
240 251
241 // getopt options 252 // getopt options
242 static const char * short_opt = "a:dHhil:o:qVv"; 253 static const char * short_opt = "12Aa:CdHhiLl:Mo:qUVvW";
243 static struct option long_opt[] = 254 static struct option long_opt[] =
244 { 255 {
245 {"help", no_argument, NULL, 'h' }, 256 {"help", no_argument, NULL, 'h' },
@@ -268,6 +279,18 @@ main(
268 case 0: /* long options toggles */ 279 case 0: /* long options toggles */
269 break; 280 break;
270 281
282 case '1':
283 cnf->word_case |= MY_CASE_FIRST;
284 break;
285
286 case '2':
287 cnf->word_case |= MY_CASE_SECOND;
288 break;
289
290 case 'A':
291 cnf->word_case = 0xFFFFFF;
292 break;
293
271 case 'a': 294 case 'a':
272 if ((cnf->evp_md = EVP_get_digestbyname(optarg)) == NULL) 295 if ((cnf->evp_md = EVP_get_digestbyname(optarg)) == NULL)
273 { 296 {
@@ -277,6 +300,10 @@ main(
277 }; 300 };
278 break; 301 break;
279 302
303 case 'C':
304 cnf->word_case |= MY_CASE_CAPITALIZE;
305 break;
306
280 case 'd': 307 case 'd':
281 cnf->allow_dups = 1; 308 cnf->allow_dups = 1;
282 break; 309 break;
@@ -288,16 +315,24 @@ main(
288 case 'h': 315 case 'h':
289 printf("Usage: %s [OPTIONS] <wordlist>\n", PROGRAM_NAME); 316 printf("Usage: %s [OPTIONS] <wordlist>\n", PROGRAM_NAME);
290 printf("OPTIONS:\n"); 317 printf("OPTIONS:\n");
318 printf(" -1 capitalize first half of word (e.g. \"WOrd\"\n");
319 printf(" -2 capitalize second half of word (e.g. \"woRD\"\n");
320 printf(" -A add word with all variations\n");
291 printf(" -a algorithm hash algorithm for alt dictionary (default: sha1)\n"); 321 printf(" -a algorithm hash algorithm for alt dictionary (default: sha1)\n");
322 printf(" -C add word as capitalized (e.g. \"Word\"\n");
292 printf(" -d allow duplicates with S/KEY dictionary\n"); 323 printf(" -d allow duplicates with S/KEY dictionary\n");
293 printf(" -H use words which only contain hexadecimal characters\n"); 324 printf(" -H use words which only contain hexadecimal characters\n");
294 printf(" -h, --help print this help and exit\n"); 325 printf(" -h, --help print this help and exit\n");
295 printf(" -i ignore warnings\n"); 326 printf(" -i ignore warnings\n");
327 printf(" -L add word as lower case (e.g. \"word\"\n");
296 printf(" -l length maximum word length (default: %i)\n", MY_DFLT_WORD_MAXLEN); 328 printf(" -l length maximum word length (default: %i)\n", MY_DFLT_WORD_MAXLEN);
329 printf(" -M add word as inverted camel case (e.g. \"wOrD\"\n");
297 printf(" -o file output file\n"); 330 printf(" -o file output file\n");
298 printf(" -q, --quiet, --silent do not print messages\n"); 331 printf(" -q, --quiet, --silent do not print messages\n");
332 printf(" -U add word as upper case (e.g. \"WORD\"\n");
299 printf(" -V, --version print version number and exit\n"); 333 printf(" -V, --version print version number and exit\n");
300 printf(" -v, --verbose print verbose messages\n"); 334 printf(" -v, --verbose print verbose messages\n");
335 printf(" -W add word as camel case (e.g. \"WoRd\"\n");
301 printf("ALGORITHMS:\n"); 336 printf("ALGORITHMS:\n");
302 printf(" md4\n"); 337 printf(" md4\n");
303 printf(" md5\n"); 338 printf(" md5\n");
@@ -311,6 +346,10 @@ main(
311 cnf->ignore_warnings = 1; 346 cnf->ignore_warnings = 1;
312 break; 347 break;
313 348
349 case 'L':
350 cnf->word_case |= MY_CASE_LOWER;
351 break;
352
314 case 'l': 353 case 'l':
315 cnf->word_maxlen = strtoull(optarg, &endptr, 0); 354 cnf->word_maxlen = strtoull(optarg, &endptr, 0);
316 if ( (optarg == endptr) || ((endptr[0])) ) 355 if ( (optarg == endptr) || ((endptr[0])) )
@@ -321,6 +360,10 @@ main(
321 }; 360 };
322 break; 361 break;
323 362
363 case 'M':
364 cnf->word_case |= MY_CASE_INVERT_CAMEL;
365 break;
366
324 case 'o': 367 case 'o':
325 cnf->file_out = optarg; 368 cnf->file_out = optarg;
326 break; 369 break;
@@ -329,6 +372,10 @@ main(
329 cnf->quiet = 1; 372 cnf->quiet = 1;
330 break; 373 break;
331 374
375 case 'U':
376 cnf->word_case |= MY_CASE_UPPER;
377 break;
378
332 case 'V': 379 case 'V':
333 printf("%s (%s) %s\n", PROGRAM_NAME, PACKAGE_NAME, PACKAGE_VERSION); 380 printf("%s (%s) %s\n", PROGRAM_NAME, PACKAGE_NAME, PACKAGE_VERSION);
334 printf("Written by David M. Syzdek.\n"); 381 printf("Written by David M. Syzdek.\n");
@@ -338,6 +385,10 @@ main(
338 cnf->verbose++; 385 cnf->verbose++;
339 break; 386 break;
340 387
388 case 'W':
389 cnf->word_case |= MY_CASE_CAMEL;
390 break;
391
341 case '?': 392 case '?':
342 fprintf(stderr, "Try `%s --help' for more information.\n", PROGRAM_NAME); 393 fprintf(stderr, "Try `%s --help' for more information.\n", PROGRAM_NAME);
343 return(1); 394 return(1);
@@ -361,6 +412,9 @@ main(
361 return(1); 412 return(1);
362 }; 413 };
363 414
415 if (!(cnf->word_case))
416 cnf->word_case = MY_CASE_LOWER;
417
364 // open file and loop through word list 418 // open file and loop through word list
365 my_info(cnf, "generating dictionary: processing word list\n"); 419 my_info(cnf, "generating dictionary: processing word list\n");
366 if (stat(argv[optind], &cnf->sb) == -1) 420 if (stat(argv[optind], &cnf->sb) == -1)
@@ -497,10 +551,9 @@ my_buff_process_word(
497{ 551{
498 size_t pos; 552 size_t pos;
499 int hexonly; 553 int hexonly;
500 unsigned char md[EVP_MAX_MD_SIZE]; 554 int x;
501 unsigned md_len; 555 int len;
502 int val; 556 char * str;
503 int rc;
504 557
505 // checks syntax of word 558 // checks syntax of word
506 hexonly = 1; 559 hexonly = 1;
@@ -542,9 +595,118 @@ my_buff_process_word(
542 595
543 my_verbose(cnf, "word '%s': processing\n", word); 596 my_verbose(cnf, "word '%s': processing\n", word);
544 597
545 // generate hash 598 // copy word
599 if ((str = bindle_strdup(word)) == NULL)
600 {
601 my_error("out of virtual memory\n");
602 return(-1);
603 };
604 len = (int)strlen(str);
605
606 // generate hash for lower case word
607 if ((cnf->word_case & MY_CASE_LOWER))
608 {
609 for(x = 0; ((str[x])); x++)
610 str[x] = tolower(str[x]);
611 if (my_buff_process_word_hash(cnf, str, len) == -1)
612 {
613 free(str);
614 return(-1);
615 };
616 };
617
618 // generates hash for first letter capital
619 if ((cnf->word_case & MY_CASE_CAPITALIZE))
620 {
621 for(x = 1; ((str[x])); x++)
622 str[x] = tolower(str[x]);
623 str[0] = toupper(str[0]);
624 if (my_buff_process_word_hash(cnf, str, len) == -1)
625 {
626 free(str);
627 return(-1);
628 };
629 };
630
631 // generates hash for upper case word
632 if ((cnf->word_case & MY_CASE_UPPER))
633 {
634 for(x = 0; ((str[x])); x++)
635 str[x] = toupper(str[x]);
636 if (my_buff_process_word_hash(cnf, str, len) == -1)
637 {
638 free(str);
639 return(-1);
640 };
641 };
642
643 // generates hash for camel case word
644 if ((cnf->word_case & MY_CASE_CAMEL))
645 {
646 for(x = 0; ((str[x])); x++)
647 str[x] = ((x & 0x01)) ? tolower(str[x]) : toupper(str[x]);
648 if (my_buff_process_word_hash(cnf, str, len) == -1)
649 {
650 free(str);
651 return(-1);
652 };
653 };
654
655 // generates hash for inverted camel case word
656 if ((cnf->word_case & MY_CASE_INVERT_CAMEL))
657 {
658 for(x = 0; ((str[x])); x++)
659 str[x] = ((x & 0x01)) ? toupper(str[x]) : tolower(str[x]);
660 if (my_buff_process_word_hash(cnf, str, len) == -1)
661 {
662 free(str);
663 return(-1);
664 };
665 };
666
667 // generates hash for first half of word capitalized
668 if ((cnf->word_case & MY_CASE_FIRST))
669 {
670 for(x = 0; ((str[x])); x++)
671 str[x] = ((len/2) > x) ? toupper(str[x]) : tolower(str[x]);
672 if (my_buff_process_word_hash(cnf, str, len) == -1)
673 {
674 free(str);
675 return(-1);
676 };
677 };
678
679 // generates hash for second half of word capitalized
680 if ((cnf->word_case & MY_CASE_FIRST))
681 {
682 for(x = 0; ((str[x])); x++)
683 str[x] = ((len/2) < x) ? toupper(str[x]) : tolower(str[x]);
684 if (my_buff_process_word_hash(cnf, str, len) == -1)
685 {
686 free(str);
687 return(-1);
688 };
689 };
690
691 free(str);
692
693 return(0);
694}
695
696
697int
698my_buff_process_word_hash(
699 my_config_t * cnf,
700 const char * word,
701 int word_len )
702{
703 unsigned char md[EVP_MAX_MD_SIZE];
704 unsigned md_len;
705 int val;
706 int rc;
707
546 md_len = sizeof(md); 708 md_len = sizeof(md);
547 if (!(EVP_Digest(word, pos, md, &md_len, cnf->evp_md, NULL))) 709 if (!(EVP_Digest(word, word_len, md, &md_len, cnf->evp_md, NULL)))
548 { 710 {
549 my_error("unable to geneate hash for '%s'\n", word); 711 my_error("unable to geneate hash for '%s'\n", word);
550 return(-1); 712 return(-1);