Advertisement
Guest User

Untitled

a guest
Mar 26th, 2018
331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.28 KB | None | 0 0
  1. #include <windows.h>
  2.  
  3. #include <iostream>
  4.  
  5. int main ()
  6. {
  7.     HMODULE hAdvAPIDLL = LoadLibraryW (L"advapi32legacy.dll");
  8.     // Should FreeLibrary later
  9.  
  10.     if (hAdvAPIDLL == 0) {
  11.         std::cout << "LoadLibraryW failed with code " << std::hex << GetLastError () << std::endl;
  12.  
  13.         return -1;
  14.     }
  15.  
  16.     std::cout << "Got handle to advapi32legacy.dll (loaded @ address 0x" << std::hex << hAdvAPIDLL << ")" << std::endl;
  17.  
  18.     using FnCreateProcessWithLogonW = BOOL (*) (LPCWSTR,
  19.                                                 LPCWSTR,
  20.                                                 LPCWSTR,
  21.                                                 DWORD,
  22.                                                 LPCWSTR,
  23.                                                 LPWSTR,
  24.                                                 DWORD,
  25.                                                 LPVOID,
  26.                                                 LPCWSTR,
  27.                                                 LPSTARTUPINFOW,
  28.                                                 LPPROCESS_INFORMATION);
  29.  
  30.     FnCreateProcessWithLogonW pCreateProcessWithLogonW =
  31.         reinterpret_cast<FnCreateProcessWithLogonW> (GetProcAddress (hAdvAPIDLL, "CreateProcessWithLogonW"));
  32.     if (pCreateProcessWithLogonW == nullptr) {
  33.         std::cout << "Unable to locate \"CreateProcessWithLogonW\" in advapi32legacy.dll, errorcode:" << std::hex <<
  34.             GetLastError () << std::endl;
  35.  
  36.         return -1;
  37.     }
  38.  
  39.     std::cout << "Located \"CreateProcessWithLogonW\" in advapi32legacy.dll @ " << std::hex << pCreateProcessWithLogonW << std::endl;
  40.  
  41.     STARTUPINFOW si = {};
  42.     si.cb = sizeof si;
  43.     PROCESS_INFORMATION pi = {};
  44.     BOOL success = pCreateProcessWithLogonW (L"Administrator",
  45.                                             nullptr,
  46.                                             L"yourpasswordgoeshere",
  47.                                             0,
  48.                                             L"devcon.exe",
  49.                                             LR"(dp_add "c:\Data\Users\DefaultAccount\net7800-arm-n650f.inf")", // meh
  50.                                             0,
  51.                                             nullptr,
  52.                                             nullptr,
  53.                                             &si,
  54.                                             &pi);
  55.  
  56.     // Should CloseHandle on pi.hProcess and pi.hThread later
  57.  
  58.     if (success != FALSE) {
  59.         std::cout << "Successfully created process!" << std::endl;
  60.  
  61.         std::cout << "Waiting for process..." << std::endl;
  62.  
  63.         switch (WaitForSingleObject (pi.hProcess, INFINITE)) {
  64.             case WAIT_OBJECT_0: {
  65.                 DWORD exitCode;
  66.                 if (GetExitCodeProcess (pi.hProcess, &exitCode) != FALSE)
  67.                     std::cout << "Process exited with code 0x" << std::hex << exitCode << std::endl;
  68.                 else
  69.                     std::cout << "Process exited with unknown exit code!" << std::endl;
  70.  
  71.                 break;
  72.             }
  73.             default:
  74.                 std::cout << "Unexpected value returned from WaitForSingleObject!" << std::endl;
  75.         }
  76.     } else {
  77.         std::cout << "Failed to create process! Errorcode: " << std::hex << "0x" << GetLastError () << std::endl;
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement