-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathCreateProcessAsPPL.cpp
More file actions
273 lines (240 loc) · 8.91 KB
/
CreateProcessAsPPL.cpp
File metadata and controls
273 lines (240 loc) · 8.91 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
271
272
273
#include <windows.h>
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#pragma comment(lib, "advapi32.lib")
class PPLProcessCreator
{
private:
HANDLE m_hProcess;
HANDLE m_hThread;
public:
PPLProcessCreator() : m_hProcess(nullptr), m_hThread(nullptr) {}
~PPLProcessCreator()
{
if (m_hProcess) CloseHandle(m_hProcess);
if (m_hThread) CloseHandle(m_hThread);
}
DWORD GetPPLProtectionLevel(DWORD processId)
{
DWORD protectionLevel = 0;
HANDLE hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, processId);
if (hProcess)
{
PROCESS_PROTECTION_LEVEL_INFORMATION protectionInfo;
DWORD returnLength = 0;
if (GetProcessInformation(hProcess, ProcessProtectionLevelInfo,
&protectionInfo, sizeof(protectionInfo)))
{
protectionLevel = protectionInfo.ProtectionLevel;
}
CloseHandle(hProcess);
}
return protectionLevel;
}
std::wstring GetPPLProtectionLevelName(DWORD protectionLevel)
{
switch (protectionLevel)
{
case PROTECTION_LEVEL_WINTCB_LIGHT:
return L"PROTECTION_LEVEL_WINTCB_LIGHT";
case PROTECTION_LEVEL_WINDOWS:
return L"PROTECTION_LEVEL_WINDOWS";
case PROTECTION_LEVEL_WINDOWS_LIGHT:
return L"PROTECTION_LEVEL_WINDOWS_LIGHT";
case PROTECTION_LEVEL_ANTIMALWARE_LIGHT:
return L"PROTECTION_LEVEL_ANTIMALWARE_LIGHT";
case PROTECTION_LEVEL_LSA_LIGHT:
return L"PROTECTION_LEVEL_LSA_LIGHT";
default:
return L"Unknown protection level";
}
}
bool CreatePPLProcess(DWORD protectionLevel, const std::wstring& executablePath, const std::wstring& commandLine = L"")
{
SIZE_T size = 0;
STARTUPINFOEXW siex = { 0 };
siex.StartupInfo.cb = sizeof(siex);
PROCESS_INFORMATION pi = { 0 };
LPPROC_THREAD_ATTRIBUTE_LIST ptal = nullptr;
// Initialize attribute list size
if (!InitializeProcThreadAttributeList(nullptr, 1, 0, &size) && GetLastError() != ERROR_INSUFFICIENT_BUFFER)
{
std::wcerr << L"InitializeProcThreadAttributeList failed: " << GetLastError() << std::endl;
return false;
}
// Allocate attribute list
ptal = reinterpret_cast<LPPROC_THREAD_ATTRIBUTE_LIST>(HeapAlloc(GetProcessHeap(), 0, size));
if (!ptal)
{
std::wcerr << L"HeapAlloc failed: " << GetLastError() << std::endl;
return false;
}
// Initialize attribute list
if (!InitializeProcThreadAttributeList(ptal, 1, 0, &size))
{
std::wcerr << L"InitializeProcThreadAttributeList failed: " << GetLastError() << std::endl;
HeapFree(GetProcessHeap(), 0, ptal);
return false;
}
// Set protection level
//DWORD protectionLevel = PROTECTION_LEVEL_ANTIMALWARE_LIGHT;
if (!UpdateProcThreadAttribute(ptal, 0, PROC_THREAD_ATTRIBUTE_PROTECTION_LEVEL, &protectionLevel, sizeof(protectionLevel), nullptr, nullptr))
{
std::wcerr << L"UpdateProcThreadAttribute failed: " << GetLastError() << std::endl;
DeleteProcThreadAttributeList(ptal);
HeapFree(GetProcessHeap(), 0, ptal);
return false;
}
siex.lpAttributeList = ptal;
// Prepare command line (CreateProcessW requires modifiable string)
std::wstring fullCommandLine = L"\"" + executablePath + L"\"";
if (!commandLine.empty()) {
fullCommandLine += L" " + commandLine;
}
std::vector<wchar_t> cmdLineBuffer(fullCommandLine.begin(), fullCommandLine.end());
cmdLineBuffer.push_back(L'\0');
// Create process with PPL protection
if (!CreateProcessW(
executablePath.c_str(), // Application name
cmdLineBuffer.data(), // Command line
nullptr, // Process security attributes
nullptr, // Thread security attributes
FALSE, // Inherit handles
EXTENDED_STARTUPINFO_PRESENT | CREATE_PROTECTED_PROCESS,
nullptr, // Environment
nullptr, // Current directory
&siex.StartupInfo, // Startup info
&pi)) // Process information
{
std::wcerr << L"CreateProcessW failed: " << GetLastError() << std::endl;
DeleteProcThreadAttributeList(ptal);
HeapFree(GetProcessHeap(), 0, ptal);
return false;
}
// Clean up attribute list
DeleteProcThreadAttributeList(ptal);
HeapFree(GetProcessHeap(), 0, ptal);
m_hProcess = pi.hProcess;
m_hThread = pi.hThread;
std::wcout << L"Successfully created PPL process with PID: " << pi.dwProcessId << std::endl;
std::wcerr << L"Protection level: " << GetPPLProtectionLevelName(GetPPLProtectionLevel(pi.dwProcessId)) << std::endl;
return true;
}
bool WaitForProcess(DWORD timeout = INFINITE)
{
if (!m_hProcess) return false;
DWORD result = WaitForSingleObject(m_hProcess, timeout);
if (result == WAIT_OBJECT_0) {
DWORD exitCode;
if (GetExitCodeProcess(m_hProcess, &exitCode)) {
std::wcout << L"Process exited with code: " << exitCode << std::endl;
}
return true;
}
return false;
}
HANDLE GetProcessHandle() const { return m_hProcess; }
HANDLE GetThreadHandle() const { return m_hThread; }
};
// Function to check if we have sufficient privileges
bool CheckPrivileges()
{
HANDLE hToken;
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken))
{
return false;
}
TOKEN_ELEVATION elevation;
DWORD dwSize;
bool isElevated = false;
if (GetTokenInformation(hToken, TokenElevation, &elevation, sizeof(elevation), &dwSize))
{
isElevated = elevation.TokenIsElevated;
}
CloseHandle(hToken);
return isElevated;
}
int wmain(int argc, wchar_t* argv[])
{
std::wcout << L"\nPPL Process Creator" << std::endl;
std::wcout << L"Two Seven One Three: x.com/TwoSevenOneT" << std::endl;
std::wcout << L"==================================================" << std::endl << std::endl;
//
// Check if running with sufficient privileges
if (!CheckPrivileges())
{
std::wcerr << L"Error: This program requires elevated privileges (Run as Administrator)" << std::endl;
return 1;
}
if (argc < 3)
{
std::wcout << L"Usage: " << argv[0] << L"[mode:0-4] <executable_path> [command_line_args]" << std::endl << std::endl;
std::wcout << L"Example: " << argv[0] << L" 1 \"C:\\Windows\\System32\\PPL.exe\"" << std::endl << std::endl;
std::wcout << L"MODE: " << std::endl;
std::wcout << L"PROTECTION_LEVEL_WINTCB_LIGHT 00000000" << std::endl;
std::wcout << L"PROTECTION_LEVEL_WINDOWS 00000001" << std::endl;
std::wcout << L"PROTECTION_LEVEL_WINDOWS_LIGHT 00000002" << std::endl;
std::wcout << L"PROTECTION_LEVEL_ANTIMALWARE_LIGHT 00000003" << std::endl;
std::wcout << L"PROTECTION_LEVEL_LSA_LIGHT 00000004" << std::endl;
return 1;
}
//#define PROTECTION_LEVEL_WINTCB_LIGHT 0x00000000
//#define PROTECTION_LEVEL_WINDOWS 0x00000001
//#define PROTECTION_LEVEL_WINDOWS_LIGHT 0x00000002
//#define PROTECTION_LEVEL_ANTIMALWARE_LIGHT 0x00000003
//#define PROTECTION_LEVEL_LSA_LIGHT 0x00000004
wchar_t* end;
long value = wcstol(argv[1], &end, 10);
DWORD protectionLevel = PROTECTION_LEVEL_ANTIMALWARE_LIGHT;
switch (value)
{
case 0:
{
protectionLevel = PROTECTION_LEVEL_WINTCB_LIGHT;
break;
}
case 1:
{
protectionLevel = PROTECTION_LEVEL_WINDOWS;
break;
}
case 2:
{
protectionLevel = PROTECTION_LEVEL_WINDOWS_LIGHT;
break;
}
case 4:
{
protectionLevel = PROTECTION_LEVEL_LSA_LIGHT;
break;
}
default:
break;
}
PPLProcessCreator creator;
std::wstring executablePath = argv[2];
std::wstring commandLine;
// Build command line from remaining arguments
for (int i = 3; i < argc; ++i)
{
if (!commandLine.empty())
{
commandLine += L" ";
}
commandLine += argv[i];
}
// Create the PPL process
if (creator.CreatePPLProcess(protectionLevel, executablePath, commandLine))
{
std::wcout << L"Process created successfully. Waiting for completion..." << std::endl;
creator.WaitForProcess();
return 0;
}
else
{
std::wcerr << L"Failed to create PPL process." << std::endl;
return 1;
}
}