Debian Codegraph @

main.c

raw symbols SCIP
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"
30 #include "samdump2.h"
31 #include "hive.h"
32
33
34 void usage() {
35 printf("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 printf("Usage: samdump2 [OPTION]... SYSTEM_FILE SAM_FILE\n");
40 printf("Retrieves syskey and extract hashes from Windows 2k/NT/XP/Vista SAM\n\n");
41 printf(" -d\t\tenable debugging\n");
42 printf(" -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 printf(" -o file\twrite output to file\n");
47 }
48
49
50 int main( int argc, char **argv ) {
51
52 unsigned char pkey[0x10];
53 list_t *hash_list;
54 list_nd_t *hash;
55 char error[512];
56 int debug=0, i=0, live=0;
57 char *file=0;
58 FILE *output;
59 int c;
60 #ifdef WIN32
61 unsigned char *buff_sam;
62 int size = 0;
63 #endif
64
65 while ((c = getopt(argc, argv, "hdlo:")) != -1)
66 switch(c) {
67 case 'd':
68 debug = 1;
69 break;
70 case 'o':
71 file = strdup(optarg);
72 break;
73 case 'h':
74 usage();
75 return -1;
76 break;
77 #ifdef WIN32
78 case 'l':
79 live = 1;
80 break;
81 #endif
82 default:
83 usage();
84 return -1;
85 break;
86 }
87
88 if (!live && argc-optind != 2) {
89 usage();
90 return -1;
91 }
92
93 if (file) {
94 output = fopen(file, "w");
95 if (output == 0) {
96 printf("Cannot open file %s for writing.\n", file);
97 exit(1);
98 }
99 }
100
101 hash_list = list_alloc();
102
103 if (!live) {
104 if (bkhive((unsigned char *)argv[argc-2], pkey, error, debug) == -1) {
105 printf("%s", error);
106 exit(-1);
107 }
108
109 if (samdump2((unsigned char *)argv[argc-1], hash_list, pkey, error, debug, live, 0) == -1) {
110 printf("%s", error);
111 exit(-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_t *) hash_list->head;
133
134 for (i=0; i<hash_list->size; i++) {
135 if (file)
136 fprintf(output, "%s\n", (char *)hash->data);
137 else
138 printf("%s\n", (char *)hash->data);
139 hash = hash->prev;
140 }
141
142 if (file)
143 fclose(output);
144
145 #ifdef WIN32
146 free(buff_sam);
147 #endif
148
149 return 0;
150 }