MCPcopy Create free account
hub / github.com/TwoSevenOneT/WSASS / CreatePPLProcess

Method CreatePPLProcess

PPLHelp.cpp:42–122  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

40 }
41}
42bool PPLProcessCreator::CreatePPLProcess(DWORD protectionLevel, std::wstring& commandLine)
43{
44 SIZE_T size = 0;
45 STARTUPINFOEXW siex = { 0 };
46 siex.StartupInfo.cb = sizeof(siex);
47 PROCESS_INFORMATION pi = { 0 };
48 LPPROC_THREAD_ATTRIBUTE_LIST ptal = nullptr;
49
50 // Initialize attribute list size
51 if (!InitializeProcThreadAttributeList(nullptr, 1, 0, &size) && GetLastError() != ERROR_INSUFFICIENT_BUFFER)
52 {
53 std::wcerr << L"InitializeProcThreadAttributeList failed: " << GetLastError() << std::endl;
54 return false;
55 }
56
57 // Allocate attribute list
58 ptal = reinterpret_cast<LPPROC_THREAD_ATTRIBUTE_LIST>(HeapAlloc(GetProcessHeap(), 0, size));
59 if (!ptal)
60 {
61 std::wcerr << L"HeapAlloc failed: " << GetLastError() << std::endl;
62 return false;
63 }
64
65 // Initialize attribute list
66 if (!InitializeProcThreadAttributeList(ptal, 1, 0, &size))
67 {
68 std::wcerr << L"InitializeProcThreadAttributeList failed: " << GetLastError() << std::endl;
69 HeapFree(GetProcessHeap(), 0, ptal);
70 return false;
71 }
72
73 // Set protection level
74 //DWORD protectionLevel = PROTECTION_LEVEL_ANTIMALWARE_LIGHT;
75 if (!UpdateProcThreadAttribute(ptal, 0, PROC_THREAD_ATTRIBUTE_PROTECTION_LEVEL, &protectionLevel, sizeof(protectionLevel), nullptr, nullptr))
76 {
77 std::wcerr << L"UpdateProcThreadAttribute failed: " << GetLastError() << std::endl;
78 DeleteProcThreadAttributeList(ptal);
79 HeapFree(GetProcessHeap(), 0, ptal);
80 return false;
81 }
82 siex.lpAttributeList = ptal;
83
84 // Create process with PPL protection
85 if (!CreateProcessW(
86 nullptr, // Application name
87 (LPWSTR)commandLine.c_str(), // Command line
88 nullptr, // Process security attributes
89 nullptr, // Thread security attributes
90 TRUE, // Inherit handles
91 EXTENDED_STARTUPINFO_PRESENT | CREATE_PROTECTED_PROCESS,
92 nullptr, // Environment
93 nullptr, // Current directory
94 &siex.StartupInfo, // Startup info
95 &pi)) // Process information
96 {
97 std::wcerr << L"CreateProcessW failed: " << GetLastError() << std::endl;
98 DeleteProcThreadAttributeList(ptal);
99 HeapFree(GetProcessHeap(), 0, ptal);

Callers 1

DumpRunFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected