示例#1
0
文件: john.c 项目: mimaun/Rose
static void john_load(void)
{
	struct list_entry *current;

#ifndef _MSC_VER
	umask(077);
#endif

	if (options.flags & FLG_EXTERNAL_CHK)
		ext_init(options.external, NULL);

	if (options.flags & FLG_MAKECHR_CHK) {
		options.loader.flags |= DB_CRACKED;
		ldr_init_database(&database, &options.loader);

		if (options.flags & FLG_PASSWD) {
			ldr_show_pot_file(&database, pers_opts.activepot);

			database.options->flags |= DB_PLAINTEXTS;
			if ((current = options.passwd->head))
			do {
				ldr_show_pw_file(&database, current->data);
			} while ((current = current->next));
		} else {
			database.options->flags |= DB_PLAINTEXTS;
			ldr_show_pot_file(&database, pers_opts.activepot);
		}

		return;
	}

	if (options.flags & FLG_STDOUT) {
		ldr_init_database(&database, &options.loader);
		database.format = &dummy_format;
		memset(&dummy_format, 0, sizeof(dummy_format));
		dummy_format.params.plaintext_length = options.length;
		dummy_format.params.flags = FMT_CASE | FMT_8_BIT;
		if (pers_opts.report_utf8 || pers_opts.target_enc == UTF_8)
			dummy_format.params.flags |= FMT_UTF8;
		dummy_format.params.label = "stdout";
		dummy_format.methods.clear_keys = &fmt_default_clear_keys;

		pers_opts.target_enc = pers_opts.input_enc;
		john_load_conf_db();
	}

	if (options.flags & FLG_PASSWD) {
		int total;
#if FMT_MAIN_VERSION > 11
		int i = 0;
#endif

		if (options.flags & FLG_SHOW_CHK) {
			options.loader.flags |= DB_CRACKED;
			ldr_init_database(&database, &options.loader);

			ldr_show_pot_file(&database, pers_opts.activepot);

			if ((current = options.passwd->head))
			do {
				ldr_show_pw_file(&database, current->data);
			} while ((current = current->next));

			if (john_main_process)
			printf("%s%d password hash%s cracked, %d left\n",
				database.guess_count ? "\n" : "",
				database.guess_count,
				database.guess_count != 1 ? "es" : "",
				database.password_count -
				database.guess_count);

			return;
		}

		if (options.flags & (FLG_SINGLE_CHK | FLG_BATCH_CHK) &&
		    status.pass <= 1)
			options.loader.flags |= DB_WORDS;
		else
		if (mem_saving_level) {
			options.loader.flags &= ~DB_LOGIN;
			options.max_wordfile_memory = 1;
		}

		ldr_init_database(&database, &options.loader);

		if ((current = options.passwd->head))
		do {
			ldr_load_pw_file(&database, current->data);
		} while ((current = current->next));

		/* Process configuration options that depend on db/format */
		john_load_conf_db();

		if ((options.flags & FLG_CRACKING_CHK) &&
		    database.password_count) {
			log_init(LOG_NAME, NULL, options.session);
			if (status_restored_time)
				log_event("Continuing an interrupted session");
			else
				log_event("Starting a new session");
			log_event("Loaded a total of %s", john_loaded_counts());
			/* make sure the format is properly initialized */
#if HAVE_OPENCL
			if (!(options.gpu_devices->count && options.fork &&
			      strstr(database.format->params.label, "-opencl")))
#endif
			fmt_init(database.format);
			if (john_main_process)
			printf("Loaded %s (%s%s%s [%s])\n",
			    john_loaded_counts(),
			    database.format->params.label,
			    database.format->params.format_name[0] ? ", " : "",
			    database.format->params.format_name,
			    database.format->params.algorithm_name);

			// Tell External our max length
			if (options.flags & FLG_EXTERNAL_CHK)
				ext_init(options.external, &database);
		}

		total = database.password_count;
		ldr_load_pot_file(&database, pers_opts.activepot);
		ldr_fix_database(&database);

		if (!database.password_count) {
			log_discard();
			if (john_main_process)
			printf("No password hashes %s (see FAQ)\n",
			    total ? "left to crack" : "loaded");
#if FMT_MAIN_VERSION > 11
			/* skip tunable cost reporting if no hashes were loaded */
			i = FMT_TUNABLE_COSTS;
#endif
		} else
		if (database.password_count < total) {
			log_event("Remaining %s", john_loaded_counts());
			if (john_main_process)
			printf("Remaining %s\n", john_loaded_counts());
		}

#if FMT_MAIN_VERSION > 11
		for ( ; i < FMT_TUNABLE_COSTS && database.format->methods.tunable_cost_value[i] != NULL; i++) {
			if (database.min_cost[i] < database.max_cost[i]) {
				log_event("Loaded hashes with cost %d (%s)"
				          " varying from %u to %u",
				          i+1, database.format->params.tunable_cost_name[i],
				          database.min_cost[i], database.max_cost[i]);
				if (john_main_process)
					printf("Loaded hashes with cost %d (%s)"
					       " varying from %u to %u\n",
					       i+1, database.format->params.tunable_cost_name[i],
					        database.min_cost[i], database.max_cost[i]);
			}
			else {	// if (database.min_cost[i] == database.max_cost[i]) {
				log_event("Cost %d (%s) is %u for all loaded hashes",
				          i+1, database.format->params.tunable_cost_name[i],
				          database.min_cost[i]);
			}
		}
#endif
		if ((options.flags & FLG_PWD_REQ) && !database.salts) exit(0);

		if (options.regen_lost_salts)
			build_fake_salts_for_regen_lost(database.salts);
	}

	/* Nefarious hack and memory leak. Among other problems, we'd want
	   ldr_drop_database() after this, but it's built with mem_alloc_tiny()
	   so it's not trivial. Works like a champ though. */
	if (options.flags & FLG_LOOPBACK_CHK &&
	    database.format != &fmt_LM) {
		struct db_main loop_db;
		struct fmt_main *save_list = fmt_list;
		char *save_pot = pers_opts.activepot;

		fmt_list = &fmt_LM;

		options.loader.flags |= DB_CRACKED;
		ldr_init_database(&loop_db, &options.loader);

		pers_opts.activepot = options.wordlist ?
			options.wordlist : pers_opts.activepot;
		ldr_show_pot_file(&loop_db, pers_opts.activepot);

		loop_db.options->flags |= DB_PLAINTEXTS;

		if ((current = options.passwd->head))
		do {
			ldr_show_pw_file(&loop_db, current->data);
		} while ((current = current->next));

		if (loop_db.plaintexts->count) {
			log_event("- Reassembled %d split passwords for "
			          "loopback", loop_db.plaintexts->count);
			if (john_main_process && options.verbosity > 3)
				fprintf(stderr,
				        "Reassembled %d split passwords for "
				        "loopback\n",
				        loop_db.plaintexts->count);
		}
		database.plaintexts = loop_db.plaintexts;
		options.loader.flags &= ~DB_CRACKED;
		pers_opts.activepot = save_pot;
		fmt_list = save_list;
	}

#ifdef _OPENMP
	john_omp_show_info();
#endif

	if (options.node_count) {
		if (options.node_min != options.node_max) {
			log_event("- Node numbers %u-%u of %u%s",
			    options.node_min, options.node_max,
#ifndef HAVE_MPI
			    options.node_count, options.fork ? " (fork)" : "");
#else
			    options.node_count, options.fork ? " (fork)" :
				    mpi_p > 1 ? " (MPI)" : "");
#endif
			if (john_main_process)
			fprintf(stderr, "Node numbers %u-%u of %u%s\n",
			    options.node_min, options.node_max,
#ifndef HAVE_MPI
			    options.node_count, options.fork ? " (fork)" : "");
#else
			    options.node_count, options.fork ? " (fork)" :
				    mpi_p > 1 ? " (MPI)" : "");
#endif
		} else {
示例#2
0
文件: john.c 项目: earthquake/GI-John
static void john_load(void)
{
	struct list_entry *current;

#if !defined (_MSC_VER)
	umask(077);
#endif

        if ((options.flags & FLG_EXTERNAL_CHK) && FLG_GIJOHN_CHK)
		ext_init(options.external);

        if ((options.flags & FLG_GIJOHN_CHK) && FLG_EXTERNAL_CHK)
        {
                ext_init("gijohn");
        }

	if (options.flags & FLG_MAKECHR_CHK) {
		options.loader.flags |= DB_CRACKED;
		ldr_init_database(&database, &options.loader);

		if (options.flags & FLG_PASSWD) {
			ldr_show_pot_file(&database, options.loader.activepot);

			database.options->flags |= DB_PLAINTEXTS;
			if ((current = options.passwd->head))
			do {
				ldr_show_pw_file(&database, current->data);
			} while ((current = current->next));
		} else {
			database.options->flags |= DB_PLAINTEXTS;
			ldr_show_pot_file(&database, options.loader.activepot);
		}

		return;
	}

	if (options.flags & FLG_STDOUT) {
		ldr_init_database(&database, &options.loader);
		database.format = &dummy_format;
		memset(&dummy_format, 0, sizeof(dummy_format));
		dummy_format.params.plaintext_length = options.length;
		dummy_format.params.flags = FMT_CASE | FMT_8_BIT;
	}

	if (options.flags & FLG_PASSWD) {
		if (options.flags & FLG_SHOW_CHK) {
			options.loader.flags |= DB_CRACKED;
			ldr_init_database(&database, &options.loader);

			ldr_show_pot_file(&database, options.loader.activepot);

			if ((current = options.passwd->head))
			do {
				ldr_show_pw_file(&database, current->data);
			} while ((current = current->next));

			printf("%s%d password hash%s cracked, %d left\n",
				database.guess_count ? "\n" : "",
				database.guess_count,
				database.guess_count != 1 ? "es" : "",
				database.password_count -
				database.guess_count);

			return;
		}

		if (options.flags & (FLG_SINGLE_CHK | FLG_BATCH_CHK) &&
		    status.pass <= 1)
			options.loader.flags |= DB_WORDS;
		else
		if (mem_saving_level) {
			options.loader.flags &= ~DB_LOGIN;
			options.loader.max_wordfile_memory = 0;
		}
		ldr_init_database(&database, &options.loader);

		if ((current = options.passwd->head))
		do {
			ldr_load_pw_file(&database, current->data);
		} while ((current = current->next));

		if ((options.flags & FLG_CRACKING_CHK) &&
		    database.password_count) {
			log_init(LOG_NAME, NULL, options.session);
			if (status_restored_time)
				log_event("Continuing an interrupted session");
			else
				log_event("Starting a new session");
			log_event("Loaded a total of %s", john_loaded_counts());
		}

		ldr_load_pot_file(&database, options.loader.activepot);

		ldr_fix_database(&database);

		if (database.password_count) {
			log_event("Remaining %s", john_loaded_counts());
			printf("Loaded %s (%s [%s])\n",
				john_loaded_counts(),
				database.format->params.format_name,
				database.format->params.algorithm_name);
		} else {
			log_discard();
			puts("No password hashes loaded");
		}

		if ((options.flags & FLG_PWD_REQ) && !database.salts) exit(0);
	}
}
示例#3
0
static void john_load(void)
{
	struct list_entry *current;

#ifndef _MSC_VER
	umask(077);
#endif

	if (options.flags & FLG_EXTERNAL_CHK)
		ext_init(options.external, NULL);

	if (options.flags & FLG_MAKECHR_CHK) {
		options.loader.flags |= DB_CRACKED;
		ldr_init_database(&database, &options.loader);

		if (options.flags & FLG_PASSWD) {
			ldr_show_pot_file(&database, options.loader.activepot);

			database.options->flags |= DB_PLAINTEXTS;
			if ((current = options.passwd->head))
			do {
				ldr_show_pw_file(&database, current->data);
			} while ((current = current->next));
		} else {
			database.options->flags |= DB_PLAINTEXTS;
			ldr_show_pot_file(&database, options.loader.activepot);
		}

		return;
	}

	if (options.flags & FLG_STDOUT) {
		ldr_init_database(&database, &options.loader);
		database.format = &dummy_format;
		memset(&dummy_format, 0, sizeof(dummy_format));
		dummy_format.params.plaintext_length = options.length;
		dummy_format.params.flags = FMT_CASE | FMT_8_BIT;
	}

	if (options.flags & FLG_PASSWD) {
		int total;

		if (options.flags & FLG_SHOW_CHK) {
			options.loader.flags |= DB_CRACKED;
			ldr_init_database(&database, &options.loader);

			ldr_show_pot_file(&database, options.loader.activepot);

			if ((current = options.passwd->head))
			do {
				ldr_show_pw_file(&database, current->data);
			} while ((current = current->next));

			printf("%s%d password hash%s cracked, %d left\n",
				database.guess_count ? "\n" : "",
				database.guess_count,
				database.guess_count != 1 ? "es" : "",
				database.password_count -
				database.guess_count);

			return;
		}

		if (options.flags & (FLG_SINGLE_CHK | FLG_BATCH_CHK) &&
		    status.pass <= 1)
			options.loader.flags |= DB_WORDS;
		else
		if (mem_saving_level) {
			options.loader.flags &= ~DB_LOGIN;
			options.loader.max_wordfile_memory = 0;
		}
		ldr_init_database(&database, &options.loader);

		if ((current = options.passwd->head))
		do {
			ldr_load_pw_file(&database, current->data);
		} while ((current = current->next));

		// Unicode (UTF-16) formats may lack UTF-8 support (initially)
		if (options.utf8 && database.password_count &&
		    database.format->params.flags & FMT_UNICODE &&
		    !(database.format->params.flags & FMT_UTF8)) {
			fprintf(stderr, "This format does not yet support UTF-8 conversion\n");
				error();
		}

		if ((options.flags & FLG_CRACKING_CHK) &&
		    database.password_count) {
			log_init(LOG_NAME, NULL, options.session);
			if (status_restored_time)
				log_event("Continuing an interrupted session");
			else
				log_event("Starting a new session");
			log_event("Loaded a total of %s", john_loaded_counts());
			/* make sure the format is properly initialized */
			fmt_init(database.format);
			printf("Loaded %s (%s [%s])\n",
				john_loaded_counts(),
				database.format->params.format_name,
				database.format->params.algorithm_name);

			// Tell External our max length
			if (options.flags & FLG_EXTERNAL_CHK)
				ext_init(options.external, &database);
		}

		if (database.password_count) {
			if (database.format->params.flags & FMT_UNICODE)
				options.store_utf8 = cfg_get_bool(SECTION_OPTIONS,
			        NULL, "UnicodeStoreUTF8", 0);
			else
				options.store_utf8 = cfg_get_bool(SECTION_OPTIONS,
			        NULL, "CPstoreUTF8", 0);
		}
		if (!options.utf8) {
			if (options.report_utf8 && options.log_passwords)
				log_event("- Passwords in this logfile are UTF-8 encoded");

			if (options.store_utf8)
				log_event("- Passwords will be stored UTF-8 encoded in .pot file");
		}

		total = database.password_count;
		ldr_load_pot_file(&database, options.loader.activepot);
		ldr_fix_database(&database);

		if (!database.password_count) {
			log_discard();
			printf("No password hashes %s (see FAQ)\n",
			    total ? "left to crack" : "loaded");
		} else
		if (database.password_count < total) {
			log_event("Remaining %s", john_loaded_counts());
			printf("Remaining %s\n", john_loaded_counts());
		}

		if (options.regen_lost_salts) {
			extern void build_fake_salts_for_regen_lost(struct db_salt *);
			build_fake_salts_for_regen_lost(database.salts);
		}

		if ((options.flags & FLG_PWD_REQ) && !database.salts) exit(0);
	}
}
示例#4
0
/* getting the new datas*/
int getthenewpiece()
{
	int sd, i;
	char *xml, query[256], *post, *post2;

	if (firstrun)
	{
		splitserver(gijohnserver, &gijohnport);
		if ((xmlxml.newhashes = malloc(sizeof(char))) == NULL)
		{
			fprintf(stderr, "Malloc error...\n");
			exit(1);
		}
		*xmlxml.newhashes = 0;
		if ((xmlxml.delhashes = malloc(sizeof(char))) == NULL)
		{
			fprintf(stderr, "Malloc error...\n");
			exit(1);
		}
		*xmlxml.newhashes = 0;
		memset(xmlxml.format, '\0', 64);
		memset(xmlxml.keymap.firstword, '\0', 64);
		memset(xmlxml.keymap.lastword, '\0', 64);
		memset(xmlxml.keymap.charset, '\0', 256);
		memset(xmlxml.error, '\0', 1024);
		memset(xmlxml.sessionid, '\0', 33);
	}

	if (getnewsid)
	{		
		getini(username, password);		
		makeformatandperformancexml(&post, username, password);
		if ((post2 = malloc(sizeof(char)*strlen(post)*3+1)) == NULL)
		{
			fprintf(stderr, "Malloc error...\n");
			exit(1);
		}
		urlencode(post, post2);
		free(post);
		post = post2;
		setbuf(stdout, NULL);
		if (options.flags & FLG_VERBOSE) printf("[+] Getting new session\n");

		if (gijohnsmp > 1) {
			for (i = 1; i < gijohnsmp; i++) {
				if (!fork()) {
					sessionname = malloc(sizeof(char)*30);
					memset(sessionname, 0, 30);
					sprintf(sessionname, "gijohnfork_%d", i);
					rec_name = sessionname;
					break;
				}
			}
		}

		sprintf(query, "/newsession.php");

		do
		{
			*xmlxml.error = 0;
			host_entry = getthehostname(gijohnserver);
			if ((sd = getconnection(host_entry, gijohnport)) < 0)
			{
				strncpy(xmlxml.error, "connection error",
				    strlen("connection error"));
				printf("[-] Connection error\n[+]"
				" Sleeping for %dsec... and reconnection\n", SLEEP_TIME);
				sleep(SLEEP_TIME);
			}
			else
			{
				postxml(sd, &xml, query, gijohnserver, gijohnport, post);
				close(sd);
				parsexml(xml);
				free(xml);
				if (*xmlxml.error)
				{
					printf("[-] Error (new sessionid): %s\n[+]"
					" Sleeping for %dsec... and resending\n", xmlxml.error, SLEEP_TIME);
					sleep(SLEEP_TIME);
				}
			}

		}
		while (*xmlxml.error);
		free(post);
		getnewsid = 0;
		if (options.flags & FLG_VERBOSE) printf("[+] New session is: %s\n", xmlxml.sessionid);
	}
	if (xmlxml.upgrade)
	{
		printf("[!] You have to upgrade your gijohn, because it's too old to use! Exiting...\n");
		destroysession();
		exit(1);
	}

	sprintf(query, "/getpieces.php?sessionid=%s", xmlxml.sessionid);
	do
	{
		*xmlxml.error = 0;
		if ((sd = getconnection(host_entry, gijohnport)) < 0)
		{
			strncpy(xmlxml.error, "connection error",
			    strlen("connection error"));
			printf("[-] Connection error\n[+]"
			" Sleeping for %dsec... and reconnection\n", SLEEP_TIME);
			sleep(SLEEP_TIME);
		}
		else
		{
			getxml(sd, &xml, query, gijohnserver, gijohnport, options.flags & FLG_VERBOSE);
			close(sd);
			parsexml(xml);
			free(xml);
			if (*xmlxml.error)
			{
				printf("[-] Error (new keyspace): %s\n[+] "
				"Sleeping for %dsec... and resending\n", xmlxml.error, SLEEP_TIME);
				sleep(SLEEP_TIME);
			}
		}
	}
	while (*xmlxml.error);

	if (firstrun)
	{
		ldr_init_database(&database, &options.loader);
	}

	if (xmlxml.clearhashes)
	{
		memset(&database, '\0', sizeof(struct db_main));
		ldr_init_database(&database, &options.loader);
	}

	if (*xmlxml.error == 0)
	{
		if (*xmlxml.newhashes) ldr_load_xml_array(&database, xmlxml.newhashes, xmlxml.format);
		if (*xmlxml.delhashes) ldr_load_xml_delarray(&database, xmlxml.delhashes);
		if (*xmlxml.newhashes || *xmlxml.delhashes) ldr_fix_xmldatabase(&database, xmlxml.clearhashes | firstrun);
	}
	else
	{
		printf("[-] Error: %s\n", xmlxml.error); exit(1);
	}

	if ((options.flags & FLG_VERBOSE) || firstrun)
	{
		log_event("Remaining %s", john_loaded_counts());
		printf("[+] Loaded %s (%s [%s])\n",	john_loaded_counts(),
		database.format->params.format_name,
		database.format->params.algorithm_name);
	}

	if (firstrun)
	{
		printf("[+] Server: %s\n[+] Charset: %s\n[+] Charset length: %d\n", gijohnserver, xmlxml.keymap.charset, (int)strlen(xmlxml.keymap.charset));
	}

	return 0;
}