File: main.c

package info (click to toggle)
samdump2 3.0.0-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 308 kB
  • sloc: ansic: 3,249; makefile: 228
file content (150 lines) | stat: -rw-r--r-- 3,616 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/** main.c
    Main file for samdump2 2.x
    
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
    as published by the Free Software Foundation; either version 2
    of the License, or (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

    This program is released under the GPL with the additional exemption 
    that compiling, linking, and/or using OpenSSL is allowed.
    
    Copyright (C) 2008 Cedric Tissieres <http://www.objectif-securite.ch>
*/

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

#include "list.h"
#include "samdump2.h"
#include "hive.h"


void usage() {
  printf("samdump2 3.0.0 by Objectif Securite (http://www.objectif-securite.ch)\noriginal author: ncuomo@studenti.unina.it\n\n");
#ifdef WIN32
  printf("Usage: samdump2 [OPTION] -l (pwdump-like, only on Windows)\n");
#endif
  printf("Usage: samdump2 [OPTION]... SYSTEM_FILE SAM_FILE\n");
  printf("Retrieves syskey and extract hashes from Windows 2k/NT/XP/Vista SAM\n\n");
  printf("  -d\t\tenable debugging\n");
  printf("  -h\t\tdisplay this information\n");
#ifdef WIN32
  printf("  -l\t\textracts hashes from a live Windows, with low-level access to NTFS\n");
#endif
  printf("  -o file\twrite output to file\n");
}


int main( int argc, char **argv ) {

  unsigned char pkey[0x10];
  list_t *hash_list;
  list_nd_t *hash;
  char error[512];
  int debug=0, i=0, live=0;
  char *file=0;
  FILE *output;
  int c;
#ifdef WIN32
  unsigned char *buff_sam;
  int size = 0;
#endif

  while ((c = getopt(argc, argv, "hdlo:")) != -1)
    switch(c) {
    case 'd':
      debug = 1;
      break;
    case 'o':
      file = strdup(optarg);
      break;
    case 'h':
      usage();
      return -1;
      break;
#ifdef WIN32
    case 'l':
      live = 1;
      break;
#endif
    default:
      usage();
      return -1;
      break;
    }

  if (!live && argc-optind != 2) {
    usage();
    return -1;
  }

  if (file) {
    output = fopen(file, "w");
    if (output == 0) {
      printf("Cannot open file %s for writing.\n", file);
      exit(1);
    }
  }

  hash_list = list_alloc();

  if (!live) {
    if (bkhive((unsigned char *)argv[argc-2], pkey, error, debug) == -1) {
      printf("%s", error);
      exit(-1);
    }
    
    if (samdump2((unsigned char *)argv[argc-1], hash_list, pkey, error, debug, live, 0) == -1) {
      printf("%s", error);
      exit(-1);
    }
  } else {
#ifdef WIN32
    if (get_live_syskey(pkey, error, debug) == -1) {
      printf("%s", error);
      exit(-1);
    }
    
    if (get_sam(&buff_sam, &size, error, debug) == -1) {
      printf("%s", error);
      exit(-1);
    }

    if (samdump2(buff_sam, hash_list, pkey, error, debug, live, size) == -1) {
      printf("%s", error);
      exit(-1);
    }
#endif
  }

  hash = (list_nd_t *) hash_list->head;

  for (i=0; i<hash_list->size; i++) {
    if (file)
      fprintf(output, "%s\n", (char *)hash->data);
    else
      printf("%s\n", (char *)hash->data);
    hash = hash->prev;
  }
  
  if (file)
    fclose(output);

#ifdef WIN32
  free(buff_sam);
#endif

  return 0;
}