static void read_file(struct db_main *db, char *name, int flags, void (*process_line)(struct db_main *db, char *line)) { struct stat file_stat; FILE *file; char line[LINE_BUFFER_SIZE]; if (flags & RF_ALLOW_DIR) { if (stat(name, &file_stat)) { if (flags & RF_ALLOW_MISSING) if (errno == ENOENT) return; pexit("stat: %s", path_expand(name)); } else if (S_ISDIR(file_stat.st_mode)) return; } if (!(file = fopen(path_expand(name), "r"))) { if ((flags & RF_ALLOW_MISSING) && errno == ENOENT) return; pexit("fopen: %s", path_expand(name)); } while (fgets(line, sizeof(line), file)) { process_line(db, line); check_abort(0); } if (ferror(file)) pexit("fgets"); if (fclose(file)) pexit("fclose"); }
void cfg_init(char *name, int allow_missing) { FILE *file; char line[LINE_BUFFER_SIZE]; int number; if (cfg_database) return; if (!(file = fopen(path_expand(name), "r"))) { if (allow_missing && errno == ENOENT) return; pexit("fopen: %s", path_expand(name)); } number = 0; while (fgetl(line, sizeof(line), file)) if (cfg_process_line(line, ++number)) cfg_error(name, number); if (ferror(file)) pexit("fgets"); if (fclose(file)) pexit("fclose"); cfg_name = str_alloc_copy(path_expand(name)); }
/* See the comment in recovery.h on how the "save" parameter is used */ void rec_done(int save) { if (!rec_file) return; /* * If we're the main process for a --fork'ed group of children, leave our .rec * file around until the children terminate (at which time we may be called * again with save < 0, meaning forced non-saving). */ if (!save && options.fork && john_main_process) { rec_save(); return; } if (save > 0) rec_save(); else log_flush(); if (fclose(rec_file)) pexit("fclose"); rec_file = NULL; if ((!save || save == -1) && unlink(path_expand(rec_name))) pexit("unlink: %s", path_expand(rec_name)); }
/* See the comment in recovery.h on how the "save" parameter is used */ void rec_done(int save) { if (!rec_file) return; /* * If we're the main process for a --fork'ed group of children, leave our .rec * file around until the children terminate (at which time we may be called * again with save < 0, meaning forced non-saving). */ #ifndef HAVE_MPI if (!save && options.fork && john_main_process) { #else if (!save && (options.fork || mpi_p > 1) && john_main_process) { #endif rec_save(); return; } if (save > 0) rec_save(); else log_flush(); if (fclose(rec_file)) pexit("fclose"); rec_file = NULL; if ((!save || save == -1) && unlink(path_expand(rec_name))) pexit("unlink: %s", path_expand(rec_name)); } static void rec_format_error(char *fn) { path_done(); cleanup_tiny_memory(); /* * MEMDBG_PROGRAM_EXIT_CHECKS() would cause the output * At Program Exit * MemDbg_Validate level 0 checking Passed * to be writen prior to the * Incorrect crash recovery file: ... * output. * Not sure if we want this. */ // MEMDBG_PROGRAM_EXIT_CHECKS(stderr); // FIXME if (fn && errno && ferror(rec_file)) pexit("%s", fn); else { fprintf(stderr, "Incorrect crash recovery file: %s\n", path_expand(rec_name)); error(); } }
static void log_file_init(struct log_file *f, char *name, int size) { f->name = name; if (chmod(path_expand(name), S_IRUSR | S_IWUSR)) if (errno != ENOENT) pexit("chmod: %s", path_expand(name)); if ((f->fd = open(path_expand(name), O_WRONLY | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR)) < 0) pexit("open: %s", path_expand(name)); f->ptr = f->buffer = mem_alloc(size + LINE_BUFFER_SIZE); f->size = size; }
static void cfg_error(char *name, int number) { if (john_main_process) fprintf(stderr, "Error in %s at line %d\n", path_expand(name), number); error(); }
void rec_init(struct db_main *db, void (*save_mode)(FILE *file)) { rec_done(1); if (!rec_argc) return; rec_name_complete(); if ((rec_fd = open(path_expand(rec_name), O_RDWR | O_CREAT, 0600)) < 0) pexit("open: %s", path_expand(rec_name)); rec_lock(); if (!(rec_file = fdopen(rec_fd, "w"))) pexit("fdopen"); rec_db = db; rec_save_mode = save_mode; }
static void cfg_error(char *name, int number) { #ifdef HAVE_MPI if (mpi_id == 0) #endif fprintf(stderr, "Error in %s at line %d\n", path_expand(name), number); error(); }
static void rec_format_error(char *fn) { if (fn && errno && ferror(rec_file)) pexit("%s", fn); else { fprintf(stderr, "Incorrect crash recovery file: %s\n", path_expand(rec_name)); error(); } }
static void rec_lock(void) { if (flock(rec_fd, LOCK_EX | LOCK_NB)) { if (errno == EWOULDBLOCK) { fprintf(stderr, "Crash recovery file is locked: %s\n", path_expand(rec_name)); error(); } else pexit("flock(LOCK_EX)"); } }
main() { String s; while (1) { cout << "Pattern to expand? "; cin >> s; int i = path_expand(s, found, poolcreate, alloc, shrink); // cout << i << " files (mem utilization was " << pool->memory_utilization() << ")\n"; delete pool; } }
static gboolean iimage_graphic_save( Classmodel *classmodel, GtkWidget *parent, const char *filename ) { iImage *iimage = IIMAGE( classmodel ); ImageValue *value = &iimage->value; char buf[FILENAME_MAX]; /* Can't happen nested-ly, so a static is OK. */ static GTimer *timer = NULL; /* We don't want $VAR etc. in the filename we pass down to the file * ops. */ im_strncpy( buf, filename, FILENAME_MAX ); path_expand( buf ); /* Append the mode string. This needs an expanded filename. */ filesel_add_mode( buf ); if( !timer ) timer = g_timer_new(); g_timer_reset( timer ); if( value->ii ) if( !imageinfo_write( value->ii, buf ) ) return( FALSE ); mainw_recent_add( &mainw_recent_image, filename ); if( main_option_time_save ) { double elapsed; elapsed = g_timer_elapsed( timer, NULL ); error_top( _( "Save timer." ) ); error_sub( _( "Image save took %g seconds." ), elapsed ); return( FALSE ); } return( TRUE ); }
char *path_of_tree(struct tree *tree) { int depth, i; struct tree *t, **anc; char *path = NULL; for (t = tree, depth = 1; ! ROOT_P(t); depth++, t = t->parent); if (ALLOC_N(anc, depth) < 0) return NULL; for (t = tree, i = depth - 1; i >= 0; i--, t = t->parent) anc[i] = t; for (i = 0; i < depth; i++) { char *p = path_expand(anc[i], path); free(path); path = p; } FREE(anc); return path; }
void rec_restore_args(int lock) { char line[LINE_BUFFER_SIZE]; int index, argc; char **argv; char *save_rec_name; rec_name_complete(); if (!(rec_file = fopen(path_expand(rec_name), "r+"))) { #ifndef HAVE_MPI if (options.fork && !john_main_process && errno == ENOENT) { #else if (options.node_min > 1 && errno == ENOENT) { #endif fprintf(stderr, "%u Session completed\n", options.node_min); if (options.flags & FLG_STATUS_CHK) return; log_event("No crash recovery file, terminating"); log_done(); #ifdef HAVE_MPI mpi_teardown(); #endif exit(0); } #ifdef HAVE_MPI if (mpi_p > 1) { fprintf(stderr, "%u@%s: fopen: %s: %s\n", mpi_id + 1, mpi_name, path_expand(rec_name), strerror(errno)); error(); } #endif pexit("fopen: %s", path_expand(rec_name)); } rec_fd = fileno(rec_file); if (lock) rec_lock(lock); if (!fgetl(line, sizeof(line), rec_file)) rec_format_error("fgets"); rec_version = 0; if (!strcmp(line, RECOVERY_V4)) rec_version = 4; else if (!strcmp(line, RECOVERY_V3)) rec_version = 3; else if (!strcmp(line, RECOVERY_V2)) rec_version = 2; else if (!strcmp(line, RECOVERY_V1)) rec_version = 1; else if (strcmp(line, RECOVERY_V0)) rec_format_error(NULL); if (fscanf(rec_file, "%d\n", &argc) != 1) rec_format_error("fscanf"); if (argc < 2) rec_format_error(NULL); argv = mem_alloc_tiny(sizeof(char *) * (argc + 1), MEM_ALIGN_WORD); argv[0] = "john"; for (index = 1; index < argc; index++) if (fgetl(line, sizeof(line), rec_file)) argv[index] = str_alloc_copy(line); else rec_format_error("fgets"); argv[argc] = NULL; save_rec_name = rec_name; opt_init(argv[0], argc, argv, 0); rec_name = save_rec_name; rec_name_completed = 1; if (fscanf(rec_file, "%u\n%u\n%x\n%x\n", &status_restored_time, &status.guess_count, &status.combs.lo, &status.combs.hi) != 4) rec_format_error("fscanf"); if (!status_restored_time) status_restored_time = 1; if (rec_version >= 4) { if (fscanf(rec_file, "%x\n%x\n%x\n%x\n%x\n%d\n", &status.combs_ehi, &status.crypts.lo, &status.crypts.hi, &status.cands.lo, &status.cands.hi, &status.compat) != 6) rec_format_error("fscanf"); } else { /* Historically, we were reusing what became the combs field for candidates * count when in --stdout mode */ status.cands = status.combs; status.compat = 1; } if (rec_version == 0) { status.pass = 0; status.progress = -1; } else if (fscanf(rec_file, "%d\n%d\n", &status.pass, &status.progress) != 2) rec_format_error("fscanf"); if (status.pass < 0 || status.pass > 3) rec_format_error(NULL); if (rec_version < 3) rec_check = 0; else if (fscanf(rec_file, "%x\n", &rec_check) != 1) rec_format_error("fscanf"); rec_restoring_now = 1; } void rec_restore_mode(int (*restore_mode)(FILE *file)) { rec_name_complete(); if (!rec_file) return; if (restore_mode) if (restore_mode(rec_file)) rec_format_error("fscanf"); if (options.flags & FLG_MASK_STACKED) if (mask_restore_state(rec_file)) rec_format_error("fscanf"); /* * Unlocking the file explicitly is normally not necessary since we're about to * close it anyway (which would normally release the lock). However, when * we're the main process running with --fork, our newborn children may hold a * copy of the fd for a moment (until they close the fd themselves). Thus, if * we don't explicitly remove the lock, there may be a race condition between * our children closing the fd and us proceeding to re-open and re-lock it. */ rec_unlock(); if (fclose(rec_file)) pexit("fclose"); rec_file = NULL; rec_restoring_now = 0; }
void do_incremental_crack(struct db_main *db, char *mode) { char *charset; int min_length, max_length, max_count; char *extra; FILE *file; struct charset_header *header; unsigned int check; char allchars[CHARSET_SIZE + 1]; char char1[CHARSET_SIZE + 1]; char2_table char2; chars_table chars[CHARSET_LENGTH - 2]; unsigned char *ptr; unsigned int length, fixed, count; unsigned int real_count; int last_length, last_count; int pos; if (!mode) { if (db->format == &fmt_LM) mode = "LanMan"; else if (db->format == &fmt_NETLM) mode = "LanMan"; else if (db->format == &fmt_NETHALFLM) mode = "LanMan"; else mode = "All"; } log_event("Proceeding with \"incremental\" mode: %.100s", mode); if (!(charset = cfg_get_param(SECTION_INC, mode, "File"))) { log_event("! No charset defined"); fprintf(stderr, "No charset defined for mode: %s\n", mode); error(); } extra = cfg_get_param(SECTION_INC, mode, "Extra"); if ((min_length = cfg_get_int(SECTION_INC, mode, "MinLen")) < 0) min_length = 0; if ((max_length = cfg_get_int(SECTION_INC, mode, "MaxLen")) < 0) max_length = CHARSET_LENGTH; max_count = cfg_get_int(SECTION_INC, mode, "CharCount"); if (min_length > max_length) { log_event("! MinLen = %d exceeds MaxLen = %d", min_length, max_length); fprintf(stderr, "MinLen = %d exceeds MaxLen = %d\n", min_length, max_length); error(); } if (min_length > db->format->params.plaintext_length) { log_event("! MinLen = %d is too large for this hash type", min_length); fprintf(stderr, "MinLen = %d exceeds the maximum possible " "length for the current hash type (%d)\n", min_length, db->format->params.plaintext_length); error(); } if (max_length > db->format->params.plaintext_length) { log_event("! MaxLen = %d is too large for this hash type", max_length); fprintf(stderr, "Warning: " "MaxLen = %d is too large for the current hash type, " "reduced to %d\n", max_length, db->format->params.plaintext_length); max_length = db->format->params.plaintext_length; } if (max_length > CHARSET_LENGTH) { log_event("! MaxLen = %d exceeds the compile-time limit of %d", max_length, CHARSET_LENGTH); fprintf(stderr, "\n" "MaxLen = %d exceeds the compile-time limit of %d\n\n" "There are several good reasons why you probably don't " "need to raise it:\n" "- many hash types don't support passwords " "(or password halves) longer than\n" "7 or 8 characters;\n" "- you probably don't have sufficient statistical " "information to generate a\n" "charset file for lengths beyond 8;\n" "- the limitation applies to incremental mode only.\n", max_length, CHARSET_LENGTH); error(); } if (!(file = fopen(path_expand(charset), "rb"))) pexit("fopen: %s", path_expand(charset)); header = (struct charset_header *)mem_alloc(sizeof(*header)); charset_read_header(file, header); if (ferror(file)) pexit("fread"); if (feof(file) || (memcmp(header->version, CHARSET_V1, sizeof(header->version)) && memcmp(header->version, CHARSET_V2, sizeof(header->version))) || !header->count) inc_format_error(charset); if (header->min != CHARSET_MIN || header->max != CHARSET_MAX || header->length != CHARSET_LENGTH) { log_event("! Incompatible charset file: %.100s", charset); fprintf(stderr, "Incompatible charset file: %s\n", charset); error(); } if (header->count > CHARSET_SIZE) inc_format_error(charset); check = (unsigned int)header->check[0] | ((unsigned int)header->check[1] << 8) | ((unsigned int)header->check[2] << 16) | ((unsigned int)header->check[3] << 24); if (!rec_restoring_now) rec_check = check; if (rec_check != check) { log_event("! Charset file has changed: %.100s", charset); fprintf(stderr, "Charset file has changed: %s\n", charset); error(); } fread(allchars, header->count, 1, file); if (ferror(file)) pexit("fread"); if (feof(file)) inc_format_error(charset); allchars[header->count] = 0; if (expand(allchars, extra ? extra : "", sizeof(allchars))) inc_format_error(charset); real_count = strlen(allchars); if (max_count < 0) max_count = CHARSET_SIZE; if (min_length != max_length) log_event("- Lengths %d to %d, up to %d different characters", min_length, max_length, max_count); else log_event("- Length %d, up to %d different characters", min_length, max_count); if ((unsigned int)max_count > real_count) { log_event("! Only %u characters available", real_count); fprintf(stderr, "Warning: only %u characters available\n", real_count); } if (!(db->format->params.flags & FMT_CASE)) switch (is_mixedcase(allchars)) { case -1: inc_format_error(charset); case 1: log_event("! Mixed-case charset, " "but the hash type is case-insensitive"); fprintf(stderr, "Warning: mixed-case charset, " "but the current hash type is case-insensitive;\n" "some candidate passwords may be unnecessarily " "tried more than once.\n"); } if (header->length >= 2) char2 = (char2_table)mem_alloc(sizeof(*char2)); else char2 = NULL; for (pos = 0; pos < (int)header->length - 2; pos++) chars[pos] = (chars_table)mem_alloc(sizeof(*chars[0])); rec_compat = 0; rec_entry = 0; memset(rec_numbers, 0, sizeof(rec_numbers)); status_init(NULL, 0); rec_restore_mode(restore_state); #ifdef WEBAPI if(packet_id) { int ret; // This is a new packet inc_rec_state.initialized = 0; inc_rec_state.words_requested = packet_rounds; inc_rec_state.words_generated = 0; inc_rec_state.cc_0 = -1; inc_rec_state.cc_1 = -1; inc_rec_state.cc_2 = -1; ret = sscanf(packet_state, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%127[^\n]", &rec_entry, &rec_numbers[0], &rec_numbers[1], &rec_numbers[2], &rec_numbers[3], &rec_numbers[4], &rec_numbers[5], &rec_numbers[6], &rec_numbers[7], &inc_rec_state.pos, &inc_rec_state.numbers_cache, &inc_rec_state.cc_0, &inc_rec_state.cc_1, &inc_rec_state.cc_2, inc_rec_state.key_i); if(ret < 14 || ret > 15) { log_event("Invalid packet state, found %d fields in %s", ret, packet_state); // XXX - Handle more gracefully.. error(); } status_init(webapi_inc_get_progress, 0); } #endif rec_init(db, save_state); ptr = header->order + (entry = rec_entry) * 3; memcpy(numbers, rec_numbers, sizeof(numbers)); crk_init(db, fix_state, NULL); last_count = last_length = -1; entry--; while (ptr < &header->order[sizeof(header->order) - 1]) { entry++; length = *ptr++; fixed = *ptr++; count = *ptr++; if (length >= CHARSET_LENGTH || fixed > length || count >= CHARSET_SIZE) inc_format_error(charset); if (entry != rec_entry) memset(numbers, 0, sizeof(numbers)); if (count >= real_count || (fixed && !count)) continue; if ((int)length + 1 < min_length || (int)length >= max_length || (int)count >= max_count) continue; if ((int)length != last_length) { inc_new_length(last_length = length, header, file, charset, char1, char2, chars); last_count = -1; } if ((int)count > last_count) inc_new_count(length, last_count = count, charset, allchars, char1, char2, chars); if (!length && !min_length) { min_length = 1; if (crk_process_key("")) break; } #if 0 log_event("- Trying length %d, fixed @%d, character count %d", length + 1, fixed + 1, count + 1); #endif if (inc_key_loop(length, fixed, count, char1, char2, chars)) break; } crk_done(); rec_done(event_abort); for (pos = 0; pos < (int)header->length - 2; pos++) MEM_FREE(chars[pos]); MEM_FREE(char2); MEM_FREE(header); fclose(file); }
void rec_restore_args(int lock) { char line[LINE_BUFFER_SIZE]; int index, argc; char **argv; char *save_rec_name; rec_name_complete(); if (!(rec_file = fopen(path_expand(rec_name), "r+"))) { if (options.fork && !john_main_process && errno == ENOENT) { fprintf(stderr, "%u Session completed\n", options.node_min); if (options.flags & FLG_STATUS_CHK) return; log_event("No crash recovery file, terminating"); log_done(); exit(0); } pexit("fopen: %s", path_expand(rec_name)); } rec_fd = fileno(rec_file); if (lock) rec_lock(); if (!fgetl(line, sizeof(line), rec_file)) rec_format_error("fgets"); rec_version = 0; if (!strcmp(line, RECOVERY_V4)) rec_version = 4; else if (!strcmp(line, RECOVERY_V3)) rec_version = 3; else if (!strcmp(line, RECOVERY_V2)) rec_version = 2; else if (!strcmp(line, RECOVERY_V1)) rec_version = 1; else if (strcmp(line, RECOVERY_V0)) rec_format_error(NULL); if (fscanf(rec_file, "%d\n", &argc) != 1) rec_format_error("fscanf"); if (argc < 2) rec_format_error(NULL); argv = mem_alloc_tiny(sizeof(char *) * (argc + 1), MEM_ALIGN_WORD); argv[0] = "john"; for (index = 1; index < argc; index++) if (fgetl(line, sizeof(line), rec_file)) argv[index] = str_alloc_copy(line); else rec_format_error("fgets"); argv[argc] = NULL; save_rec_name = rec_name; opt_init(argv[0], argc, argv); rec_name = save_rec_name; rec_name_completed = 1; if (fscanf(rec_file, "%u\n%u\n%x\n%x\n", &status_restored_time, &status.guess_count, &status.combs.lo, &status.combs.hi) != 4) rec_format_error("fscanf"); if (!status_restored_time) status_restored_time = 1; if (rec_version >= 4) { if (fscanf(rec_file, "%x\n%x\n%x\n%x\n%x\n%d\n", &status.combs_ehi, &status.crypts.lo, &status.crypts.hi, &status.cands.lo, &status.cands.hi, &status.compat) != 6) rec_format_error("fscanf"); } else { /* Historically, we were reusing what became the combs field for candidates * count when in --stdout mode */ status.cands = status.combs; status.compat = 1; } if (rec_version == 0) { status.pass = 0; status.progress = -1; } else if (fscanf(rec_file, "%d\n%d\n", &status.pass, &status.progress) != 2) rec_format_error("fscanf"); if (status.pass < 0 || status.pass > 3) rec_format_error(NULL); if (rec_version < 3) rec_check = 0; else if (fscanf(rec_file, "%x\n", &rec_check) != 1) rec_format_error("fscanf"); rec_restoring_now = 1; }
static void rec_name_complete(void) { if (rec_name_completed) return; #ifndef HAVE_MPI if (options.fork && !john_main_process) { #else if (!john_main_process && options.node_min) { #endif char *suffix = mem_alloc(1 + 20 + strlen(RECOVERY_SUFFIX) + 1); sprintf(suffix, ".%u%s", options.node_min, RECOVERY_SUFFIX); rec_name = path_session(rec_name, suffix); MEM_FREE(suffix); } else { rec_name = path_session(rec_name, RECOVERY_SUFFIX); } rec_name_completed = 1; } #if OS_FLOCK || FCNTL_LOCKS static void rec_lock(int shared) { int lockmode; #if FCNTL_LOCKS int blockmode; struct flock lock; #endif /* * In options.c, MPI code path call rec_restore_args(mpi_p) * relying on anything >1 meaning LOCK_SH. After restore, the * root node must block, in case some other node has not yet * closed the original file */ if (shared == 1) { #if FCNTL_LOCKS lockmode = F_WRLCK; blockmode = F_SETLKW; #else lockmode = LOCK_EX; #endif #ifdef HAVE_MPI if (!rec_restored || mpi_id || mpi_p == 1) #endif #if FCNTL_LOCKS blockmode = F_SETLK; #else lockmode |= LOCK_NB; #endif } else #if FCNTL_LOCKS { lockmode = F_RDLCK; blockmode = F_SETLK; } #else lockmode = LOCK_SH | LOCK_NB; #endif #ifdef LOCK_DEBUG fprintf(stderr, "%s(%u): Locking session file...\n", __FUNCTION__, options.node_min); #endif #if FCNTL_LOCKS memset(&lock, 0, sizeof(lock)); lock.l_type = lockmode; if (fcntl(rec_fd, blockmode, &lock)) { if (errno == EAGAIN || errno == EACCES) { #else if (flock(rec_fd, lockmode)) { if (errno == EWOULDBLOCK) { #endif #ifdef HAVE_MPI fprintf(stderr, "Node %d@%s: Crash recovery file is" " locked: %s\n", mpi_id + 1, mpi_name, path_expand(rec_name)); #else fprintf(stderr, "Crash recovery file is locked: %s\n", path_expand(rec_name)); #endif error(); } else #if FCNTL_LOCKS pexit("fcntl()"); #else pexit("flock()"); #endif } #ifdef LOCK_DEBUG fprintf(stderr, "%s(%u): Locked session file (%s)\n", __FUNCTION__, options.node_min, shared == 1 ? "exclusive" : "shared"); #endif } static void rec_unlock(void) { #if FCNTL_LOCKS struct flock lock = { 0 }; lock.l_type = F_UNLCK; #endif #ifdef LOCK_DEBUG fprintf(stderr, "%s(%u): Unlocking session file\n", __FUNCTION__, options.node_min); #endif #if FCNTL_LOCKS if (fcntl(rec_fd, F_SETLK, &lock)) pexit("fcntl(F_UNLCK)"); #else if (flock(rec_fd, LOCK_UN)) pexit("flock(LOCK_UN)"); #endif } #else #define rec_lock(lock) \ {} #define rec_unlock() \ {} #endif void rec_init(struct db_main *db, void (*save_mode)(FILE *file)) { rec_done(1); if (!rec_argc) return; rec_name_complete(); if ((rec_fd = open(path_expand(rec_name), O_RDWR | O_CREAT, 0600)) < 0) pexit("open: %s", path_expand(rec_name)); rec_lock(1); if (!(rec_file = fdopen(rec_fd, "w"))) pexit("fdopen"); rec_db = db; rec_save_mode = save_mode; } void rec_save(void) { int save_format; #ifdef HAVE_MPI int fake_fork; #endif int add_argc = 0, add_enc = 1, add_2nd_enc = 1; int add_mkv_stats = (options.mkv_stats ? 1 : 0); long size; char **opt; log_flush(); if (!rec_file) return; if (fseek(rec_file, 0, SEEK_SET)) pexit("fseek"); #ifdef _MSC_VER if (_write(fileno(rec_file), "", 0)) pexit("ftruncate"); #elif __CYGWIN__ if (ftruncate(rec_fd, 0)) pexit("ftruncate"); #endif save_format = !options.format && rec_db->loaded; #ifdef HAVE_MPI fake_fork = (mpi_p > 1); #endif opt = rec_argv; while (*++opt) { #ifdef HAVE_MPI if (!strncmp(*opt, "--fork", 6)) fake_fork = 0; else #endif if (!strncmp(*opt, "--encoding", 10) || !strncmp(*opt, "--input-encoding", 16)) add_enc = 0; else if (!strncmp(*opt, "--internal-encoding", 19) || !strncmp(*opt, "--target-encoding", 17)) add_2nd_enc = 0; else if (!strncmp(*opt, "--mkv-stats", 11)) add_mkv_stats = 0; } if (add_2nd_enc && (options.flags & FLG_STDOUT) && (pers_opts.input_enc != UTF_8 || pers_opts.target_enc != UTF_8)) add_2nd_enc = 0; add_argc = add_enc + add_2nd_enc + add_mkv_stats; #ifdef HAVE_MPI add_argc += fake_fork; #endif fprintf(rec_file, RECOVERY_V "\n%d\n", rec_argc + (save_format ? 1 : 0) + add_argc); opt = rec_argv; while (*++opt) { /* Add defaults as if they were actually on **argv */ if (options.wordlist && !(strcmp(*opt, "--wordlist") && strcmp(*opt, "--loopback"))) fprintf(rec_file, "%s=%s\n", *opt, options.wordlist); else if (!strcmp(*opt, "--rules")) fprintf(rec_file, "%s=%s\n", *opt, pers_opts.activewordlistrules); else if (!strcmp(*opt, "--single")) fprintf(rec_file, "%s=%s\n", *opt, pers_opts.activesinglerules); else if (!strcmp(*opt, "--incremental")) fprintf(rec_file, "%s=%s\n", *opt, options.charset); else if (!strcmp(*opt, "--markov")) fprintf(rec_file, "%s=%s\n", *opt, options.mkv_param); else fprintf(rec_file, "%s\n", *opt); } if (save_format) fprintf(rec_file, "--format=%s\n", rec_db->format->params.label); if (add_enc) fprintf(rec_file, "--input-encoding=%s\n", cp_id2name(pers_opts.input_enc)); if (add_2nd_enc && pers_opts.input_enc == UTF_8 && pers_opts.target_enc == UTF_8) fprintf(rec_file, "--internal-encoding=%s\n", cp_id2name(pers_opts.internal_enc)); else if (add_2nd_enc) fprintf(rec_file, "--target-encoding=%s\n", cp_id2name(pers_opts.target_enc)); if (add_mkv_stats) fprintf(rec_file, "--mkv-stats=%s\n", options.mkv_stats); #ifdef HAVE_MPI if (fake_fork) fprintf(rec_file, "--fork=%d\n", mpi_p); #endif fprintf(rec_file, "%u\n%u\n%x\n%x\n%x\n%x\n%x\n%x\n%x\n" "%d\n%d\n%d\n%x\n", status_get_time() + 1, status.guess_count, status.combs.lo, status.combs.hi, status.combs_ehi, status.crypts.lo, status.crypts.hi, status.cands.lo, status.cands.hi, status.compat, status.pass, status_get_progress ? (int)status_get_progress() : -1, rec_check); if (rec_save_mode) rec_save_mode(rec_file); if (options.flags & FLG_MASK_STACKED) mask_save_state(rec_file); if (ferror(rec_file)) pexit("fprintf"); if ((size = ftell(rec_file)) < 0) pexit("ftell"); if (fflush(rec_file)) pexit("fflush"); #ifndef _MSC_VER if (ftruncate(rec_fd, size)) pexit("ftruncate"); #endif #if HAVE_WINDOWS_H==0 if (!options.fork && fsync(rec_fd)) pexit("fsync"); #endif }
int path_generate(Shell_t *shp, struct argnod *todo, struct argnod **arghead) { char *cp; int brace; struct argnod *ap; struct argnod *top = NULL; struct argnod *apin; char *pat, *rescan; char *format = NULL; char comma, range = 0; int first, last, incr, count = 0; char end_char; char tmp[32]; if (!sh_isoption(shp, SH_BRACEEXPAND)) return path_expand(shp, todo->argval, arghead); todo->argchn.ap = NULL; again: apin = ap = todo; todo = ap->argchn.ap; cp = ap->argval; range = comma = brace = 0; // First search for {...,...}. while (1) { switch (*cp++) { case '{': { if (brace++ == 0) pat = cp; break; } case '}': { if (--brace > 0) break; if (brace == 0 && comma && *cp != '(') goto endloop1; comma = brace = 0; break; } case '.': { if (brace != 1) break; if (*cp != '.') break; char *endc; incr = 1; if (isdigit(*pat) || *pat == '+' || *pat == '-') { first = strtol(pat, &endc, 0); if (endc == (cp - 1)) { last = strtol(cp + 1, &endc, 0); if (*endc == '.' && endc[1] == '.') { incr = strtol(endc + 2, &endc, 0); } else if (last < first) { incr = -1; } if (incr) { if (*endc == '%') { Sffmt_t fmt; memset(&fmt, 0, sizeof(fmt)); fmt.version = SFIO_VERSION; fmt.form = endc; fmt.extf = checkfmt; sfprintf(sfstdout, "%!", &fmt); if (!(fmt.flags & (SFFMT_LLONG | SFFMT_LDOUBLE))) { switch (fmt.fmt) { case 'c': case 'd': case 'i': case 'o': case 'u': case 'x': case 'X': { format = endc; endc = fmt.form; break; } default: { break; } } } } else { format = "%d"; } if (*endc == '}') { cp = endc + 1; range = 2; goto endloop1; } } } } else if ((cp[2] == '}' || (cp[2] == '.' && cp[3] == '.')) && ((*pat >= 'a' && *pat <= 'z' && cp[1] >= 'a' && cp[1] <= 'z') || (*pat >= 'A' && *pat <= 'Z' && cp[1] >= 'A' && cp[1] <= 'Z'))) { first = *pat; last = cp[1]; cp += 2; if (*cp == '.') { incr = strtol(cp + 2, &endc, 0); cp = endc; } else if (first > last) { incr = -1; } if (incr && *cp == '}') { cp++; range = 1; goto endloop1; } } cp++; break; } case ',': { if (brace == 1) comma = 1; break; } case '\\': { cp++; break; } case 0: { // insert on stack ap->argchn.ap = top; top = ap; if (todo) goto again; for (; ap; ap = apin) { apin = ap->argchn.ap; if (!sh_isoption(shp, SH_NOGLOB)) { brace = path_expand(shp, ap->argval, arghead); } else { ap->argchn.ap = *arghead; *arghead = ap; brace = 1; } if (brace) { count += brace; (*arghead)->argflag |= ARG_MAKE; } } return count; } default: { break; } } } endloop1: rescan = cp; cp = pat - 1; *cp = 0; while (1) { brace = 0; if (range) { if (range == 1) { pat[0] = first; cp = &pat[1]; } else { *(rescan - 1) = 0; pat = tmp; assert(format); sfsprintf(pat, sizeof(tmp), format, first); *(rescan - 1) = '}'; cp = &end_char; *cp = 0; } if (incr * (first + incr) > last * incr) { *cp = '}'; } else { first += incr; } } else { // generate each pattern and put on the todo list while (1) { switch (*++cp) { case '\\': { cp++; break; } case '{': { brace++; break; } case ',': { if (brace == 0) goto endloop2; break; } case '}': { if (--brace < 0) goto endloop2; } default: { break; } } } } endloop2: brace = *cp; *cp = 0; sh_sigcheck(shp); ap = (struct argnod *)stkseek(shp->stk, ARGVAL); ap->argflag = ARG_RAW; ap->argchn.ap = todo; sfputr(shp->stk, apin->argval, -1); sfputr(shp->stk, pat, -1); sfputr(shp->stk, rescan, -1); todo = ap = (struct argnod *)stkfreeze(shp->stk, 1); if (brace == '}') break; if (!range) pat = cp + 1; } goto again; }
// // File name completion. // Generate the list of files found by adding an suffix to end of name. // The number of matches is returned. // int path_complete(Shell_t *shp, const char *name, const char *suffix, struct argnod **arghead) { sufstr = suffix; suflen = (int)strlen(suffix); return path_expand(shp, name, arghead); }
void do_wordlist_crack(struct db_main *db, char *name, int rules) { union { char buffer[2][LINE_BUFFER_SIZE + CACHE_BANK_SHIFT]; ARCH_WORD dummy; } aligned; char *line = aligned.buffer[0], *last = aligned.buffer[1]; struct rpp_context ctx; char *prerule, *rule, *word; char *(*apply)(char *word, char *rule, int split, char *last); int dist_rules, dist_switch; unsigned long my_words, their_words, my_words_left; log_event("Proceeding with wordlist mode"); if (name) { if (!(word_file = fopen(path_expand(name), "r"))) pexit("fopen: %s", path_expand(name)); log_event("- Wordlist file: %.100s", path_expand(name)); } else { word_file = stdin; log_event("- Reading candidate passwords from stdin"); } length = db->format->params.plaintext_length; if (rules) { if (rpp_init(rule_ctx = &ctx, SUBSECTION_WORDLIST)) { log_event("! No wordlist mode rules found"); if (john_main_process) fprintf(stderr, "No wordlist mode rules found in %s\n", cfg_name); error(); } rules_init(length); rule_count = rules_count(&ctx, -1); log_event("- %d preprocessed word mangling rules", rule_count); apply = rules_apply; } else { rule_ctx = NULL; rule_count = 1; log_event("- No word mangling rules"); apply = dummy_rules_apply; } rule_number = 0; line_number = 0; status_init(get_progress, 0); rec_restore_mode(restore_state); rec_init(db, save_state); crk_init(db, fix_state, NULL); prerule = rule = ""; if (rules) prerule = rpp_next(&ctx); /* A string that can't be produced by fgetl(). */ last[0] = '\n'; last[1] = 0; dist_rules = 0; dist_switch = rule_count; /* never */ my_words = ~0UL; /* all */ their_words = 0; if (options.node_count) { int rule_rem = rule_count % options.node_count; const char *now, *later = ""; dist_switch = rule_count - rule_rem; if (!rule_rem || rule_number < dist_switch) { dist_rules = 1; now = "rules"; if (rule_rem) later = ", then switch to distributing words"; } else { dist_switch = rule_count; /* never */ my_words = options.node_max - options.node_min + 1; their_words = options.node_count - my_words; now = "words"; } log_event("- Will distribute %s across nodes%s", now, later); } my_words_left = my_words; if (their_words) { if (line_number) { /* Restored session. line_number is right after a word we've actually used. */ int for_node = line_number % options.node_count + 1; if (for_node < options.node_min || for_node > options.node_max) { /* We assume that line_number is at the beginning of other nodes' block */ if (skip_lines(their_words, line) && /* Check for error since a mere EOF means next rule (the loop below should see * the EOF again, and it will skip to next rule if applicable) */ ferror(word_file)) prerule = NULL; } else { my_words_left = options.node_max - for_node + 1; } } else { /* New session. Skip lower-numbered nodes' lines. */ if (skip_lines(options.node_min - 1, line)) prerule = NULL; } } if (prerule) do { if (rules) { if (dist_rules) { int for_node = rule_number % options.node_count + 1; if (for_node < options.node_min || for_node > options.node_max) goto next_rule; } if ((rule = rules_reject(prerule, -1, last, db))) { if (strcmp(prerule, rule)) log_event("- Rule #%d: '%.100s'" " accepted as '%.100s'", rule_number + 1, prerule, rule); else log_event("- Rule #%d: '%.100s'" " accepted", rule_number + 1, prerule); } else { log_event("- Rule #%d: '%.100s' rejected", rule_number + 1, prerule); goto next_rule; } } while (fgetl(line, LINE_BUFFER_SIZE, word_file)) { line_number++; if (line[0] != '#') { process_word: if ((word = apply(line, rule, -1, last))) { last = word; if (ext_filter(word)) if (crk_process_key(word)) { rules = 0; break; } } next_word: if (--my_words_left) continue; if (skip_lines(their_words, line)) break; my_words_left = my_words; continue; } if (strncmp(line, "#!comment", 9)) goto process_word; goto next_word; } if (ferror(word_file)) break; if (rules) { next_rule: if (!(rule = rpp_next(&ctx))) break; rule_number++; if (rule_number >= dist_switch) { log_event("- Switching to distributing words"); dist_rules = 0; dist_switch = rule_count; /* not anymore */ my_words = options.node_max - options.node_min + 1; their_words = options.node_count - my_words; } line_number = 0; if (fseek(word_file, 0, SEEK_SET)) pexit("fseek"); if (their_words && skip_lines(options.node_min - 1, line)) break; } my_words_left = my_words; } while (rules); crk_done(); rec_done(event_abort || (status.pass && db->salts)); if (ferror(word_file)) pexit("fgets"); if (name) { if (event_abort) progress = get_progress(); else progress = 100; if (fclose(word_file)) pexit("fclose"); word_file = NULL; } }
/*! \brief Add new sections to the temporary path while drawing. * \par Function Description * Calculates the next section to be added to a path while drawing. * The temporary slots in the #GschemToplevel structure are used as * follows: * - first_wx and first_wy contain the location of the next point * that will lie on the path * - second_wx and second_wy contain the location of the next * point's control point. * - third_wx and third_wy contain the location of the previous * point's control point. * - temp_path is the new #PATH object (i.e. sequence of path * sections that comprise the path drawn so far). * * path_next_sections() adds up to two additional sections to the * temporary path, and returns the number of sections added, on the * basis that: a path starts with a MOVETO the first point; two cusp * nodes (control points coincident with the node position) generate a * LINETO section; and a path ends either whenever the user clicks on * either the first or the current node. * * \return the number of path sections added. */ static int path_next_sections (GschemToplevel *w_current) { gboolean cusp_point, cusp_prev, close_path, end_path, start_path; PATH *p; PATH_SECTION *section, *prev_section; int x1, y1, x2, y2, x3, y3; int save_num_sections; g_assert (w_current); g_assert (w_current->temp_path != NULL); g_assert (w_current->temp_path->sections != NULL); x1 = w_current->first_wx; y1 = w_current->first_wy; x2 = w_current->second_wx; y2 = w_current->second_wy; x3 = w_current->third_wx; y3 = w_current->third_wy; p = w_current->temp_path; save_num_sections = p->num_sections; /* Check whether the section that's being added is the initial * MOVETO. This is detected if the path is currently empty. */ start_path = (p->num_sections == 0); prev_section = start_path ? NULL : &p->sections[p->num_sections - 1]; /* Check whether the point that's being added has a handle offset. */ cusp_point = (w_current->first_wx == w_current->second_wx && w_current->first_wy == w_current->second_wy); /* Check whether there's a leftover control handle from the previous * point. */ cusp_prev = (!start_path && prev_section->x3 == x3 && prev_section->y3 == y3); /* Check whether the section that's being added closes the path. * This is detected if the location of the node is the same as the * location of the starting node, and there is at least one section * in the path in addition to the initial MOVETO section. */ section = &p->sections[0]; close_path = (!start_path && x1 == section->x3 && y1 == section->y3); /* Check whether the section that's being added ends the path. This * is detected if the location of the node is the same as the * location of the previous node. */ end_path = (!start_path && x1 == prev_section->x3 && y1 == prev_section->y3); /* Create section */ if (start_path) { /* At the start of the path, just create the initial MOVETO. */ path_expand (w_current); section = &p->sections[p->num_sections++]; section->code = PATH_MOVETO; section->x3 = x1; section->y3 = y1; } else if (!end_path) { path_expand (w_current); section = &p->sections[p->num_sections++]; /* If there are two cusp points, then add a line segment. If the * path is being closed, closing the path adds an implicit line * segment. */ if (cusp_prev && cusp_point && close_path) { section->code = PATH_END; } else if (cusp_prev && cusp_point) { section->code = PATH_LINETO; section->x3 = x1; section->y3 = y1; } else { /* If there are one or more Bezier control points, the section * needs to be a CURVETO. The control point of the current * point is mirrored about the point (i.e. the line is kept * continuous through the point). */ section->code = PATH_CURVETO; section->x1 = x3; section->y1 = y3; section->x2 = x1 + (x1 - x2); section->y2 = y1 + (y1 - y2); section->x3 = x1; section->y3 = y1; if (close_path) { path_expand (w_current); section = &p->sections[p->num_sections++]; section->code = PATH_END; } } } /* Return the number of sections added */ return p->num_sections - save_num_sections; }
static void john_init(char *name, int argc, char **argv) { int show_usage = 0; int make_check = (argc == 2 && !strcmp(argv[1], "--make_check")); if (make_check) argv[1] = "--test=0"; CPU_detect_or_fallback(argv, make_check); status_init(NULL, 1); if (argc < 2 || (argc == 2 && (!strcasecmp(argv[1], "--help") || !strcasecmp(argv[1], "-h") || !strcasecmp(argv[1], "-help")))) { john_register_all(); /* for printing by opt_init() */ show_usage = 1; } opt_init(name, argc, argv, show_usage); /* * --list=? needs to be supported, because it has been supported in the released * john-1.7.9-jumbo-6 version, and it is used by the bash completion script. * --list=? is, however, not longer mentioned in doc/OPTIONS and in the usage * output. Instead, --list=help is. */ if (options.listconf && (!strcasecmp(options.listconf, "help") || !strcmp(options.listconf, "?"))) { john_list_options(); exit(0); } if (options.listconf && (!strcasecmp(options.listconf, "help:help") || !strcasecmp(options.listconf, "help:"))) { john_list_help_options(); exit(0); } if (options.listconf && !strcasecmp(options.listconf, "help:format-methods")) { john_list_method_names(); exit(0); } if (options.listconf && !strncasecmp(options.listconf, "help:", 5)) { if (strcasecmp(options.listconf, "help:parameters") && strcasecmp(options.listconf, "help:list-data")) { fprintf(stderr, "%s is not a --list option that supports additional values.\nSupported options:\n", options.listconf+5); john_list_help_options(); exit(1); } } if (options.listconf && !strcasecmp(options.listconf, "hidden-options")) { puts("--help print usage summary, just like running the command"); puts(" without any parameters"); puts("--subformat=FORMAT pick a benchmark format for --format=crypt"); puts("--mkpc=N force a lower max. keys per crypt"); puts("--length=N force a lower max. length"); puts("--field-separator-char=C use 'C' instead of the ':' in input and pot files"); puts("--fix-state-delay=N performance tweak, see documentation"); puts("--log-stderr log to screen instead of file\n"); exit(0); } if (!make_check) { #if defined(_OPENMP) && OMP_FALLBACK #if defined(__DJGPP__) || defined(__CYGWIN32__) #error OMP_FALLBACK is incompatible with the current DOS and Win32 code #endif if (!getenv("JOHN_NO_OMP_FALLBACK") && omp_get_max_threads() <= 1) { #define OMP_FALLBACK_PATHNAME JOHN_SYSTEMWIDE_EXEC "/" OMP_FALLBACK_BINARY execv(OMP_FALLBACK_PATHNAME, argv); perror("execv: " OMP_FALLBACK_PATHNAME); } #endif path_init(argv); if (options.listconf && !strcasecmp(options.listconf, "build-info")) { puts("Version: " JOHN_VERSION); puts("Build: " JOHN_BLD _MP_VERSION); printf("Arch: %d-bit %s\n", ARCH_BITS, ARCH_LITTLE_ENDIAN ? "LE" : "BE"); #if JOHN_SYSTEMWIDE puts("System-wide exec: " JOHN_SYSTEMWIDE_EXEC); puts("System-wide home: " JOHN_SYSTEMWIDE_HOME); puts("Private home: " JOHN_PRIVATE_HOME); #endif printf("$JOHN is %s\n", path_expand("$JOHN/")); printf("Format interface version: %d\n", FMT_MAIN_VERSION); puts("Rec file version: " RECOVERY_V); puts("Charset file version: " CHARSET_V); printf("CHARSET_MIN: %d (0x%02x)\n", CHARSET_MIN, CHARSET_MIN); printf("CHARSET_MAX: %d (0x%02x)\n", CHARSET_MAX, CHARSET_MAX); printf("CHARSET_LENGTH: %d\n", CHARSET_LENGTH); printf("Max. Markov mode level: %d\n", MAX_MKV_LVL); printf("Max. Markov mode password length: %d\n", MAX_MKV_LEN); #ifdef __VERSION__ printf("Compiler version: %s\n", __VERSION__); #endif #ifdef __GNUC__ printf("gcc version: %d.%d.%d\n", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__); #endif #ifdef __ICC printf("icc version: %d\n", __ICC); #endif #ifdef __clang_version__ printf("clang version: %s\n", __clang_version__); #endif #ifdef OPENSSL_VERSION_NUMBER // The man page suggests the type of OPENSSL_VERSION_NUMBER is long, // gcc insists it is int. printf("OpenSSL library version: %lx", (unsigned long)OPENSSL_VERSION_NUMBER); // FIXME: How do I detect a missing library? // Even if if is extremely unlikely that openssl is missing, // at least flush all output buffers... fflush(NULL); if ((unsigned long)OPENSSL_VERSION_NUMBER != (unsigned long)SSLeay()) printf("\t(loaded: %lx)", (unsigned long)SSLeay()); printf("\n"); #endif exit(0); } } if (options.listconf && !strcasecmp(options.listconf, "encodings")) { listEncodings(); exit(0); } #ifdef CL_VERSION_1_0 if (options.listconf && !strcasecmp(options.listconf, "opencl-devices")) { listOpenCLdevices(); exit(0); } #endif #ifdef HAVE_CUDA if (options.listconf && !strcasecmp(options.listconf, "cuda-devices")) { cuda_device_list(); exit(0); } #endif if (!make_check) { if (options.config) { path_init_ex(options.config); cfg_init(options.config, 1); cfg_init(CFG_FULL_NAME, 1); cfg_init(CFG_ALT_NAME, 0); } else { #if JOHN_SYSTEMWIDE cfg_init(CFG_PRIVATE_FULL_NAME, 1); cfg_init(CFG_PRIVATE_ALT_NAME, 1); #endif cfg_init(CFG_FULL_NAME, 1); cfg_init(CFG_ALT_NAME, 0); } } /* This is --crack-status. We toggle here, so if it's enabled in john.conf, we can disable it using the command line option */ if (cfg_get_bool(SECTION_OPTIONS, NULL, "CrackStatus", 0)) options.flags ^= FLG_CRKSTAT; initUnicode(UNICODE_UNICODE); /* Init the unicode system */ john_register_all(); /* maybe restricted to one format by options */ if ((options.subformat && !strcasecmp(options.subformat, "list")) || (options.listconf && !strcasecmp(options.listconf, "subformats"))) { dynamic_DISPLAY_ALL_FORMATS(); /* NOTE if we have other 'generics', like sha1, sha2, rc4, ... * then EACH of them should have a DISPLAY_ALL_FORMATS() * function and we can call them here. */ exit(0); } if (options.listconf && !strcasecmp(options.listconf, "inc-modes")) { cfg_print_subsections("Incremental", NULL, NULL, 0); exit(0); } if (options.listconf && !strcasecmp(options.listconf, "rules")) { cfg_print_subsections("List.Rules", NULL, NULL, 0); exit(0); } if (options.listconf && !strcasecmp(options.listconf, "externals")) { cfg_print_subsections("List.External", NULL, NULL, 0); exit(0); } if (options.listconf && !strcasecmp(options.listconf, "sections")) { cfg_print_section_names(0); exit(0); } if (options.listconf && !strncasecmp(options.listconf, "parameters", 10) && (options.listconf[10] == '=' || options.listconf[10] == ':') && options.listconf[11] != '\0') { cfg_print_section_params(&options.listconf[11], NULL); exit(0); } if (options.listconf && !strncasecmp(options.listconf, "list-data", 9) && (options.listconf[9] == '=' || options.listconf[9] == ':') && options.listconf[10] != '\0') { cfg_print_section_list_lines(&options.listconf[10], NULL); exit(0); } if (options.listconf && !strcasecmp(options.listconf, "ext-filters")) { cfg_print_subsections("List.External", "filter", NULL, 0); exit(0); } if (options.listconf && !strcasecmp(options.listconf, "ext-filters-only")) { cfg_print_subsections("List.External", "filter", "generate", 0); exit(0); } if (options.listconf && !strcasecmp(options.listconf, "ext-modes")) { cfg_print_subsections("List.External", "generate", NULL, 0); exit(0); } if (options.listconf && !strcasecmp(options.listconf, "formats")) { int column; struct fmt_main *format; int i, dynamics = 0; char **formats_list; i = 0; format = fmt_list; while ((format = format->next)) i++; formats_list = malloc(sizeof(char*) * i); i = 0; format = fmt_list; do { char *label = format->params.label; if (!strncmp(label, "dynamic", 7)) { if (dynamics++) continue; else label = "dynamic_n"; } formats_list[i++] = label; } while ((format = format->next)); formats_list[i] = NULL; column = 0; i = 0; do { int length; char *label = formats_list[i++]; length = strlen(label) + 2; column += length; if (column > 78) { printf("\n"); column = length; } printf("%s%s", label, formats_list[i] ? ", " : "\n"); } while (formats_list[i]); free(formats_list); exit(0); } if (options.listconf && !strcasecmp(options.listconf, "format-details")) { struct fmt_main *format; format = fmt_list; do { int ntests = 0; if(format->params.tests) { while (format->params.tests[ntests++].ciphertext); ntests--; } printf("%s\t%d\t%d\t%d\t%08x\t%d\t%s\t%s\t%s\t%d\t%d\t%d\n", format->params.label, format->params.plaintext_length, format->params.min_keys_per_crypt, format->params.max_keys_per_crypt, format->params.flags, ntests, format->params.algorithm_name, format->params.format_name, format->params.benchmark_comment, format->params.benchmark_length, format->params.binary_size, ((format->params.flags & FMT_DYNAMIC) && format->params.salt_size) ? // salts are handled internally within the format. We want to know the 'real' salt size // dynamic will alway set params.salt_size to 0 or sizeof a pointer. dynamic_real_salt_length(format) : format->params.salt_size); } while ((format = format->next)); exit(0); } if (options.listconf && !strcasecmp(options.listconf, "format-all-details")) { struct fmt_main *format; format = fmt_list; do { int ntests = 0; if(format->params.tests) { while (format->params.tests[ntests++].ciphertext); ntests--; } /* * attributes should be printed in the same sequence * as with format-details, but human-readable */ printf("Format label \t%s\n", format->params.label); printf("Max. password length in bytes \t%d\n", format->params.plaintext_length); printf("Min. keys per crypt \t%d\n", format->params.min_keys_per_crypt); printf("Max. keys per crypt \t%d\n", format->params.max_keys_per_crypt); printf("Flags\n"); printf(" Case sensitive \t%s\n", (format->params.flags & FMT_CASE) ? "yes" : "no"); printf(" Supports 8-bit characters \t%s\n", (format->params.flags & FMT_8_BIT) ? "yes" : "no"); printf(" Converts 8859-1 to UTF-16/UCS-2\t%s\n", (format->params.flags & FMT_UNICODE) ? "yes" : "no"); printf(" Honours --encoding=NAME \t%s\n", (format->params.flags & FMT_UTF8) ? "yes" : "no"); printf(" False positives possible \t%s\n", (format->params.flags & FMT_NOT_EXACT) ? "yes" : "no"); printf(" Uses a bitslice implementation \t%s\n", (format->params.flags & FMT_BS) ? "yes" : "no"); printf(" The split() method unifies case\t%s\n", (format->params.flags & FMT_SPLIT_UNIFIES_CASE) ? "yes" : "no"); printf(" A $dynamic$ format \t%s\n", (format->params.flags & FMT_DYNAMIC) ? "yes" : "no"); #ifdef _OPENMP printf(" Parallelized with OpenMP \t%s\n", (format->params.flags & FMT_OMP) ? "yes" : "no"); #endif printf("Number of test cases for --test \t%d\n", ntests); printf("Algorithm name \t%s\n", format->params.algorithm_name); printf("Format name \t%s\n", format->params.format_name); printf("Benchmark comment \t%s\n", format->params.benchmark_comment); printf("Benchmark length \t%d\n", format->params.benchmark_length); printf("Binary size \t%d\n", format->params.binary_size); printf("Salt size \t%d\n", ((format->params.flags & FMT_DYNAMIC) && format->params.salt_size) ? // salts are handled internally within the format. We want to know the 'real' salt size/ // dynamic will alway set params.salt_size to 0 or sizeof a pointer. dynamic_real_salt_length(format) : format->params.salt_size); printf("\n"); } while ((format = format->next)); exit(0); } if (options.listconf && !strncasecmp(options.listconf, "format-methods", 14)) { struct fmt_main *format; format = fmt_list; do { int ShowIt = 1, i; if (options.listconf[14] == '=' || options.listconf[14] == ':') { ShowIt = 0; if (!strcasecmp(&options.listconf[15], "set_key") || !strcasecmp(&options.listconf[15], "get_key") || !strcasecmp(&options.listconf[15], "crypt_all") || !strcasecmp(&options.listconf[15], "cmp_all") || !strcasecmp(&options.listconf[15], "cmp_one") || !strcasecmp(&options.listconf[15], "cmp_exact")) ShowIt = 1; else if (strcasecmp(&options.listconf[15], "init") && strcasecmp(&options.listconf[15], "prepare") && strcasecmp(&options.listconf[15], "valid") && strcasecmp(&options.listconf[15], "split") && strcasecmp(&options.listconf[15], "binary") && strcasecmp(&options.listconf[15], "clear_keys") && strcasecmp(&options.listconf[15], "salt") && strcasecmp(&options.listconf[15], "get_hash") && strcasecmp(&options.listconf[15], "get_hash[0]") && strcasecmp(&options.listconf[15], "get_hash[1]") && strcasecmp(&options.listconf[15], "get_hash[2]") && strcasecmp(&options.listconf[15], "get_hash[3]") && strcasecmp(&options.listconf[15], "get_hash[4]") && strcasecmp(&options.listconf[15], "get_hash[5]") && strcasecmp(&options.listconf[15], "set_salt") && strcasecmp(&options.listconf[15], "binary_hash") && strcasecmp(&options.listconf[15], "binary_hash[0]") && strcasecmp(&options.listconf[15], "binary_hash[1]") && strcasecmp(&options.listconf[15], "binary_hash[2]") && strcasecmp(&options.listconf[15], "binary_hash[3]") && strcasecmp(&options.listconf[15], "binary_hash[3]") && strcasecmp(&options.listconf[15], "binary_hash[5]") && strcasecmp(&options.listconf[15], "salt_hash")) { fprintf(stderr, "Error, invalid option (invalid method name) %s\n", options.listconf); fprintf(stderr, "Valid method names are:\n"); john_list_method_names(); exit(1); } if (format->methods.init != fmt_default_init && !strcasecmp(&options.listconf[15], "init")) ShowIt = 1; if (format->methods.prepare != fmt_default_prepare && !strcasecmp(&options.listconf[15], "prepare")) ShowIt = 1; if (format->methods.valid != fmt_default_valid && !strcasecmp(&options.listconf[15], "valid")) ShowIt = 1; if (format->methods.split != fmt_default_split && !strcasecmp(&options.listconf[15], "split")) ShowIt = 1; if (format->methods.binary != fmt_default_binary && !strcasecmp(&options.listconf[15], "binary")) ShowIt = 1; if (format->methods.salt != fmt_default_salt && !strcasecmp(&options.listconf[15], "salt")) ShowIt = 1; if (format->methods.clear_keys != fmt_default_clear_keys && !strcasecmp(&options.listconf[15], "clear_keys")) ShowIt = 1; for (i = 0; i < 6; ++i) { char Buf[20]; sprintf(Buf, "get_hash[%d]", i); if (format->methods.get_hash[i] && format->methods.get_hash[i] != fmt_default_get_hash && !strcasecmp(&options.listconf[15], Buf)) ShowIt = 1; } if (format->methods.get_hash[0] && format->methods.get_hash[0] != fmt_default_get_hash && !strcasecmp(&options.listconf[15], "get_hash")) ShowIt = 1; for (i = 0; i < 6; ++i) { char Buf[20]; sprintf(Buf, "binary_hash[%d]", i); if (format->methods.binary_hash[i] && format->methods.binary_hash[i] != fmt_default_binary_hash && !strcasecmp(&options.listconf[15], Buf)) ShowIt = 1; } if (format->methods.binary_hash[0] && format->methods.binary_hash[0] != fmt_default_binary_hash && !strcasecmp(&options.listconf[15], "binary_hash")) ShowIt = 1; if (format->methods.salt_hash != fmt_default_salt_hash && !strcasecmp(&options.listconf[15], "salt_hash")) ShowIt = 1; if (format->methods.set_salt != fmt_default_set_salt && !strcasecmp(&options.listconf[15], "set_salt")) ShowIt = 1; } if (ShowIt) { int i; printf("Methods overridden for: %s [%s] %s\n", format->params.label, format->params.algorithm_name, format->params.format_name); if (format->methods.init != fmt_default_init) printf("\tinit()\n"); if (format->methods.prepare != fmt_default_prepare) printf("\tprepare()\n"); if (format->methods.valid != fmt_default_valid) printf("\tvalid()\n"); if (format->methods.split != fmt_default_split) printf("\tsplit()\n"); if (format->methods.binary != fmt_default_binary) printf("\tbinary()\n"); if (format->methods.salt != fmt_default_salt) printf("\tsalt()\n"); for (i = 0; i < 6; ++i) if (format->methods.binary_hash[i] != fmt_default_binary_hash) { if (format->methods.binary_hash[i]) printf("\t\tbinary_hash[%d]()\n", i); else printf("\t\tbinary_hash[%d]() (NULL pointer)\n", i); } if (format->methods.salt_hash != fmt_default_salt_hash) printf("\tsalt_hash()\n"); if (format->methods.set_salt != fmt_default_set_salt) printf("\tset_salt()\n"); // there is no default for set_key() it must be defined. printf("\tset_key()\n"); // there is no default for get_key() it must be defined. printf("\tget_key()\n"); if (format->methods.clear_keys != fmt_default_clear_keys) printf("\tclear_keys()\n"); for (i = 0; i < 6; ++i) if (format->methods.get_hash[i] != fmt_default_get_hash) { if (format->methods.get_hash[i]) printf("\t\tget_hash[%d]()\n", i); else printf("\t\tget_hash[%d]() (NULL pointer)\n", i); } // there is no default for crypt_all() it must be defined. printf("\tcrypt_all()\n"); // there is no default for cmp_all() it must be defined. printf("\tcmp_all()\n"); // there is no default for cmp_one() it must be defined. printf("\tcmp_one()\n"); // there is no default for cmp_exact() it must be defined. printf("\tcmp_exact()\n"); printf("\n\n"); } } while ((format = format->next)); exit(0); } /* * Other --list=help:WHAT are processed earlier, but these require * a valid config: */ if (options.listconf && !strcasecmp(options.listconf, "help:parameters")) { cfg_print_section_names(1); exit(0); } if (options.listconf && !strcasecmp(options.listconf, "help:list-data")) { cfg_print_section_names(2); exit(0); } /* --list last resort: list subsections of any john.conf section name */ if (options.listconf) { //printf("Subsections of [%s]:\n", options.listconf); if (cfg_print_subsections(options.listconf, NULL, NULL, 1)) exit(0); else { fprintf(stderr, "Section [%s] not found.\n", options.listconf); /* Just in case the user specified an invalid value * like help or list... * print the same list as with --list=?, but exit(1) */ john_list_options(); exit(1); } } #ifdef CL_VERSION_1_0 if (!options.ocl_platform) { if ((options.ocl_platform = cfg_get_param(SECTION_OPTIONS, SUBSECTION_OPENCL, "Platform"))) platform_id = atoi(options.ocl_platform); else platform_id = -1; } if (!options.gpu_device) { if ((options.gpu_device = cfg_get_param(SECTION_OPTIONS, SUBSECTION_OPENCL, "Device"))) ocl_gpu_id = atoi(options.gpu_device); else ocl_gpu_id = -1; } if (platform_id == -1 || ocl_gpu_id == -1) opencl_find_gpu(&ocl_gpu_id, &platform_id); #endif common_init(); sig_init(); john_load(); if (options.encodingStr && options.encodingStr[0]) log_event("- %s input encoding enabled", options.encodingStr); }
void init_probatables(char * filename) { FILE * fichier; char * ligne; unsigned int i; unsigned int j; unsigned int k; unsigned int nb_lignes; if (!(fichier = fopen(filename, "r"))) { static char fpath[PATH_BUFFER_SIZE] = "$JOHN/"; strcat(fpath, filename); filename = path_expand(fpath); if (!(fichier = fopen(filename, "r"))) { fprintf(stderr, "could not open %s\n", filename); error(); } } first = mem_alloc( sizeof(unsigned char) * 256 ); ligne = mem_alloc(4096); proba2 = mem_alloc(sizeof(unsigned char) * 256 * 256); proba1 = mem_alloc(sizeof(unsigned char) * 256 ); for(j=0;j<256*256;j++) proba2[j] = UNK_STR; for(j=0;j<256;j++) proba1[j] = UNK_STR; for(i=0;i<256;i++) { first[i] = 255; for(j=0;j<256;j++) { charsorted[i*256+j] = j; } } nb_lignes = 0; while(fgets(ligne, 4096, fichier)) { if (ligne[0] == 0) continue; ligne[strlen(ligne)-1] = 0; // chop if( sscanf(ligne, "%d=proba1[%d]", &i, &j) == 2 ) { if(i>UNK_STR) i = UNK_STR; proba1[j] = i; } if( sscanf(ligne, "%d=proba2[%d*256+%d]", &i, &j, &k) == 3 ) { if(i>UNK_STR) i = UNK_STR; if( (first[j]>k) && (i<UNK_STR)) first[j] = k; proba2[j*256+k] = i; } nb_lignes++; } MEM_FREE(ligne); fclose(fichier); stupidsort(charsorted, proba1, 256); for(i=1;i<256;i++) stupidsort(&(charsorted[i*256]), &(proba2[i*256]), 256); }
static void john_init(char *name, int argc, char **argv) { int make_check = (argc == 2 && !strcmp(argv[1], "--make_check")); if (make_check) argv[1] = "--test=0"; CPU_detect_or_fallback(argv, make_check); status_init(NULL, 1); if (argc < 2) john_register_all(); /* for printing by opt_init() */ opt_init(name, argc, argv); if (options.listconf && !strcasecmp(options.listconf, "?")) { puts("inc-modes, rules, externals, ext-filters, ext-filters-only,"); puts("ext-modes, build-info, hidden-options, <conf section name>"); exit(0); } if (options.listconf && !strcasecmp(options.listconf, "hidden-options")) { puts("--list=NAME list configuration, rules, etc"); puts("--mkpc=N force a lower max. keys per crypt"); exit(0); } if (!make_check) { #if defined(_OPENMP) && OMP_FALLBACK #if defined(__DJGPP__) || defined(__CYGWIN32__) #error OMP_FALLBACK is incompatible with the current DOS and Win32 code #endif if (!getenv("JOHN_NO_OMP_FALLBACK") && omp_get_max_threads() <= 1) { #define OMP_FALLBACK_PATHNAME JOHN_SYSTEMWIDE_EXEC "/" OMP_FALLBACK_BINARY execv(OMP_FALLBACK_PATHNAME, argv); perror("execv: " OMP_FALLBACK_PATHNAME); } #endif path_init(argv); if (options.listconf && !strcasecmp(options.listconf, "build-info")) { puts("Version: " JOHN_VERSION); puts("Build: " JOHN_BLD _MP_VERSION); printf("Arch: %d-bit %s\n", ARCH_BITS, ARCH_LITTLE_ENDIAN ? "LE" : "BE"); #if JOHN_SYSTEMWIDE puts("System-wide exec: " JOHN_SYSTEMWIDE_EXEC); puts("System-wide home: " JOHN_SYSTEMWIDE_HOME); puts("Private home: " JOHN_PRIVATE_HOME); #endif printf("$JOHN is %s\n", path_expand("$JOHN/")); puts("Rec file version: " RECOVERY_V); printf("CHARSET_MIN: %d (0x%02x)\n", CHARSET_MIN, CHARSET_MIN); printf("CHARSET_MAX: %d (0x%02x)\n", CHARSET_MAX, CHARSET_MAX); printf("CHARSET_LENGTH: %d\n", CHARSET_LENGTH); #ifdef __GNUC__ printf("gcc version: %d.%d.%d\n", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__); #endif #ifdef __ICC printf("icc version: %d\n", __ICC); #endif exit(0); } if (options.flags & FLG_CONFIG_CLI) { path_init_ex(options.config); cfg_init(options.config, 1); cfg_init(CFG_FULL_NAME, 1); cfg_init(CFG_ALT_NAME, 0); } else { #if JOHN_SYSTEMWIDE cfg_init(CFG_PRIVATE_FULL_NAME, 1); cfg_init(CFG_PRIVATE_ALT_NAME, 1); #endif cfg_init(CFG_FULL_NAME, 1); cfg_init(CFG_ALT_NAME, 0); } } if (options.subformat && !strcasecmp(options.subformat, "list")) { dynamic_DISPLAY_ALL_FORMATS(); /* NOTE if we have other 'generics', like sha1, sha2, rc4, ... * then EACH of them should have a DISPLAY_ALL_FORMATS() * function and we can call them here. */ exit(0); } if (options.listconf && !strcasecmp(options.listconf, "inc-modes")) { cfg_print_subsections("Incremental", NULL, NULL); exit(0); } if (options.listconf && !strcasecmp(options.listconf, "rules")) { cfg_print_subsections("List.Rules", NULL, NULL); exit(0); } if (options.listconf && !strcasecmp(options.listconf, "externals")) { cfg_print_subsections("List.External", NULL, NULL); exit(0); } if (options.listconf && !strcasecmp(options.listconf, "ext-filters")) { cfg_print_subsections("List.External", "filter", NULL); exit(0); } if (options.listconf && !strcasecmp(options.listconf, "ext-filters-only")) { cfg_print_subsections("List.External", "filter", "generate"); exit(0); } if (options.listconf && !strcasecmp(options.listconf, "ext-modes")) { cfg_print_subsections("List.External", "generate", NULL); exit(0); } /* Catch-all for any other john.conf section name :-) */ if (options.listconf) { cfg_print_subsections(options.listconf, NULL, NULL); exit(0); } initUnicode(UNICODE_UNICODE); /* Init the unicode system */ john_register_all(); /* maybe restricted to one format by options */ common_init(); sig_init(); john_load(); if (options.encodingStr && options.encodingStr[0]) log_event("- %s input encoding enabled", options.encodingStr); #ifdef CL_VERSION_1_0 if (!options.ocl_platform) if ((options.ocl_platform = cfg_get_param(SECTION_OPTIONS, SUBSECTION_OPENCL, "Platform"))) platform_id = atoi(options.ocl_platform); if (!options.ocl_device) if ((options.ocl_device = cfg_get_param(SECTION_OPTIONS, SUBSECTION_OPENCL, "Device"))) gpu_id = atoi(options.ocl_device); #endif }