Debian Codegraph @

bkhive.c

raw symbols SCIP
1 /* Bkhive
2 Extract Syskey bootkey from the system hive file
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 Copyright (C) 2004-2006 Nicola Cuomo <[email protected]>
19 Improvments and some bugs fixes by Objectif Securite
20 <http://www.objectif-securite.ch>
21 */
22
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #if defined(__linux__cxx . . $ `<built-in>:400:9`!)
27 #include <endian.h>
28 #elif defined(__FreeBSD__)
29 #include <machine/endian.h>
30 #endif
31
32 #include "hive.h"cxx . . $ `<file>/hive.h`/
33
34 #ifdef BYTE_ORDERcxx . . $ `<external>/15855202785537844739/endian.h:30:10`!
35 #if BYTE_ORDERcxx . . $ `<external>/15855202785537844739/endian.h:30:10`! == LITTLE_ENDIANcxx . . $ `<external>/15855202785537844739/endian.h:27:10`!
36 #elif BYTE_ORDER == BIG_ENDIAN
37 #include <byteswap.h>
38 #else
39 #warning "Doesn't define a standard ENDIAN type"
40 #endif
41 #else
42 #warning "Doesn't define BYTE_ORDER"
43 #endif
44
45
46 int bkhivecxx . . $ bkhive(39ba397a76982871).(unsigned char *system, unsigned char *pkey, char *error, int debug) {
47
48 /* hive */
49 struct hivecxx . . $ hive# h;
50 nk_hdrcxx . . $ nk_hdr# *n = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
51 unsigned char *b;
52
53 int i, j, buf_len, control;
54
55 char *kn[] = { "JD", "Skew1", "GBG", "Data" };
56 char kv[9];
57 unsigned char *buf = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
58 char *keyname;
59 char *root_key, *regselect, *reglsa;
60 // System\ControlSet001\Control\Lsa\ on some nt4 box
61
62 unsigned char key[0x10];
63
64 #if BYTE_ORDERcxx . . $ `<external>/15855202785537844739/endian.h:30:10`! == LITTLE_ENDIANcxx . . $ `<external>/15855202785537844739/endian.h:27:10`!
65 int p[] = { 0xb, 0x6, 0x7, 0x1, 0x8, 0xa, 0xe, 0x0, 0x3, 0x5, 0x2, 0xf, 0xd, 0x9, 0xc, 0x4 };
66 #elif BYTE_ORDER == BIG_ENDIAN
67 int p[] = { 0x8, 0x5, 0x4, 0x2, 0xb, 0x9, 0xd, 0x3, 0x0, 0x6, 0x1, 0xc, 0xe, 0xa, 0xf, 0x7 };
68 #endif
69
70
71 /* Initialize hive access */
72 _InitHivecxx . . $ _InitHive(75e6f13f219d000f).( &h );
73
74 /* Open the system hive file */
75 if( _RegOpenHivecxx . . $ _RegOpenHive(84cbfd8c19656c97).( system, &h ) ) {
76 sprintfcxx . . $ sprintf(26c8642d26409d6d).(error, "Error opening hive file %s\n", system );
77 return -1;
78 }
79
80 /* Get Root key name
81 $$$PROTO.HIV for 2k/XP,
82 CMI-CreateHive{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx} for Vista */
83 if( _RegGetRootKeycxx . . $ _RegGetRootKey(3d851ed2cd37585f).( &h, &root_key)) {
84 sprintfcxx . . $ sprintf(26c8642d26409d6d).(error, "Error reading hive root key\n");
85 return -1;
86 }
87
88 if (debug)
89 printfcxx . . $ printf(581fddd72a8db8fc).("Root Key : %s\n", root_key);
90
91 regselect = (char *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(strlencxx . . $ strlen(751346f8406fd082).(root_key)+10);
92 reglsa = (char *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(strlencxx . . $ strlen(751346f8406fd082).(root_key)+33);
93
94 sprintfcxx . . $ sprintf(26c8642d26409d6d).(regselect, "%s\\Select", root_key);
95
96 /* Find the Default ControlSet */
97 n = (nk_hdrcxx . . $ nk_hdr#*) malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(nk_hdrcxx . . $ nk_hdr#));
98
99 if (!_RegOpenKeycxx . . $ _RegOpenKey(31ebb3f0ca3e6396).(&h, regselect, &n))
100 if (!_RegQueryValuecxx . . $ _RegQueryValue(9d8dfe56b004a603).( &h, "Default", n, &buf, &buf_len)) {
101 if (buf_len == 4)
102 control = *(int*)(buf);
103 else
104 control = 1;
105
106 sprintfcxx . . $ sprintf(26c8642d26409d6d).(reglsa,"%s\\ControlSet%03d\\Control\\Lsa\\", root_key, control);
107 if (debug)
108 printfcxx . . $ printf(581fddd72a8db8fc).("Default ControlSet: %03d\n", control);
109 }
110 else {
111 sprintfcxx . . $ sprintf(26c8642d26409d6d).(error, "Error reading ControlSet: _RegQueryValue\n");
112 return -1;
113 }
114 else {
115 sprintfcxx . . $ sprintf(26c8642d26409d6d).(error, "Error reading ControlSet: _RegOpenKey\n");
116 return -1;
117 }
118
119
120 /* foreach keys */
121 for( i = 0; i < 4; i++ ) {
122 keyname = (char *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64).( strlencxx . . $ strlen(751346f8406fd082).( reglsa ) + strlencxx . . $ strlen(751346f8406fd082).( kn[i] ) + 1 );
123 sprintfcxx . . $ sprintf(26c8642d26409d6d).( keyname, "%s%s", reglsa, kn[i] );
124 if (debug)
125 printfcxx . . $ printf(581fddd72a8db8fc).("********* %s *********\n", keyname);
126
127 /* Access lsa subkey */
128 if( _RegOpenKeycxx . . $ _RegOpenKey(31ebb3f0ca3e6396).( &h, keyname, &n ) ) {
129 _RegCloseHivecxx . . $ _RegCloseHive(75e6f13f219d000f).( &h );
130
131 sprintfcxx . . $ sprintf(26c8642d26409d6d).(error, "Error accessing key %s\nWrong/corrupted hive??\n", kn[i] );
132 return -1;
133 }
134
135 /* Access the data */
136 b = read_datacxx . . $ read_data(c27d5f014b3fecf5).( &h, n->classname_offcxx . . $ _nk_hdr#classname_off. + 0x1000 );
137 if (debug)
138 printfcxx . . $ printf(581fddd72a8db8fc).("n->classname_len = %d b = %x\n",
139 n->classname_lencxx . . $ _nk_hdr#classname_len.,
140 (unsigned int)(b-(h.basecxx . . $ hive#base.)));
141
142 // Quick hack for unicode -> ascii translation
143 for( j = 0; j < n->classname_lencxx . . $ _nk_hdr#classname_len. && j<9; j++)
144 kv[j] = b[j*2];
145 kv[8] = 0;
146 sscanfcxx . . $ sscanf(5e8a2c12db2ea735).( kv, "%x", (unsigned int*)( &key[i*4] ) );
147
148 freecxx . . $ free(5d22bdacc48458e8).( keyname );
149 }
150
151 _RegCloseHivecxx . . $ _RegCloseHive(75e6f13f219d000f).( &h );
152
153 if (debug) {
154 printfcxx . . $ printf(581fddd72a8db8fc).("Bootkey unsorted: ");
155 for( i = 0; i < 0x10; i++ ) {
156 printfcxx . . $ printf(581fddd72a8db8fc).("%.2x", key[i]);
157 }
158 printfcxx . . $ printf(581fddd72a8db8fc).("\n");
159 }
160
161 for( i = 0; i < 0x10; i++ ) {
162 /* Permute the class name */
163 pkey[i] = key[p[i]];
164 }
165
166 freecxx . . $ free(5d22bdacc48458e8).(n);
167 return 0;
168 }
169