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

📄 loader.c

📁 著名的解Unix密码的源程序
💻 C
📖 第 1 页 / 共 2 页
字号:
		current_salt->count++;		db->password_count++;		last_pw = current_salt->list;		current_pw = current_salt->list = mem_alloc_tiny(			pw_size, MEM_ALIGN_WORD);		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_split_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 *salt;	int hash;	struct db_salt *current_salt, *last_salt;	struct db_password *current_pw, *last_pw;	ciphertext = ldr_get_field(&line);	hash = LDR_HASH_FUNC(format->methods.binary(ciphertext));	if (!(current_pw = db->password_hash[hash])) return;	last_pw = NULL;	do {		if (!strcmp(current_pw->source, ciphertext)) break;		last_pw = current_pw;	} while ((current_pw = current_pw->next_hash));	if (!current_pw) return;	if (last_pw) last_pw->next_hash = current_pw->next_hash;	else db->password_hash[hash] = current_pw->next_hash;	salt = format->methods.salt(ciphertext);	hash = format->methods.salt_hash(salt);	last_salt = NULL;	if ((current_salt = db->salt_hash[hash]))	do {		if (!memcmp(current_salt->salt, salt,			format->params.salt_size)) break;		last_salt = current_salt;	} while ((current_salt = current_salt->next));	if (!current_salt) return;	do {		last_pw = NULL;		current_pw = current_salt->list;		do {			if (!strcmp(current_pw->source, ciphertext)) break;			last_pw = current_pw;		} while ((current_pw = current_pw->next));		if (!current_pw) break;		db->password_count--;		current_salt->count--;		if (last_pw) last_pw->next = current_pw->next; else		if (!(current_salt->list = current_pw->next)) {			db->salt_count--;			if (last_salt) last_salt->next = current_salt->next;			else db->salt_hash[hash] = current_salt->next;			break;		}	} while (1);}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_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];	if ((current = salt->list))	do {		hash = hash_func(current->binary);		current->next_hash = salt->hash[hash];		salt->hash[hash] = current;	} 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 (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((void **)&db->password_hash);	mem_free((void **)&db->salt_hash);	ldr_filter_salts(db);	ldr_init_hash(db);}static int ldr_cracked_hash(char *ciphertext){	int hash = 0;	while (*ciphertext) {		hash <<= 1;		hash ^= *ciphertext++;	}	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;	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;	} else {		split = fmt_default_split;		count = 1;	}	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);		hash = ldr_cracked_hash(piece);		if ((current = db->cracked_hash[hash]))		do {			if (!strcmp(current->ciphertext, piece)) break;		} while ((current = current->next));		if (pass) {			if (current) {				if (show) printf("%s", current->plaintext);				else list_add(db->plaintexts,					current->plaintext);				db->guess_count++;			} else			if (show) {				chars = format->params.plaintext_length;				do {					putchar('?');				} while (--chars);			}		} 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 + -