| 1 | /** main.c |
| 2 | Main file for samdump2 2.x |
| 3 | |
| 4 | This program is free software; you can redistribute it and/or |
| 5 | modify it under the terms of the GNU General Public License |
| 6 | as published by the Free Software Foundation; either version 2 |
| 7 | of the License, or (at your option) any later version. |
| 8 | |
| 9 | This program is distributed in the hope that it will be useful, |
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | GNU General Public License for more details. |
| 13 | |
| 14 | You should have received a copy of the GNU General Public License |
| 15 | along with this program; if not, write to the Free Software |
| 16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | |
| 18 | This program is released under the GPL with the additional exemption |
| 19 | that compiling, linking, and/or using OpenSSL is allowed. |
| 20 | |
| 21 | Copyright (C) 2008 Cedric Tissieres <http://www.objectif-securite.ch> |
| 22 | */ |
| 23 | |
| 24 | #include <stdio.h> |
| 25 | #include <stdlib.h> |
| 26 | #include <unistd.h> |
| 27 | #include <string.h> |
| 28 | |
| 29 | #include "list.h"cxx . . $ `<file>/list.h`/ |
| 30 | #include "samdump2.h"cxx . . $ `<file>/samdump2.h`/ |
| 31 | #include "hive.h"cxx . . $ `<file>/hive.h`/ |
| 32 | |
| 33 | |
| 34 | void usagecxx . . $ usage(d878ad36e69247c7).() { |
| 35 | printfcxx . . $ printf(581fddd72a8db8fc).("samdump2 3.0.0 by Objectif Securite (http://www.objectif-securite.ch)\noriginal author: [email protected]\n\n"); |
| 36 | #ifdef WIN32 |
| 37 | printf("Usage: samdump2 [OPTION] -l (pwdump-like, only on Windows)\n"); |
| 38 | #endif |
| 39 | printfcxx . . $ printf(581fddd72a8db8fc).("Usage: samdump2 [OPTION]... SYSTEM_FILE SAM_FILE\n"); |
| 40 | printfcxx . . $ printf(581fddd72a8db8fc).("Retrieves syskey and extract hashes from Windows 2k/NT/XP/Vista SAM\n\n"); |
| 41 | printfcxx . . $ printf(581fddd72a8db8fc).(" -d\t\tenable debugging\n"); |
| 42 | printfcxx . . $ printf(581fddd72a8db8fc).(" -h\t\tdisplay this information\n"); |
| 43 | #ifdef WIN32 |
| 44 | printf(" -l\t\textracts hashes from a live Windows, with low-level access to NTFS\n"); |
| 45 | #endif |
| 46 | printfcxx . . $ printf(581fddd72a8db8fc).(" -o file\twrite output to file\n"); |
| 47 | } |
| 48 | |
| 49 | |
| 50 | int maincxx . . $ main(afcd3168fc1188a4).( int argc, char **argv ) { |
| 51 | |
| 52 | unsigned char pkey[0x10]; |
| 53 | list_tcxx . . $ list_t# *hash_list; |
| 54 | list_nd_tcxx . . $ list_nd_t# *hash; |
| 55 | char error[512]; |
| 56 | int debug=0, i=0, live=0; |
| 57 | char *file=0; |
| 58 | FILEcxx . . $ FILE# *output; |
| 59 | int c; |
| 60 | #ifdef WIN32 |
| 61 | unsigned char *buff_sam; |
| 62 | int size = 0; |
| 63 | #endif |
| 64 | |
| 65 | while ((c = getoptcxx . . $ getopt(2483c31ff9bab884).(argc, argv, "hdlo:")) != -1) |
| 66 | switch(c) { |
| 67 | case 'd': |
| 68 | debug = 1; |
| 69 | break; |
| 70 | case 'o': |
| 71 | file = strdupcxx . . $ strdup(a8b8e32347182212).(optargcxx . . $ optarg.); |
| 72 | break; |
| 73 | case 'h': |
| 74 | usagecxx . . $ usage(d878ad36e69247c7).(); |
| 75 | return -1; |
| 76 | break; |
| 77 | #ifdef WIN32 |
| 78 | case 'l': |
| 79 | live = 1; |
| 80 | break; |
| 81 | #endif |
| 82 | default: |
| 83 | usagecxx . . $ usage(d878ad36e69247c7).(); |
| 84 | return -1; |
| 85 | break; |
| 86 | } |
| 87 | |
| 88 | if (!live && argc-optindcxx . . $ optind. != 2) { |
| 89 | usagecxx . . $ usage(d878ad36e69247c7).(); |
| 90 | return -1; |
| 91 | } |
| 92 | |
| 93 | if (file) { |
| 94 | output = fopencxx . . $ fopen(82ec0787cd37e0a3).(file, "w"); |
| 95 | if (output == 0) { |
| 96 | printfcxx . . $ printf(581fddd72a8db8fc).("Cannot open file %s for writing.\n", file); |
| 97 | exitcxx . . $ exit(3ca292c338df9bb3).(1); |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | hash_list = list_alloccxx . . $ list_alloc(a211c0eefd2c4fb9).(); |
| 102 | |
| 103 | if (!live) { |
| 104 | if (bkhivecxx . . $ bkhive(39ba397a76982871).((unsigned char *)argv[argc-2], pkey, error, debug) == -1) { |
| 105 | printfcxx . . $ printf(581fddd72a8db8fc).("%s", error); |
| 106 | exitcxx . . $ exit(3ca292c338df9bb3).(-1); |
| 107 | } |
| 108 | |
| 109 | if (samdump2cxx . . $ samdump2(1a80424bda6f31a3).((unsigned char *)argv[argc-1], hash_list, pkey, error, debug, live, 0) == -1) { |
| 110 | printfcxx . . $ printf(581fddd72a8db8fc).("%s", error); |
| 111 | exitcxx . . $ exit(3ca292c338df9bb3).(-1); |
| 112 | } |
| 113 | } else { |
| 114 | #ifdef WIN32 |
| 115 | if (get_live_syskey(pkey, error, debug) == -1) { |
| 116 | printf("%s", error); |
| 117 | exit(-1); |
| 118 | } |
| 119 | |
| 120 | if (get_sam(&buff_sam, &size, error, debug) == -1) { |
| 121 | printf("%s", error); |
| 122 | exit(-1); |
| 123 | } |
| 124 | |
| 125 | if (samdump2(buff_sam, hash_list, pkey, error, debug, live, size) == -1) { |
| 126 | printf("%s", error); |
| 127 | exit(-1); |
| 128 | } |
| 129 | #endif |
| 130 | } |
| 131 | |
| 132 | hash = (list_nd_tcxx . . $ list_nd_t# *) hash_list->headcxx . . $ list_t_#head.; |
| 133 | |
| 134 | for (i=0; i<hash_list->sizecxx . . $ list_t_#size.; i++) { |
| 135 | if (file) |
| 136 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(output, "%s\n", (char *)hash->datacxx . . $ list_nd_t_#data.); |
| 137 | else |
| 138 | printfcxx . . $ printf(581fddd72a8db8fc).("%s\n", (char *)hash->datacxx . . $ list_nd_t_#data.); |
| 139 | hash = hash->prevcxx . . $ list_nd_t_#prev.; |
| 140 | } |
| 141 | |
| 142 | if (file) |
| 143 | fclosecxx . . $ fclose(89bc1efcdac0ca22).(output); |
| 144 | |
| 145 | #ifdef WIN32 |
| 146 | free(buff_sam); |
| 147 | #endif |
| 148 | |
| 149 | return 0; |
| 150 | } |