AttackingDirectory

Untitled

Aug 7th, 2023
806
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.50 KB | Source Code | 0 0
  1. #include <windows.h>
  2. #include <iostream>
  3.  
  4. BOOL CreateProcessWithBlockDllPolicy(IN LPSTR lpProcessPath, OUT DWORD* dwProcessId, OUT HANDLE* hProcess, OUT HANDLE* hThread) {
  5.  
  6.  
  7.     STARTUPINFOEXA        SiEx = { 0 };
  8.     PROCESS_INFORMATION   Pi = { 0 };
  9.     SIZE_T                sAttrSize = NULL;
  10.  
  11.     if (lpProcessPath == NULL)
  12.         return FALSE;
  13.     RtlSecureZeroMemory(&SiEx, sizeof(STARTUPINFOEXA));
  14.     RtlSecureZeroMemory(&Pi, sizeof(PROCESS_INFORMATION));
  15.  
  16.     SiEx.StartupInfo.cb = sizeof(STARTUPINFOEXA);
  17.     SiEx.StartupInfo.dwFlags = EXTENDED_STARTUPINFO_PRESENT;
  18.  
  19.  
  20.     InitializeProcThreadAttributeList(NULL, 1, NULL, &sAttrSize);
  21.     LPPROC_THREAD_ATTRIBUTE_LIST pAttrBuf = (LPPROC_THREAD_ATTRIBUTE_LIST)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sAttrSize);
  22.  
  23.     if (!InitializeProcThreadAttributeList(pAttrBuf, 1, NULL, &sAttrSize)) {
  24.         printf("[!] InitializeProcThreadAttributeList Failed With Error : %d \n", GetLastError());
  25.         return FALSE;
  26.     }
  27.  
  28.     DWORD64 dwPolicy = PROCESS_CREATION_MITIGATION_POLICY_BLOCK_NON_MICROSOFT_BINARIES_ALWAYS_ON;
  29.  
  30.     if (!UpdateProcThreadAttribute(pAttrBuf, NULL, PROC_THREAD_ATTRIBUTE_MITIGATION_POLICY, &dwPolicy, sizeof(DWORD64), NULL, NULL)) {
  31.         printf("[!] UpdateProcThreadAttribute Failed With Error : %d \n", GetLastError());
  32.         return FALSE;
  33.     }
  34.  
  35.     SiEx.lpAttributeList = (LPPROC_THREAD_ATTRIBUTE_LIST)pAttrBuf;
  36.  
  37.     if (!CreateProcessA(
  38.         NULL,
  39.         lpProcessPath,
  40.         NULL,
  41.         NULL,
  42.         FALSE,
  43.         EXTENDED_STARTUPINFO_PRESENT,
  44.         NULL,
  45.         NULL,
  46.         &SiEx.StartupInfo,
  47.         &Pi)) {
  48.         printf("[!] CreateProcessA Failed With Error : %d \n", GetLastError());
  49.         return FALSE;
  50.     }
  51.  
  52.  
  53.     *dwProcessId = Pi.dwProcessId;
  54.     *hProcess = Pi.hProcess;
  55.     *hThread = Pi.hThread;
  56.  
  57.     DeleteProcThreadAttributeList(pAttrBuf);
  58.     HeapFree(GetProcessHeap(), 0, pAttrBuf);
  59.  
  60.     if (*dwProcessId != NULL && *hProcess != NULL && *hThread != NULL)
  61.         return TRUE;
  62.     else
  63.         return FALSE;
  64. }
  65.  
  66. #define LOCAL_BLOCKDLLPOLICY
  67. #ifdef LOCAL_BLOCKDLLPOLICY
  68. #define STOP_ARG "MalDevAcad"
  69. #endif
  70.  
  71. int main(int argc, char* argv[]) {
  72.  
  73.     DWORD   dwProcessId = NULL;
  74.     HANDLE  hProcess = NULL,
  75.         hThread = NULL;
  76.  
  77. #ifdef LOCAL_BLOCKDLLPOLICY
  78.     if (argc == 2 && (strcmp(argv[1], STOP_ARG) == 0)) {
  79.     /*
  80.         СЮДА РЕАЛЬНЫЙ КОД, ТИП КОТОРЫЙ ДОЛЖЕН БУДЕТ ЗАПУСТИТЬСЯ ПРИ ВКЛЮЧЕННОЙ BLOCK DLL PROCESS
  81.     */
  82.     printf("[+] Process Is Now Protected With The Block Dll Policy \n");
  83.  
  84.     WaitForSingleObject((HANDLE)-1, INFINITE);
  85.     }
  86.     else {
  87.  
  88.         printf("[!] Local Process Is Not Protected With The Block Dll Policy \n");
  89.         CHAR pcFilename[MAX_PATH * 2];
  90.         if (!GetModuleFileNameA(NULL, (LPSTR) & pcFilename, MAX_PATH * 2)) {
  91.             printf("[!] GetModuleFileNameA Failed With Error : %d \n", GetLastError());
  92.             return -1;
  93.         }
  94.  
  95.         DWORD dwBufferSize = (DWORD)(lstrlenA(pcFilename) + lstrlenA(STOP_ARG) + 0xFF);
  96.         CHAR* pcBuffer = (CHAR*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwBufferSize);
  97.         if (!pcBuffer)
  98.             return FALSE;
  99.  
  100.         sprintf_s(pcBuffer, dwBufferSize, "%s %s", pcFilename, STOP_ARG);
  101.         if (!CreateProcessWithBlockDllPolicy(pcBuffer, &dwProcessId, &hProcess, &hThread)) {
  102.             return -1;
  103.         }
  104.  
  105.         HeapFree(GetProcessHeap(), 0, pcBuffer);
  106.  
  107.         printf("[i] Process Created With Pid %d \n", dwProcessId);
  108.  
  109.  
  110.         }
  111. #endif
  112. #ifndef LOCAL_BLOCKDLLPOLICY
  113.         if (!CreateProcessWithBlockDllPolicy((LPSTR)"C:\\Windows\\System32\\RuntimeBroker.exe", &dwProcessId, &hProcess, &hThread)) {
  114.             return -1;
  115.         }
  116.         printf("[i] Process Created With Pid %d \n", dwProcessId);
  117.  
  118. #endif /
  119.         return 0;
  120.  
  121. }
Advertisement
Add Comment
Please, Sign In to add comment