⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 loader.c

📁 UNIX、linux密码的破密程序源代码实现
💻 C
📖 第 1 页 / 共 2 页
字号:
		current_pw->next = last_pw;		last_pw = db->password_hash[pw_hash];		db->password_hash[pw_hash] = current_pw;		current_pw->next_hash = last_pw;		current_pw->binary = mem_alloc_copy(			format->params.binary_size, MEM_ALIGN_WORD, binary);		current_pw->source = str_alloc_copy(piece);		if (db->options->flags & DB_WORDS) {			if (!words)				words = ldr_init_words(login, gecos, home);			current_pw->words = words;		}		if (db->options->flags & DB_LOGIN) {			if (count > 1) {				current_pw->login = mem_alloc_tiny(					strlen(login) + 3, MEM_ALIGN_NONE);				sprintf(current_pw->login, "%s:%d",					login, index + 1);			} else			if (words)				current_pw->login = words->head->data;			else				current_pw->login = str_alloc_copy(login);		}	}}void ldr_load_pw_file(struct db_main *db, char *name){	read_file(db, name, RF_ALLOW_DIR, ldr_load_pw_line);}static void ldr_load_pot_line(struct db_main *db, char *line){	struct fmt_main *format = db->format;	char *ciphertext;	void *binary;	int hash;	struct db_password *current;	ciphertext = ldr_get_field(&line);	if (format->methods.valid(ciphertext) != 1) return;	ciphertext = format->methods.split(ciphertext, 0);	binary = format->methods.binary(ciphertext);	hash = LDR_HASH_FUNC(binary);	if ((current = db->password_hash[hash]))	do {		if (current->binary && !memcmp(current->binary, binary,		    format->params.binary_size) &&		    !strcmp(current->source, ciphertext))			current->binary = NULL;	} while ((current = current->next_hash));}void ldr_load_pot_file(struct db_main *db, char *name){	if (db->format)		read_file(db, name, RF_ALLOW_MISSING, ldr_load_pot_line);}static void ldr_init_salts(struct db_main *db){	struct db_salt **tail, *current;	int hash;	for (hash = 0, tail = &db->salts; hash < SALT_HASH_SIZE; hash++)	if ((current = db->salt_hash[hash])) {		*tail = current;		do {			tail = &current->next;		} while ((current = current->next));	}}static void ldr_remove_marked(struct db_main *db){	struct db_salt *current_salt, *last_salt;	struct db_password *current_pw, *last_pw;	last_salt = NULL;	if ((current_salt = db->salts))	do {		last_pw = NULL;		if ((current_pw = current_salt->list))		do {			if (!current_pw->binary) {				db->password_count--;				current_salt->count--;				if (last_pw)					last_pw->next = current_pw->next;				else					current_salt->list = current_pw->next;			} else				last_pw = current_pw;		} while ((current_pw = current_pw->next));		if (!current_salt->list) {			db->salt_count--;			if (last_salt)				last_salt->next = current_salt->next;			else				db->salts = current_salt->next;		} else			last_salt = current_salt;	} while ((current_salt = current_salt->next));}static void ldr_filter_salts(struct db_main *db){	struct db_salt *current, *last;	last = NULL;	if ((current = db->salts))	do {		if (current->count < db->options->min_pps ||		    current->count > db->options->max_pps) {			if (last)				last->next = current->next;			else				db->salts = current->next;			db->salt_count--;			db->password_count -= current->count;		} else			last = current;	} while ((current = current->next));}void ldr_update_salt(struct db_main *db, struct db_salt *salt){	struct db_password *current;	int (*hash_func)(void *binary);	int hash;	if (salt->hash_size < 0) {		salt->count = 0;		if ((current = salt->list))		do {			current->next_hash = current->next;			salt->count++;		} while ((current = current->next));		return;	}	memset(salt->hash, 0,		password_hash_sizes[salt->hash_size] *		sizeof(struct db_password *));	hash_func = db->format->methods.binary_hash[salt->hash_size];	salt->count = 0;	if ((current = salt->list))	do {		hash = hash_func(current->binary);		current->next_hash = salt->hash[hash];		salt->hash[hash] = current;		salt->count++;	} while ((current = current->next));}static void ldr_init_hash(struct db_main *db){	struct db_salt *current;	int size;	if ((current = db->salts))	do {		for (size = 2; size >= 0; size--)		if (current->count >= password_hash_thresholds[size]) break;		if ((db->format->params.flags & FMT_BS) && !size) size = -1;		if (size >= 0 && mem_saving_level < 2) {			current->hash = mem_alloc_tiny(				password_hash_sizes[size] *				sizeof(struct db_password *),				MEM_ALIGN_WORD);			current->hash_size = size;			current->index = db->format->methods.get_hash[size];		}		ldr_update_salt(db, current);	} while ((current = current->next));}void ldr_fix_database(struct db_main *db){	ldr_init_salts(db);	MEM_FREE(db->password_hash);	MEM_FREE(db->salt_hash);	ldr_remove_marked(db);	ldr_filter_salts(db);	ldr_init_hash(db);	db->loaded = 1;}static int ldr_cracked_hash(char *ciphertext){	int hash = 0;	while (*ciphertext) {		hash <<= 1;		hash ^= *ciphertext++ | 0x20; /* ASCII case insensitive */	}	hash ^= hash >> CRACKED_HASH_LOG;	hash ^= hash >> (2 * CRACKED_HASH_LOG);	hash &= CRACKED_HASH_SIZE - 1;	return hash;}static void ldr_show_pot_line(struct db_main *db, char *line){	char *ciphertext, *pos;	int hash;	struct db_cracked *current, *last;	ciphertext = ldr_get_field(&line);	if (line) {		pos = line;		do {			if (*pos == '\r' || *pos == '\n') *pos = 0;		} while (*pos++);		if (db->options->flags & DB_PLAINTEXTS) {			list_add(db->plaintexts, line);			return;		}		hash = ldr_cracked_hash(ciphertext);		last = db->cracked_hash[hash];		current = db->cracked_hash[hash] =			mem_alloc_tiny(sizeof(struct db_cracked),			MEM_ALIGN_WORD);		current->next = last;		current->ciphertext = str_alloc_copy(ciphertext);		current->plaintext = str_alloc_copy(line);	}}void ldr_show_pot_file(struct db_main *db, char *name){	read_file(db, name, RF_ALLOW_MISSING, ldr_show_pot_line);}static void ldr_show_pw_line(struct db_main *db, char *line){	int show;	char source[LINE_BUFFER_SIZE];	struct fmt_main *format;	char *(*split)(char *ciphertext, int index);	int index, count, unify;	char *login, *ciphertext, *gecos, *home;	char *piece;	int pass, found, chars;	int hash;	struct db_cracked *current;	format = NULL;	count = ldr_split_line(&login, &ciphertext, &gecos, &home,		source, &format, db->options, line);	if (!count) return;	show = !(db->options->flags & DB_PLAINTEXTS);	if (format) {		split = format->methods.split;		unify = format->params.flags & FMT_SPLIT_UNIFIES_CASE;	} else {		split = fmt_default_split;		count = 1;		unify = 0;	}	if (!*ciphertext) {		found = 1;		if (show) printf("%s:NO PASSWORD", login);		db->guess_count++;	} else	for (found = pass = 0; pass == 0 || (pass == 1 && found); pass++)	for (index = 0; index < count; index++) {		piece = split(ciphertext, index);		if (unify)			piece = strcpy(mem_alloc(strlen(piece) + 1), piece);		hash = ldr_cracked_hash(piece);		if ((current = db->cracked_hash[hash]))		do {			if (!strcmp(current->ciphertext, piece))				break;/* This extra check, along with ldr_cracked_hash() being case-insensitive, * is only needed for matching some pot file records produced by older * versions of John and contributed patches where split() didn't unify the * case of hex-encoded hashes. */			if (unify &&			    format->methods.valid(current->ciphertext) == 1 &&			    !strcmp(split(current->ciphertext, 0), piece))				break;		} while ((current = current->next));		if (unify)			MEM_FREE(piece);		if (pass) {			chars = 0;			if (show) {				if (format)					chars = format->params.plaintext_length;				if (index < count - 1 && current &&				    (int)strlen(current->plaintext) != chars)					current = NULL;			}			if (current) {				if (show) {					printf("%s", current->plaintext);				} else					list_add(db->plaintexts,						current->plaintext);				db->guess_count++;			} else			while (chars--)				putchar('?');		} else		if (current) {			found = 1;			if (show) printf("%s:", login);			break;		}	}	if (found && show) {		if (source[0])			printf(":%s", source);		else			putchar('\n');	}	if (format || found) db->password_count += count;}void ldr_show_pw_file(struct db_main *db, char *name){	read_file(db, name, RF_ALLOW_DIR, ldr_show_pw_line);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -