📄 unshadow.c
字号:
/* * This file is part of John the Ripper password cracker, * Copyright (c) 1996-99 by Solar Designer */#include <stdio.h>#include <string.h>#include "misc.h"#include "params.h"#include "memory.h"struct shadow_entry { struct shadow_entry *next; char *login, *passwd;};static struct shadow_entry **shadow_table;static int login_hash(char *login){ int hash = 0; while (*login) { hash <<= 1; hash ^= *login++; } hash ^= hash >> SHADOW_HASH_LOG; hash ^= hash >> (2 * SHADOW_HASH_LOG); hash &= SHADOW_HASH_SIZE - 1; return hash;}static void read_file(char *name, void (*process_line)(char *line)){ FILE *file; char line[LINE_BUFFER_SIZE]; if (!(file = fopen(name, "r"))) pexit("fopen: %s", name); while (fgetl(line, sizeof(line), file)) process_line(line); if (ferror(file)) pexit("fgets"); if (fclose(file)) pexit("fclose");}static void process_shadow_line(char *line){ static struct shadow_entry **entry = NULL; struct shadow_entry *last; char *login, *passwd, *tail; if (!(passwd = strchr(line, ':'))) { while (*line == ' ' || *line == '\t') line++; if (!strncmp(line, "password = ", 11) && entry) /* AIX */ (*entry)->passwd = str_alloc_copy(line + 11); return; } login = line; *passwd++ = 0; if (!strncmp(passwd, "u_name=", 7)) { /* DU C2 */ if (!(passwd = strstr(passwd, ":u_pwd="))) return; passwd += 7; } if (!(tail = strchr(passwd, ':'))) tail = passwd + strlen(passwd); *tail = 0; entry = &shadow_table[login_hash(login)]; last = *entry; *entry = mem_alloc_tiny(sizeof(struct shadow_entry), MEM_ALIGN_WORD); (*entry)->next = last; (*entry)->login = str_alloc_copy(login); (*entry)->passwd = str_alloc_copy(passwd);}static void process_passwd_line(char *line){ char *pos1, *pos2; struct shadow_entry *current; if (!(pos1 = strchr(line, ':'))) return; *pos1++ = 0; if (!(pos2 = strchr(pos1, ':'))) pos2 = pos1 + strlen(pos1); if (pos2 > pos1 && (current = shadow_table[login_hash(line)])) do { if (!strcmp(current->login, line)) { printf("%s:%s%s\n", line, current->passwd, pos2); return; } } while ((current = current->next)); printf("%s:%s\n", line, pos1);}int unshadow(int argc, char **argv){ if (argc != 3) { printf("Usage: %s PASSWORD-FILE SHADOW-FILE\n", argv[0] ? argv[0] : "unshadow"); if (argc <= 1) return 0; else error(); } shadow_table = (struct shadow_entry **) mem_alloc(SHADOW_HASH_SIZE * sizeof(struct shadow_entry *)); memset(shadow_table, 0, sizeof(shadow_table)); read_file(argv[2], process_shadow_line); read_file(argv[1], process_passwd_line); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -