home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <string.h>
- #include <dos/dos.h>
- #include <exec/memory.h>
-
- /* duh */
- #define TRUE 1 /* generic true/false because i don't want to waste time */
- #define FALSE 0 /* including exec/types.h so there. */
-
- /* the following for passwd structure traversal */
- #define USER 1 /* at user field in line */
- #define PASSWD 2 /* at passwd field in passwd entry */
- #define DONE 3 /* at rest of crap and we can ignore this stuff */
-
- /* maximum values for internal passwd structure */
- #define NAMESIZE 11 /* for struct passwd and for parsepass routine */
- #define SALTSIZE 3
- #define PASSWDSIZE 14
- #define WORDSIZE 20 /* maximum size of password in command line or password in dictfile */
-
- /* values for return() from getnextdict */
- #define DICT_DONE 1 /* dictionary has been exhausted */
- #define DICT_ERROR 2 /* dictionary file is corrupt or something else just as fucked up */
-
- int CXBRK(void) {return(0);} /* sorry user we're gonna make SURE that you can't */
- int chkabort(void) {return(0);} /* f--k us up without giving us chance to clean up */
-
- /*
- ** TODO: Must arrange the passwords according to salt values so that
- ** similar salts get called consecutively. This speeds crypt() up
- ** considerably! Ie: A LOT!!!
- */
- struct passwd
- {
- char name[NAMESIZE];
- char salt[SALTSIZE];
- char password[PASSWDSIZE];
- struct passwd *nextitem;
- };
-
- FILE *dictionary;
-
- char *crypt(char *, char *);
- struct passwd *parsepass(char *);
- void cleanup(struct passwd *);
- void log(char *, char *, char *);
- long getnextdict(char *, char *);
-
- void main(int argc, char *argv[])
- {
- unsigned int counter;
- unsigned int c=FALSE;
- unsigned char commandword[WORDSIZE];
-
- struct passwd *firstitem=NULL;
- struct passwd *currentitem=NULL;
-
- long actualsigs;
- long waitmask = SIGBREAKF_CTRL_C;
- long status;
-
- dictionary=NULL; /* i don't want to do this more than once */
-
- for (counter = 0; counter < argc; counter++)
- {
- if (argv[counter][0] == '-')
- {
- c = TRUE;
- for (counter=1; counter < WORDSIZE; counter++)
- {
- commandword[counter-1] = argv[2][counter];
- if (commandword[counter-1] == 0) break;
- }
- break;
- }
- if (argv[counter][0] == '?')
- {
- usage:
- printf("Usage: %s <passwdfile> -<word> [outputfile]\n", argv[0]);
- printf(" %s <passwdfile> <dictfile> [outputfile]\n", argv[0]);
- printf(" %s ?\n", argv[0]);
- printf("This program written in Feb 23, '97 by sudog.\n");
- printf("So there.\n");
- exit(0);
- }
- }
-
- counter = 0;
-
- if (argc > 2)
- {
- if (firstitem = parsepass(argv[1]))
- {
- currentitem = firstitem;
- /*
- ** This section deals with command-line supplied password.
- */
- if (c)
- {
- while (currentitem != NULL)
- {
- if (!strcmp(currentitem->password, crypt(commandword, currentitem->salt)))
- {
- printf("%s %s\n", currentitem->name, commandword);
- if (argc > 3)
- {
- log(argv[3], currentitem->name, commandword);
- }
- }
- actualsigs = CheckSignal(waitmask);
- if (actualsigs)
- {
- break;
- }
- currentitem = currentitem->nextitem;
- }
- }
- /*
- ** This section deals with a dictionary file!
- ** TODO:
- ** Add place holder so a system crash can be survived and iterations can
- ** continue from last point... VERY cool. let's do som background cracking!
- */
- else
- {
- while ( 1 )
- {
- if (!(status=getnextdict(commandword, argv[2])))
- {
- while (currentitem != NULL)
- {
- if (!strcmp(currentitem->password, crypt(commandword, currentitem->salt)))
- {
- printf("%s %s\n", currentitem->name, commandword);
- if (argc > 3)
- {
- log(argv[3], currentitem->name, commandword);
- }
- }
- actualsigs = CheckSignal(waitmask);
- if (actualsigs)
- {
- getnextdict(NULL, NULL);
- cleanup(firstitem);
- }
- currentitem = currentitem->nextitem;
- }
- currentitem = firstitem;
- }
- else
- {
- if (status == DICT_DONE)
- {
- break;
- }
- if (status == DICT_ERROR) /* getnextdict is smart enough to clean up as much as possible after error */
- {
- printf("Error: Dictionary file error.\n");
- break;
- }
- }
- }
- }
- }
- else
- {
- printf("Error in parsing password file.\n");
- }
- }
- else
- {
- printf("Error. You don't have a clue. Here. Have one.\n");
- goto usage;
- }
-
- cleanup(firstitem);
-
- }
-
- long getnextdict(char *commandword, char *filename)
- {
- long counter=0;
- int gotone=FALSE;
- char temp;
-
- if (commandword == NULL && filename == NULL)
- {
- if (dictionary)
- {
- fclose(dictionary);
- }
- return(0);
- }
- if (!dictionary)
- {
- if (!(dictionary = fopen(filename, "r")))
- {
- return(DICT_ERROR);
- }
- }
- if (dictionary)
- {
- while ( 1 )
- {
- temp = fgetc(dictionary);
- if (feof(dictionary))
- {
- if (gotone)
- {
- commandword[counter] = 0;
- return(0);
- }
- else
- {
- return(DICT_DONE);
- }
- }
- if (temp > 31 && temp < 127)
- {
- if (gotone == FALSE)
- {
- gotone = TRUE;
- }
- if (counter < WORDSIZE)
- {
- commandword[counter++] = temp;
- }
- }
- else
- {
- if (gotone == TRUE)
- {
- commandword[counter] = 0;
- return(0);
- }
- }
- }
- }
- }
-
- void cleanup(struct passwd *firstitem)
- {
- struct passwd *currentitem;
- while (firstitem != NULL)
- {
- currentitem = firstitem->nextitem;
- FreeMem(firstitem, sizeof(struct passwd));
- firstitem = currentitem;
- }
- getnextdict(NULL,NULL);
- exit(0);
- }
-
- void log (char *filename, char *username, char *password)
- {
- FILE *output;
-
- if (output = fopen(filename, "a"))
- {
- fprintf(output, "%s %s\n", username, password);
- fclose(output);
- }
- else
- {
- printf("Error: Unable to open output file!\n");
- }
- }
-
- struct passwd *parsepass(char *filename)
- {
- struct passwd *currentitem=NULL;
- struct passwd *firstitem=NULL;
- unsigned int counter = 0;
- unsigned int state = USER;
- unsigned int ff = FALSE;
- FILE *input;
- char temp;
-
-
- if (input = fopen(filename, "r"))
- {
- while ( 1 )
- {
- temp = fgetc(input);
- if (feof(input)) break;
- if (temp > 31 && temp < 127)
- {
- if (ff == FALSE)
- {
- ff = TRUE;
- if (!firstitem)
- {
- if (firstitem = (struct passwd *)AllocMem(sizeof(struct passwd), MEMF_CLEAR))
- {
- currentitem = firstitem;
- state = USER;
- counter = 0;
- }
- else
- {
- printf("Error: Can't allocate %d bytes..\n", sizeof(struct passwd));
- break;
- }
- }
- else
- {
- if (!(currentitem->nextitem = (struct passwd *)AllocMem(sizeof(struct passwd), MEMF_CLEAR)))
- {
- printf("Error: Can't allocate %d bytes.\n", sizeof(struct passwd));
- break;
- }
- currentitem = currentitem->nextitem;
- state = USER;
- counter = 0;
- }
- }
- if (state == USER)
- {
- if (temp != ':' && counter < NAMESIZE)
- {
- currentitem->name[counter++] = temp;
- }
- if (temp == ':')
- {
- state = PASSWD;
- counter = 0;
- }
- }
- else if (state == PASSWD)
- {
- if (temp != ':' && counter < 2)
- {
- currentitem->salt[counter] = temp;
- }
- if (counter == 2)
- {
- currentitem->salt[counter] = 0;
- }
- if (temp != ':' && counter < PASSWDSIZE)
- {
- currentitem->password[counter++] = temp;
- }
- if (temp == ':')
- {
- state = DONE;
- counter = 0;
- }
- }
- }
- else
- {
- state = USER;
- ff = FALSE;
- }
- }
- }
- else
- {
- printf("Error: Unable to open specified passwd file.\n");
- }
- return(firstitem);
- }
-