简体   繁体   English

如何在外部运行进程中更改 PEB 的命令行

[英]How to change the CommandLine of the PEB in an external running process

Basically I would like to be able to change the PEB of commandline, which I believe is at offset 0x70 .基本上我希望能够更改命令行的 PEB,我相信它位于偏移量0x70处。 I am trying to do this using WriteProcessMemory which is part of Kernel32.dll .我正在尝试使用WriteProcessMemory来执行此操作,它是Kernel32.dll的一部分。

Current_ImageBase.buffer = pNewAddr;
if (!WriteProcessMemory(hProcess, rtlUserProcParamsAddress + 0x70, (IntPtr)(&Current_ImageBase), Marshal.SizeOf(typeof(UNICODE_STRING)), out intPtrOutput))
{
    Console.WriteLine("ERROR: Failed to reflect change back to PEB.\n");
    return false;
}

This should change the CommandLine of PEB.这应该会改变 PEB 的命令行。

There is no guarantee that the PEB will be identical on every version of Windows.无法保证每个版本的 Windows 上的PEB都是相同的。

The PEB contains a pointer to a _RTL_USER_PROCESS_PARAMETERS structure named ProcessParameters. PEB包含一个指向名为 ProcessParameters 的_RTL_USER_PROCESS_PARAMETERS结构的指针。

This structure contains a UNICODE_STRING named CommandLine .此结构包含一个名为CommandLineUNICODE_STRING Inside this structure is a pointer to a buffer which contains the command line arguments.在这个结构内部是一个指向缓冲区的指针,该缓冲区包含命令行 arguments。

To externally overwrite these arguments, you must:要从外部覆盖这些 arguments,您必须:

  1. Call NTQueryProcessInformation to get the ProcessBasicInformation and therefore the PEB address调用NTQueryProcessInformation以获取 ProcessBasicInformation 和 PEB 地址

  2. OpenProcess and get write permissions OpenProcess并获得写权限

  3. ReadProcessMemory the PEB ReadProcessMemory PEB

  4. ReadProcessMemory PEB.ProcessParameters ReadProcessMemory PEB.ProcessParameters

  5. ReadProcessMemory PEB.ProcessParameters.CommandLine ReadProcessMemory PEB.ProcessParameters.CommandLine

  6. WriteProcessMemory PEB.ProcessParameters.CommandLine.Buffer with the correct size pulled from the UNICODE_STRING.Length从 UNICODE_STRING.Length 中提取正确大小的WriteProcessMemory PEB.ProcessParameters.CommandLine.Buffer

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM