home *** CD-ROM | disk | FTP | other *** search
/ The Hacker's Encyclopedia 1998 / hackers_encyclopedia.iso / programs / kc9_src.arj / PWP.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-07  |  27.6 KB  |  963 lines

  1. /****************************************************************************\
  2.  
  3. **        Password Preprocesser v2.00 - Password Cracker Guess Mutator      **
  4.  
  5. ** ======================================================================== **
  6.  
  7. **                Sourcefile: pwp.c -- Last Update: 09/20/91                **
  8.  
  9. ** ======================================================================== **
  10.  
  11. **           Written By Doctor Dissector, Copyright (C) 1990, 1991          **
  12.  
  13. ** ======================================================================== **
  14.  
  15. **                   LIMITED EDITION -- DO NOT DISTRIBUTE                   **
  16.  
  17. \****************************************************************************/
  18.  
  19.  
  20.  
  21. /*=[ License ]==============================================================*/
  22.  
  23.  
  24.  
  25. /*
  26.  
  27. ** Password Preprocesser - Version 2.00
  28.  
  29. ** Copyright (C) 1991 By Doctor Dissector
  30.  
  31. **
  32.  
  33. ** This program is NOT free software BUT may be used without charge or
  34.  
  35. ** payment in any form IF your copy is a "registered" distributed version.
  36.  
  37. ** You may modify it as much as you please, however, you MAY NOT re-
  38.  
  39. ** distribute it, in any shape or for: ie. modified OR unmodified,
  40.  
  41. ** without the expressed written consent (ie. e-mail) of
  42.  
  43. ** Doctor Dissector.
  44.  
  45. **
  46.  
  47. ** This program was initially distributed in the hope that it will be
  48.  
  49. ** useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  50.  
  51. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  52.  
  53. */
  54.  
  55.  
  56.  
  57. /*=[ Disclaimer ]===========================================================*/
  58.  
  59.  
  60.  
  61. /*
  62.  
  63. **  The author of this package, Doctor Dissector, will not assume liability
  64.  
  65. **  for ANY of the effects of the use or distribution of this package.  If
  66.  
  67. **  you, at ANY time compile or use this package, you will assume full
  68.  
  69. **  liability for your own actions; Doctor Dissector can neither enforce the
  70.  
  71. **  lawful use of this package nor your actions before, during, or after
  72.  
  73. **  exposure to this package.  Doctor Dissector does NOT endorse your unlawful
  74.  
  75. **  use of this package to appropriate computer accounts not under your lawful
  76.  
  77. **  ownership.
  78.  
  79. **
  80.  
  81. **  The original intent of this package was to prove that Un*x accounts can be
  82.  
  83. **  easily, efficiently, and effectively cracked utilizing modified DES
  84.  
  85. **  encryption routines and proper statistical, mathematical, logical, and
  86.  
  87. **  programming skills.
  88.  
  89. */
  90.  
  91.  
  92.  
  93. /*=[ Copyright ]============================================================*/
  94.  
  95.  
  96.  
  97. char pwp_c_msg[] = "Source: pwp.c, Copyright (C) 1990, 1991 By Doctor Dissector";
  98.  
  99.  
  100.  
  101. /*=[ Include Header Files ]=================================================*/
  102.  
  103.  
  104.  
  105. #include <stdio.h>
  106.  
  107. #include <string.h>
  108.  
  109. #include "pwp.h"
  110.  
  111.  
  112.  
  113. /*=[ Global Variables ]=====================================================*/
  114.  
  115.  
  116.  
  117. char progname[MAX_FILE];        /* calling name of the program */
  118.  
  119.  
  120.  
  121. int  double_w,                  /* double words?               0 = NO       */
  122.  
  123.      gecos,                     /* use GECOS fields?           0 = NO       */
  124.  
  125.      include,                   /* include sourcefile?         0 = NO       */
  126.  
  127.      kc,                        /* killer cracker format?      0 = NO       */
  128.  
  129.      logins,                    /* use login fields?           0 = NO       */
  130.  
  131.      lowercase,                 /* all lowercase?              0 = NO       */
  132.  
  133.      lowreverse,                /* lowercase & reverse?        0 = NO       */
  134.  
  135.      minlength,                 /* minimum length              0 = Inactive */
  136.  
  137.      nonalpha,                  /* minimum non-alpha chars     0 = Inactive */
  138.  
  139.      novowels,                  /* remove vowels?              0 = NO       */
  140.  
  141.      reverse,                   /* reverse?                    0 = NO       */
  142.  
  143.      upchar,                    /* make one char uppercase     0 = Inactive */
  144.  
  145.      uplast,                    /* last char uppercase?        0 = NO       */
  146.  
  147.      uppercase,                 /* all uppercase?              0 = NO       */
  148.  
  149.      upreverse,                 /* uppercase & reverse?        0 = NO       */
  150.  
  151.      translate;                 /* character/character xlate?  0 = Inactive */
  152.  
  153.  
  154.  
  155. char prefixes[MAX_TAIL],        /* prefix characters */
  156.  
  157.      suffixes[MAX_TAIL],        /* suffix characters */
  158.  
  159.      xchar[MAX_XCHAR][2];       /* xlate character table */
  160.  
  161.  
  162.  
  163. /*==========================================================================*/
  164.  
  165.  
  166.  
  167. /*
  168.  
  169. **     function: void print_usage(void)
  170.  
  171. **  description: displays program usage & options
  172.  
  173. **      returns: nothing
  174.  
  175. */
  176.  
  177.  
  178.  
  179. void print_usage()
  180.  
  181. {
  182.  
  183.     printf("\n");
  184.  
  185.     printf("Password Preprocesser, Version 2.00 (9/20/91)\n");
  186.  
  187.     printf("Copyright (C) 1991, By Doctor Dissector\n");
  188.  
  189.     printf("*** DO NOT DISTRIBUTE THIS VERSION ***\n\n");
  190.  
  191.     printf("Brief:  Mutates a wordlist read from the standard input into other possible\n");
  192.  
  193.     printf("        guesses for use with password 'crackers' and outputs the result to\n");
  194.  
  195.     printf("        the standard output.\n\n");
  196.  
  197.     printf("Usage:  %s [[flag] ...] < [wordlist|pwfile] > [resultfile]\n\n", progname);
  198.  
  199.     printf("Flags:  -?                  display this usage menu\n");
  200.  
  201.     printf("        -Double             doubles the original word\n");
  202.  
  203.     printf("        -Gecos              create result words from GECOS fields of pwfile\n");
  204.  
  205.     printf("        -Help               display this usage menu\n");
  206.  
  207.     printf("        -Include            include original words into resultfile\n");
  208.  
  209.     printf("        -Kc                 save login/GECOS words in KC9 'single-crack' form\n");
  210.  
  211.     printf("        -LOGins             create result words from login fields of pwfile\n");
  212.  
  213.     printf("        -LOWErcase          convert original words to lowercase\n");
  214.  
  215.     printf("        -LOWReverse         convert original words to lowercase & reverse\n");
  216.  
  217.     printf("        -Minlength:<#>      min length <#> of result words\n");
  218.  
  219.     printf("        -NONalpha:<#>       min non-alphabetic chars <#> in result words\n");
  220.  
  221.     printf("        -NOVowels           remove vowels from original words\n");
  222.  
  223.     printf("        -Prefixes:<string>  prepend chars in <string> to original words\n");
  224.  
  225.     printf("        -Reverse            reverse original words\n");
  226.  
  227.     printf("        -Suffixes:<string>  append chars in <string> to original words\n");
  228.  
  229.     printf("        -Translate:<o><n>   translate char <o> in original words char <n>\n");
  230.  
  231.     printf("        -UPChar:<#>         convert char <#> in original words to uppercase\n");
  232.  
  233.     printf("        -UPLast             convert last char in original words to uppercase\n");
  234.  
  235.     printf("        -UPPercase          convert original words to uppercase\n");
  236.  
  237.     printf("        -UPReverse          convert original words to uppercase & reverse\n\n");
  238.  
  239. }
  240.  
  241.  
  242.  
  243. /*==========================================================================*/
  244.  
  245.  
  246.  
  247. /*
  248.  
  249. **     function: void init_vars(void)
  250.  
  251. **  description: pre-initialize global variables
  252.  
  253. **      returns: nothing
  254.  
  255. */
  256.  
  257.  
  258.  
  259. void init_vars()
  260.  
  261. {
  262.  
  263.     progname[0]=0;
  264.  
  265.     double_w=0;
  266.  
  267.     gecos=0;
  268.  
  269.     include=0;
  270.  
  271.     kc=0;
  272.  
  273.     logins=0;
  274.  
  275.     lowercase=0;
  276.  
  277.     lowreverse=0;
  278.  
  279.     minlength=0;
  280.  
  281.     nonalpha=0;
  282.  
  283.     novowels=0;
  284.  
  285.     reverse=0;
  286.  
  287.     translate=0;
  288.  
  289.     upchar=0;
  290.  
  291.     uplast=0;
  292.  
  293.     uppercase=0;
  294.  
  295.     upreverse=0;
  296.  
  297.     prefixes[0]=0;
  298.  
  299.     suffixes[0]=0;
  300.  
  301. }
  302.  
  303.  
  304.  
  305. /*==========================================================================*/
  306.  
  307.  
  308.  
  309. /*
  310.  
  311. **     function: void eexit(int exitcode, char *desc1, char *desc2)
  312.  
  313. **  description: displays an exit/error message and exits with an exit
  314.  
  315. **               code of <exitcode>
  316.  
  317. **      returns: nothing
  318.  
  319. */
  320.  
  321.  
  322.  
  323. void eexit(exitcode, desc1, desc2)
  324.  
  325.     int  exitcode;
  326.  
  327.     char *desc1, *desc2;
  328.  
  329. {
  330.  
  331.     fprintf(stderr, "\n%s: ", progname);
  332.  
  333.     if (desc1)
  334.  
  335.         fprintf(stderr, "%s", desc1);
  336.  
  337.     else
  338.  
  339.         fprintf(stderr, "abnormal program termination");
  340.  
  341.     if (desc2)
  342.  
  343.         fprintf(stderr, ": %s", desc2);
  344.  
  345.     fprintf(stderr, "\n");
  346.  
  347.     exit(exitcode);
  348.  
  349. }
  350.  
  351.  
  352.  
  353. /*==========================================================================*/
  354.  
  355.  
  356.  
  357. /*
  358.  
  359. **     function: int chstrnum(char xc, char *word)
  360.  
  361. **  description: counts the number occurrances of <xc> in <word>
  362.  
  363. **      returns: number of occurrances, 0 if none
  364.  
  365. */
  366.  
  367.  
  368.  
  369. int chstrnum(xc, word)
  370.  
  371.     char xc, *word;
  372.  
  373. {
  374.  
  375.     register int i;
  376.  
  377.  
  378.  
  379.     for(i=0; (*word); word++)
  380.  
  381.         if (xc==(*word))
  382.  
  383.             i++;
  384.  
  385.     return(i);
  386.  
  387. }
  388.  
  389.  
  390.  
  391. /*==========================================================================*/
  392.  
  393.  
  394.  
  395. /*
  396.  
  397. **     function: char upcharacter(char c)
  398.  
  399. **  description: converts <c> to an uppercase equivalent
  400.  
  401. **      returns: uppercase <c> if any
  402.  
  403. */
  404.  
  405.  
  406.  
  407. char upcharacter(c)
  408.  
  409.     register char c;
  410.  
  411. {
  412.  
  413.     return((c>='a') && (c<='z') ? c-32 : c);
  414.  
  415. }
  416.  
  417.  
  418.  
  419. /*==========================================================================*/
  420.  
  421.  
  422.  
  423. /*
  424.  
  425. **     function: char *lowcase(char *str)
  426.  
  427. **  description: converts <str> to its lowercase equivalent
  428.  
  429. **      returns: lowercase of <str>
  430.  
  431. */
  432.  
  433.  
  434.  
  435. char *lowcase(str)
  436.  
  437.     register char *str;
  438.  
  439. {
  440.  
  441.     register char *ptr;
  442.  
  443.     static   char s[MAX_WORD];
  444.  
  445.  
  446.  
  447.     ptr=s;
  448.  
  449.     while(*str)
  450.  
  451.         (*ptr++)=(((*str)>='A') && ((*str)<='Z') ? (*str++)+32 : (*str++));
  452.  
  453.     *ptr=0;
  454.  
  455.     return(s);
  456.  
  457. }
  458.  
  459.  
  460.  
  461. /*==========================================================================*/
  462.  
  463.  
  464.  
  465. /*
  466.  
  467. **     function: char *upcase(char *str)
  468.  
  469. **  description: converts <str> to its uppercase equivalent
  470.  
  471. **      returns: uppercase of <str>
  472.  
  473. */
  474.  
  475.  
  476.  
  477. char *upcase(str)
  478.  
  479.     register char *str;
  480.  
  481. {
  482.  
  483.     register char *ptr;
  484.  
  485.     static   char s[MAX_WORD];
  486.  
  487.  
  488.  
  489.     ptr=s;
  490.  
  491.     while(*str)
  492.  
  493.         (*ptr++)=(((*str)>='a') && ((*str)<='z') ? (*str++)-32 : (*str++));
  494.  
  495.     *ptr=0;
  496.  
  497.     return(s);
  498.  
  499. }
  500.  
  501.  
  502.  
  503. /*==========================================================================*/
  504.  
  505.  
  506.  
  507. /*
  508.  
  509. **     function: char *reverse_string(char *str)
  510.  
  511. **  description: reverse string <str>
  512.  
  513. **      returns: the reverse of <str>
  514.  
  515. */
  516.  
  517.  
  518.  
  519. char *reverse_string(str)
  520.  
  521.     register char *str;
  522.  
  523. {
  524.  
  525.     register int  i, j;
  526.  
  527.     static   char s[MAX_WORD];
  528.  
  529.  
  530.  
  531.     i=strlen(str);
  532.  
  533.     s[i]=0;
  534.  
  535.     while(*str)
  536.  
  537.         s[--i]=(*str++);
  538.  
  539.     return(s);
  540.  
  541. }
  542.  
  543.  
  544.  
  545. /*==========================================================================*/
  546.  
  547.  
  548.  
  549. /*
  550.  
  551. **     function: char *do_lowercase(char *word)
  552.  
  553. **  description: creates lowercase equivalent of <word>
  554.  
  555. **      returns: lowercase equivalent of <word> or "\0" if both words match
  556.  
  557. */
  558.  
  559.  
  560.  
  561. char *do_lowercase(word)
  562.  
  563.     char *word;
  564.  
  565. {
  566.  
  567.     static char s[MAX_WORD];
  568.  
  569.  
  570.  
  571.     strcpy(s, lowcase(word));
  572.  
  573.     if (include)
  574.  
  575.         if (!strcmp(s, word))
  576.  
  577.             s[0]=0;
  578.  
  579.     return(s);
  580.  
  581. }
  582.  
  583.  
  584.  
  585. /*==========================================================================*/
  586.  
  587.  
  588.  
  589. /*
  590.  
  591. **     function: char *do_uppercase(char *word)
  592.  
  593. **  description: creates uppercase equivalent of <word>
  594.  
  595. **      returns: uppercase equivalent of <word> or "\0" if both words match
  596.  
  597. */
  598.  
  599.  
  600.  
  601. char *do_uppercase(word)
  602.  
  603.     char *word;
  604.  
  605. {
  606.  
  607.     static char s[MAX_WORD];
  608.  
  609.  
  610.  
  611.     strcpy(s, upcase(word));
  612.  
  613.     if (include)
  614.  
  615.         if (!strcmp(s, word))
  616.  
  617.             s[0]=0;
  618.  
  619.     return(s);
  620.  
  621. }
  622.  
  623.  
  624.  
  625. /*==========================================================================*/
  626.  
  627.  
  628.  
  629. /*
  630.  
  631. **     function: char *do_reverse(char *word)
  632.  
  633. **  description: reverses <word>
  634.  
  635. **      returns: reverse of <word> or "\0" if both words match
  636.  
  637. */
  638.  
  639.  
  640.  
  641. char *do_reverse(word)
  642.  
  643.     char *word;
  644.  
  645. {
  646.  
  647.     static char s[MAX_WORD];
  648.  
  649.  
  650.  
  651.     strcpy(s, reverse_string(word));
  652.  
  653.     if (include)
  654.  
  655.         if (!strcmp(s, word))
  656.  
  657.             s[0]=0;
  658.  
  659.     return(s);
  660.  
  661. }
  662.  
  663.  
  664.  
  665. /*==========================================================================*/
  666.  
  667.  
  668.  
  669. /*
  670.  
  671. **     function: char *do_lowreverse(char *word)
  672.  
  673. **  description: converts <word> to lowercase & reverses it
  674.  
  675. **      returns: lowered/reversed <word> or "\0" if both words match
  676.  
  677. */
  678.  
  679.  
  680.  
  681. char *do_lowreverse(word)
  682.  
  683.     char *word;
  684.  
  685. {
  686.  
  687.     static char s[MAX_WORD];
  688.  
  689.  
  690.  
  691.     strcpy(s, lowcase(reverse_string(word)));
  692.  
  693.     if (reverse)
  694.  
  695.         if (!strcmp(s, reverse_string(word)))
  696.  
  697.             s[0]=0;
  698.  
  699.     if ((lowercase) && (s[0]))
  700.  
  701.         if (!strcmp(s, lowcase(word)))
  702.  
  703.             s[0]=0;
  704.  
  705.     if ((include) && (s[0]))
  706.  
  707.         if (!strcmp(s, word))
  708.  
  709.             s[0]=0;
  710.  
  711.     return(s);
  712.  
  713. }
  714.  
  715.  
  716.  
  717. /*==========================================================================*/
  718.  
  719.  
  720.  
  721. /*
  722.  
  723. **     function: char *do_upreverse(char *word)
  724.  
  725. **  description: converts <word> to uppercase & reverses it
  726.  
  727. **      returns: uppered/reversed <word> or "\0" if both words match
  728.  
  729. */
  730.  
  731.  
  732.  
  733. char *do_upreverse(word)
  734.  
  735.     char *word;
  736.  
  737. {
  738.  
  739.     static char s[MAX_WORD];
  740.  
  741.  
  742.  
  743.     strcpy(s, upcase(reverse_string(word)));
  744.  
  745.     if (reverse)
  746.  
  747.         if (!strcmp(s, reverse_string(word)))
  748.  
  749.             s[0]=0;
  750.  
  751.     if ((uppercase) && (s[0]))
  752.  
  753.         if (!strcmp(s, upcase(word)))
  754.  
  755.             s[0]=0;
  756.  
  757.     if ((include) && (s[0]))
  758.  
  759.         if (!strcmp(s, word))
  760.  
  761.             s[0]=0;
  762.  
  763.     return(s);
  764.  
  765. }
  766.  
  767.  
  768.  
  769. /*==========================================================================*/
  770.  
  771.  
  772.  
  773. /*
  774.  
  775. **     function: char *uplast_word(char *word)
  776.  
  777. **  description: converts the last character in <word> to uppercase
  778.  
  779. **      returns: converted <word>
  780.  
  781. */
  782.  
  783.  
  784.  
  785. char *uplast_word(word)
  786.  
  787.     char *word;
  788.  
  789. {
  790.  
  791.     static char s[MAX_WORD];
  792.  
  793.  
  794.  
  795.     strcpy(s, word);
  796.  
  797.     s[strlen(word)-1]=upcharacter(word[strlen(word)-1]);
  798.  
  799.     return(s);
  800.  
  801. }
  802.  
  803.  
  804.  
  805. /*==========================================================================*/
  806.  
  807.  
  808.  
  809. /*
  810.  
  811. **     function: char *do_uplast(char *word)
  812.  
  813. **  description: converts the last character in <word> to uppercase
  814.  
  815. **      returns: converted <word> or "\0" if both words match
  816.  
  817. */
  818.  
  819.  
  820.  
  821. char *do_uplast(word)
  822.  
  823.     char *word;
  824.  
  825. {
  826.  
  827.     static char s[MAX_WORD];
  828.  
  829.  
  830.  
  831.     strcpy(s, uplast_word(word));
  832.  
  833.     if (uppercase)
  834.  
  835.         if (!strcmp(s, upcase(word)))
  836.  
  837.             s[0]=0;
  838.  
  839.     if ((include) && (s[0]))
  840.  
  841.         if (!strcmp(s, word))
  842.  
  843.             s[0]=0;
  844.  
  845.     return(s);
  846.  
  847. }
  848.  
  849.  
  850.  
  851. /*==========================================================================*/
  852.  
  853.  
  854.  
  855. /*
  856.  
  857. **     function: char *do_upchar(char *word, int ch)
  858.  
  859. **  description: converts the character at index <ch-1> in <word> to uppercase
  860.  
  861. **      returns: converted <word> or "\0" if both words match
  862.  
  863. */
  864.  
  865.  
  866.  
  867. char *do_upchar(word, ch)
  868.  
  869.     char *word;
  870.  
  871.           int  ch;
  872.  
  873. {
  874.  
  875.     static char s[MAX_WORD];
  876.  
  877.  
  878.  
  879.     strcpy(s, word);
  880.  
  881.     s[ch-1]=upcharacter(word[ch-1]);
  882.  
  883.     if (uppercase)
  884.  
  885.         if (!strcmp(s, upcase(word)))
  886.  
  887.             s[0]=0;
  888.  
  889.     if (uplast)
  890.  
  891.         if (!strcmp(s, uplast_word(word)))
  892.  
  893.             s[0]=0;
  894.  
  895.     if (strlen(word)<ch)
  896.  
  897.         s[0]=0;
  898.  
  899.     if ((include) && (s[0]))
  900.  
  901.         if (!strcmp(s, word))
  902.  
  903.             s[0]=0;
  904.  
  905.     return(s);
  906.  
  907. }
  908.  
  909.  
  910.  
  911. /*==========================================================================*/
  912.  
  913.  
  914.  
  915. /*
  916.  
  917. **     function: char *do_novowels(char *word)
  918.  
  919. **  description: removes vowels from <word>
  920.  
  921. **      returns: vowel-less <word> or "\0" if both words match
  922.  
  923. */
  924.  
  925.  
  926.  
  927. char *do_novowels(word)
  928.  
  929.     char *word;
  930.  
  931. {
  932.  
  933.     register int  i, j;
  934.  
  935.     static   char s[MAX_WORD], c;
  936.  
  937.  
  938.  
  939.     for(i=0, j=0; word[i]; i++) {
  940.  
  941.         c=upcharacter(word[i]);
  942.  
  943.         if (!((c=='A') || (c=='E') || (c=='I') || (c=='O') || (c=='U')))
  944.  
  945.             s[j++]=word[i];
  946.  
  947.     }
  948.  
  949.     s[j]=0;
  950.  
  951.     if (include)
  952.  
  953.         if (!strcmp(s, word))
  954.  
  955.             s[0]=0;
  956.  
  957.     return(s);
  958.  
  959. }
  960.  
  961.  
  962.  
  963. /*==========================================================================*/
  964.  
  965.  
  966.  
  967. /*
  968.  
  969. **     function: char *do_double(char *word)
  970.  
  971. **  description: doubles the <word> if its length is less than 8
  972.  
  973. **      returns: doubled <word> or "\0" if <word> is longer than 7 chars
  974.  
  975. */
  976.  
  977.  
  978.  
  979. char *do_double(word)
  980.  
  981.     char *word;
  982.  
  983. {
  984.  
  985.     static   char s[MAX_WORD];
  986.  
  987.  
  988.  
  989.     if (strlen(word)<8)
  990.  
  991.         sprintf(s, "%s%s", word, word);
  992.  
  993.     else
  994.  
  995.         s[0]=0;
  996.  
  997.     return(s);
  998.  
  999. }
  1000.  
  1001.  
  1002.  
  1003. /*==========================================================================*/
  1004.  
  1005.  
  1006.  
  1007. /*
  1008.  
  1009. **     function: char *do_prefixes(char *word, char prechar)
  1010.  
  1011. **  description: pre-pends the <word> with the character <prechar>
  1012.  
  1013. **      returns: pre-pended <word>
  1014.  
  1015. */
  1016.  
  1017.  
  1018.  
  1019. char *do_prefixes(word, prechar)
  1020.  
  1021.     char *word, prechar;
  1022.  
  1023. {
  1024.  
  1025.     static char s[MAX_WORD];
  1026.  
  1027.  
  1028.  
  1029.     sprintf(s, "%c%s", prechar, word);
  1030.  
  1031.     return(s);
  1032.  
  1033. }
  1034.  
  1035.  
  1036.  
  1037. /*==========================================================================*/
  1038.  
  1039.  
  1040.  
  1041. /*
  1042.  
  1043. **     function: char *do_suffixes(char *word, char postchar)
  1044.  
  1045. **  description: post-pends the <word> with the character <word>'s length
  1046.  
  1047. **               is less than 8 characters
  1048.  
  1049. **      returns: post-pended <word> or "\0" if the <word> is 8 characters
  1050.  
  1051. **               or longer
  1052.  
  1053. */
  1054.  
  1055.  
  1056.  
  1057. char *do_suffixes(word, postchar)
  1058.  
  1059.     char *word, postchar;
  1060.  
  1061. {
  1062.  
  1063.     static char s[MAX_WORD];
  1064.  
  1065.  
  1066.  
  1067.     if (strlen(word)<8)
  1068.  
  1069.         sprintf(s, "%s%c", word, postchar);
  1070.  
  1071.     else
  1072.  
  1073.         s[0]=0;
  1074.  
  1075.     return(s);
  1076.  
  1077. }
  1078.  
  1079.  
  1080.  
  1081. /*==========================================================================*/
  1082.  
  1083.  
  1084.  
  1085. /*
  1086.  
  1087. **     function: char *do_xlate_char(char *word, char *xc, int pos)
  1088.  
  1089. **  description: translates the <pos>th occurance xc[0] to xc[1]
  1090.  
  1091. **      returns: translated word
  1092.  
  1093. */
  1094.  
  1095.  
  1096.  
  1097. char *do_xlate_char(word, xc, pos)
  1098.  
  1099.     char *word, *xc;
  1100.  
  1101.     int  pos;
  1102.  
  1103. {
  1104.  
  1105.     register int  i, j;
  1106.  
  1107.     static   char s[MAX_WORD];
  1108.  
  1109.  
  1110.  
  1111.     strcpy(s, word);
  1112.  
  1113.     for(i=0, j=0; (s[i]); i++) {
  1114.  
  1115.         if (s[i]==xc[0])
  1116.  
  1117.             if (++j>pos)
  1118.  
  1119.                 break;
  1120.  
  1121.     }
  1122.  
  1123.     if (s[i])
  1124.  
  1125.         s[i]=xc[1];
  1126.  
  1127.     else
  1128.  
  1129.         s[0]=0;
  1130.  
  1131.     return(s);
  1132.  
  1133. }
  1134.  
  1135.  
  1136.  
  1137. /*==========================================================================*/
  1138.  
  1139.  
  1140.  
  1141. /*
  1142.  
  1143. **     function: char *do_xlate_all(char *word, char *xc)
  1144.  
  1145. **  description: translates all occurances of xc[0] to xc[1]
  1146.  
  1147. **      returns: translated <word>
  1148.  
  1149. */
  1150.  
  1151.  
  1152.  
  1153. char *do_xlate_all(word, xc)
  1154.  
  1155.     char *word, *xc;
  1156.  
  1157. {
  1158.  
  1159.     register int  i;
  1160.  
  1161.     static   char s[MAX_WORD];
  1162.  
  1163.  
  1164.  
  1165.     for(i=0; word[i]; i++) {
  1166.  
  1167.         if (word[i]==xc[0])
  1168.  
  1169.             s[i]=xc[1];
  1170.  
  1171.         else
  1172.  
  1173.             s[i]=word[i];
  1174.  
  1175.     }
  1176.  
  1177.     s[i]=0;
  1178.  
  1179.     return(s);
  1180.  
  1181. }
  1182.  
  1183.  
  1184.  
  1185. /*==========================================================================*/
  1186.  
  1187.  
  1188.  
  1189. /*
  1190.  
  1191. **     function: int do_nonalpha(char *word)
  1192.  
  1193. **  description: counts the number of non-alphabetic characters in <word>
  1194.  
  1195. **      returns: number of non-alphabetic characters in <word>
  1196.  
  1197. */
  1198.  
  1199.  
  1200.  
  1201. int do_nonalpha(word)
  1202.  
  1203.     char *word;
  1204.  
  1205. {
  1206.  
  1207.     register int i, okchars;
  1208.  
  1209.  
  1210.  
  1211.     for(i=0, okchars=0; word[i]; i++) {
  1212.  
  1213.         if (!(((word[i]>='A') && (word[i]<='Z')) ||
  1214.  
  1215.             ((word[i]>='a') && (word[i]<='z'))))
  1216.  
  1217.             okchars++;
  1218.  
  1219.     }
  1220.  
  1221.     return(okchars);
  1222.  
  1223. }
  1224.  
  1225.  
  1226.  
  1227. /*==========================================================================*/
  1228.  
  1229.  
  1230.  
  1231. /*
  1232.  
  1233. **     function: void do_result(char *word)
  1234.  
  1235. **  description: checks for minimum length of <word> and minimum
  1236.  
  1237. **               non-alphabetic characters in <word> before writing
  1238.  
  1239. **               the <word> to stdout
  1240.  
  1241. **      returns: nothing
  1242.  
  1243. */
  1244.  
  1245.  
  1246.  
  1247. void do_result(word)
  1248.  
  1249.     char *word;
  1250.  
  1251. {
  1252.  
  1253.     if (!word[0])
  1254.  
  1255.         return;
  1256.  
  1257.     if (minlength)
  1258.  
  1259.         if (strlen(word)<minlength)
  1260.  
  1261.             return;
  1262.  
  1263.     if (nonalpha)
  1264.  
  1265.         if (do_nonalpha(word)<nonalpha)
  1266.  
  1267.             return;
  1268.  
  1269.     printf("%s\n", word);
  1270.  
  1271. }
  1272.  
  1273.  
  1274.  
  1275. /*==========================================================================*/
  1276.  
  1277.  
  1278.  
  1279. /*
  1280.  
  1281. **     function: void process_word(char *word)
  1282.  
  1283. **  description: processes one original <word> for mutation
  1284.  
  1285. **      returns: nothing
  1286.  
  1287. */
  1288.  
  1289.  
  1290.  
  1291. void process_word(word)
  1292.  
  1293.     char *word;
  1294.  
  1295. {
  1296.  
  1297.     int i, j, k;
  1298.  
  1299.  
  1300.  
  1301.     if (include)
  1302.  
  1303.         do_result(word);
  1304.  
  1305.     if (lowercase)
  1306.  
  1307.         do_result(do_lowercase(word));
  1308.  
  1309.     if (uppercase)
  1310.  
  1311.         do_result(do_uppercase(word));
  1312.  
  1313.     if (reverse)
  1314.  
  1315.         do_result(do_reverse(word));
  1316.  
  1317.     if (lowreverse)
  1318.  
  1319.         do_result(do_lowreverse(word));
  1320.  
  1321.     if (upreverse)
  1322.  
  1323.         do_result(do_upreverse(word));
  1324.  
  1325.     if (uplast)
  1326.  
  1327.         do_result(do_uplast(word));
  1328.  
  1329.     if (upchar)
  1330.  
  1331.         do_result(do_upchar(word, upchar));
  1332.  
  1333.     if (novowels)
  1334.  
  1335.         do_result(do_novowels(word));
  1336.  
  1337.     if (double_w)
  1338.  
  1339.         do_result(do_double(word));
  1340.  
  1341.     if (prefixes[0]) {
  1342.  
  1343.         for(i=0; prefixes[i]; i++)
  1344.  
  1345.             do_result(do_prefixes(word, prefixes[i]));
  1346.  
  1347.     }
  1348.  
  1349.     if (suffixes[0]) {
  1350.  
  1351.         for(i=0; suffixes[i]; i++)
  1352.  
  1353.             do_result(do_suffixes(word, suffixes[i]));
  1354.  
  1355.     }
  1356.  
  1357.     if (translate) {
  1358.  
  1359.         for(i=0; i<translate; i++) {
  1360.  
  1361.             j=chstrnum(xchar[i][0], word);
  1362.  
  1363.             if (j) {
  1364.  
  1365.                 for(k=0; k<j; k++)
  1366.  
  1367.                     do_result(do_xlate_char(word, &xchar[i], k));
  1368.  
  1369.                 if (j>1)
  1370.  
  1371.                     do_result(do_xlate_all(word, &xchar[i]));
  1372.  
  1373.             }
  1374.  
  1375.         }
  1376.  
  1377.     }
  1378.  
  1379. }
  1380.  
  1381.  
  1382.  
  1383. /*==========================================================================*/
  1384.  
  1385.  
  1386.  
  1387. /*
  1388.  
  1389. **     function: int okgf(char gfc)
  1390.  
  1391. **  description: checks to see if the character is a GECOS delimiting char
  1392.  
  1393. **      returns: 1 if it is a delimiter, 0 if not
  1394.  
  1395. */
  1396.  
  1397.  
  1398.  
  1399. int okgf(gfc)
  1400.  
  1401.     char gfc;
  1402.  
  1403. {
  1404.  
  1405.     if ((gfc!=',') && (gfc!=' ') && (gfc!='*') && (gfc!=':') && (gfc!='.') &&
  1406.  
  1407.         (gfc!='-') && (gfc!='/') && (gfc!=')') && (gfc!='('))
  1408.  
  1409.         return(1);
  1410.  
  1411.     return(0);
  1412.  
  1413. }
  1414.  
  1415.  
  1416.  
  1417. /*==========================================================================*/
  1418.  
  1419.  
  1420.  
  1421. /*
  1422.  
  1423. **     function: void process_line(char *line)
  1424.  
  1425. **  description: processes a single line of /etc/passwd information
  1426.  
  1427. **      returns: nothing
  1428.  
  1429. */
  1430.  
  1431.  
  1432.  
  1433. void process_line(line)
  1434.  
  1435.     char *line;
  1436.  
  1437. {
  1438.  
  1439.     int  i, ok=0;
  1440.  
  1441.     char *login, *epw, *gec, *gecw;
  1442.  
  1443.  
  1444.  
  1445.     for(login=line; (*line!=':') && (*line); line++)
  1446.  
  1447.         ;
  1448.  
  1449.     if (*line) {
  1450.  
  1451.         *line=0;
  1452.  
  1453.         for(epw=++line; (*line!=':') && (*line); line++)
  1454.  
  1455.             ;
  1456.  
  1457.         if (*line) {
  1458.  
  1459.             *line=0;
  1460.  
  1461.             for(++line; (*line!=':') && (*line); line++)
  1462.  
  1463.                 ;
  1464.  
  1465.             if (*line) {
  1466.  
  1467.                 *line=0;
  1468.  
  1469.                 for(++line; (*line!=':') && (*line); line++)
  1470.  
  1471.                     ;
  1472.  
  1473.                 if (*line) {
  1474.  
  1475.                     *line=0;
  1476.  
  1477.                     for(gec=++line; (*line!=':') && (*line); line++)
  1478.  
  1479.                         ;
  1480.  
  1481.                     if (*line) {
  1482.  
  1483.                         *line=0;
  1484.  
  1485.                         ok=1;
  1486.  
  1487.                     }
  1488.  
  1489.                 }
  1490.  
  1491.             }
  1492.  
  1493.         }
  1494.  
  1495.     }
  1496.  
  1497.     if (ok) {
  1498.  
  1499.         if (strlen(epw)>13)
  1500.  
  1501.             epw[13]=0;
  1502.  
  1503.         if ((epw[0]!='*') && (strlen(epw)==13) && (login[0]!='+')) {
  1504.  
  1505.             if (logins)
  1506.  
  1507.                 process_word(login);
  1508.  
  1509.             if (gecos) {
  1510.  
  1511.                 while(*gec) {
  1512.  
  1513.                     for(; (*gec) && (!okgf(*gec)); gec++)
  1514.  
  1515.                         ;
  1516.  
  1517.                     if (*gec) {
  1518.  
  1519.                         gecw=gec;
  1520.  
  1521.                         for(; (*gec) && (okgf(*gec)); gec++)
  1522.  
  1523.                             ;
  1524.  
  1525.                         if (*gec)
  1526.  
  1527.                             *gec++=0;
  1528.  
  1529.                         process_word(gecw);
  1530.  
  1531.                     }
  1532.  
  1533.                 }
  1534.  
  1535.             }
  1536.  
  1537.             if (kc)
  1538.  
  1539.                 printf("***!***\n");
  1540.  
  1541.         }
  1542.  
  1543.     }
  1544.  
  1545. }
  1546.  
  1547.  
  1548.  
  1549. /*==========================================================================*/
  1550.  
  1551.  
  1552.  
  1553. /*
  1554.  
  1555. **     function: void process_pwfile(void)
  1556.  
  1557. **  description: processes /etc/passwd file type info (login/GECOS)
  1558.  
  1559. **      returns: nothing
  1560.  
  1561. */
  1562.  
  1563.  
  1564.  
  1565. void process_pwfile()
  1566.  
  1567. {
  1568.  
  1569.     char line[MAX_LINE];
  1570.  
  1571.  
  1572.  
  1573.     while(gets(line))
  1574.  
  1575.         process_line(line);
  1576.  
  1577. }
  1578.  
  1579.  
  1580.  
  1581.  
  1582.  
  1583. /*==========================================================================*/
  1584.  
  1585.  
  1586.  
  1587. /*
  1588.  
  1589. **     function: void process_wordlist(void)
  1590.  
  1591. **  description: processes each word from a wordlist
  1592.  
  1593. **      returns: nothing
  1594.  
  1595. */
  1596.  
  1597.  
  1598.  
  1599. void process_wordlist()
  1600.  
  1601. {
  1602.  
  1603.     char word[MAX_WORD];
  1604.  
  1605.  
  1606.  
  1607.     while(gets(word)) {
  1608.  
  1609.         if (strcmp(word, "***!***"))
  1610.  
  1611.             process_word(word);
  1612.  
  1613.         else
  1614.  
  1615.             printf("***!***\n");
  1616.  
  1617.     }
  1618.  
  1619. }
  1620.  
  1621.  
  1622.  
  1623. /*==========================================================================*/
  1624.  
  1625.  
  1626.  
  1627. /*
  1628.  
  1629. **     function: int getcmd(char *name)
  1630.  
  1631. **  description: searches [cmdtab] for a matching command
  1632.  
  1633. **      returns: value assigned to each command in [cmdtab] or ERROR_FLAG
  1634.  
  1635. **               upon error
  1636.  
  1637. */
  1638.  
  1639.  
  1640.  
  1641. int getcmd(name)
  1642.  
  1643.     char *name;
  1644.  
  1645. {
  1646.  
  1647.     struct cmd *c;
  1648.  
  1649.  
  1650.  
  1651.     for(c=cmdtab; c; c++) {
  1652.  
  1653.         if (!strncmp(name, c->cmd_name, c->unique)) {
  1654.  
  1655.             if (strlen(name)<=strlen(c->cmd_name)) {
  1656.  
  1657.                 if (!strncmp(name, c->cmd_name, strlen(name)))
  1658.  
  1659.                     return(c->cmd_code);
  1660.  
  1661.             }
  1662.  
  1663.             return(ERROR_FLAG);
  1664.  
  1665.         }
  1666.  
  1667.     }
  1668.  
  1669.     return(ERROR_FLAG);
  1670.  
  1671. }
  1672.  
  1673.  
  1674.  
  1675. /*==========================================================================*/
  1676.  
  1677.  
  1678.  
  1679. /*
  1680.  
  1681. **     function: void process_arg(char *arg)
  1682.  
  1683. **  description: processes the value of one command line argument
  1684.  
  1685. **      returns: nothing
  1686.  
  1687. */
  1688.  
  1689.  
  1690.  
  1691. void process_arg(arg)
  1692.  
  1693.     char *arg;
  1694.  
  1695. {
  1696.  
  1697.     int  result_code, i;
  1698.  
  1699.     char tail[MAX_TAIL];
  1700.  
  1701.  
  1702.  
  1703.     tail[0]=0;
  1704.  
  1705.     for(i=0; (arg[i]!=':') && (arg[i]); i++)
  1706.  
  1707.         ;
  1708.  
  1709.     if (arg[i]) {
  1710.  
  1711.         strcpy(tail, &arg[i+1]);
  1712.  
  1713.         arg[i]=0;
  1714.  
  1715.     }
  1716.  
  1717.     result_code=getcmd(lowcase(arg));
  1718.  
  1719.     switch(result_code) {
  1720.  
  1721.         case DOUBLE_FLAG:
  1722.  
  1723.             double_w=1;
  1724.  
  1725.             break;
  1726.  
  1727.         case GECOS_FLAG:
  1728.  
  1729.             gecos=1;
  1730.  
  1731.             break;
  1732.  
  1733.         case HELP_FLAG:
  1734.  
  1735.             print_usage();
  1736.  
  1737.             exit(0);
  1738.  
  1739.             break;
  1740.  
  1741.         case INCLUDE_FLAG:
  1742.  
  1743.             include=1;
  1744.  
  1745.             break;
  1746.  
  1747.         case KC_FLAG:
  1748.  
  1749.             kc=1;
  1750.  
  1751.             break;
  1752.  
  1753.         case LOGINS_FLAG:
  1754.  
  1755.             logins=1;
  1756.  
  1757.             break;
  1758.  
  1759.         case LOWERCASE_FLAG:
  1760.  
  1761.             lowercase=1;
  1762.  
  1763.             break;
  1764.  
  1765.         case LOWREVERSE_FLAG:
  1766.  
  1767.             lowreverse=1;
  1768.  
  1769.             break;
  1770.  
  1771.         case MINLENGTH_FLAG:
  1772.  
  1773.             minlength=atoi(tail);
  1774.  
  1775.             break;
  1776.  
  1777.         case NONALPHA_FLAG:
  1778.  
  1779.             nonalpha=atoi(tail);
  1780.  
  1781.             break;
  1782.  
  1783.         case NOVOWELS_FLAG:
  1784.  
  1785.             novowels=1;
  1786.  
  1787.             break;
  1788.  
  1789.         case PREFIXES_FLAG:
  1790.  
  1791.             strcpy(prefixes, tail);
  1792.  
  1793.             break;
  1794.  
  1795.         case REVERSE_FLAG:
  1796.  
  1797.             reverse=1;
  1798.  
  1799.             break;
  1800.  
  1801.         case SUFFIXES_FLAG:
  1802.  
  1803.             strcpy(suffixes, tail);
  1804.  
  1805.             break;
  1806.  
  1807.         case UPCHAR_FLAG:
  1808.  
  1809.             upchar=atoi(tail);
  1810.  
  1811.             break;
  1812.  
  1813.         case UPLAST_FLAG:
  1814.  
  1815.             uplast=1;
  1816.  
  1817.             break;
  1818.  
  1819.         case UPPERCASE_FLAG:
  1820.  
  1821.             uppercase=1;
  1822.  
  1823.             break;
  1824.  
  1825.         case UPREVERSE_FLAG:
  1826.  
  1827.             upreverse=1;
  1828.  
  1829.             break;
  1830.  
  1831.         case TRANSLATE_FLAG:
  1832.  
  1833.             if (strlen(tail)>1) {
  1834.  
  1835.                 xchar[translate  ][0]=tail[0];
  1836.  
  1837.                 xchar[translate++][1]=tail[1];
  1838.  
  1839.             }
  1840.  
  1841.             break;
  1842.  
  1843.         default:
  1844.  
  1845.             eexit(1, "invalid argument", arg);
  1846.  
  1847.             break;
  1848.  
  1849.     }
  1850.  
  1851. }
  1852.  
  1853.  
  1854.  
  1855. /*==========================================================================*/
  1856.  
  1857.  
  1858.  
  1859. /*
  1860.  
  1861. **     function: void main(int argc, char **argv)
  1862.  
  1863. **  description: main function
  1864.  
  1865. **      returns: nothing
  1866.  
  1867. */
  1868.  
  1869.  
  1870.  
  1871. void main(argc, argv)
  1872.  
  1873.     int  argc;
  1874.  
  1875.     char **argv;
  1876.  
  1877. {
  1878.  
  1879.     char s[MAX_LINE];
  1880.  
  1881.  
  1882.  
  1883.     init_vars();
  1884.  
  1885.     strcpy(progname, *argv);
  1886.  
  1887.     if (argc==1) {
  1888.  
  1889.         print_usage();
  1890.  
  1891.         exit(0);
  1892.  
  1893.     }
  1894.  
  1895.     for(; --argc; ) {
  1896.  
  1897.         strcpy(s, *++argv);
  1898.  
  1899.         if ((s[0]=='-') || (s[0]=='/'))
  1900.  
  1901.             process_arg(&s[1]);
  1902.  
  1903.         else
  1904.  
  1905.             eexit(1, "invalid argument", s);
  1906.  
  1907.     }
  1908.  
  1909.     if ((kc) && (!gecos) && (!logins))
  1910.  
  1911.         eexit(1, "flag 'kc' must be used with 'logins' or 'gecos'", NULL);
  1912.  
  1913.     if ((gecos) || (logins))
  1914.  
  1915.         process_pwfile();
  1916.  
  1917.     else
  1918.  
  1919.         process_wordlist();
  1920.  
  1921.     exit(0);
  1922.  
  1923. }
  1924.  
  1925.