[英]Why does ctypes WriteProcessMemory() fail?
我一直在努力使此功能运行一段时间,但没有运气。
def write_memory(self, address, data):
PROCESS_ALL_ACCESS = 0x001F0FFF
count = c_ulong(0)
length = len(data)
c_data = c_char_p(data[count.value:])
null = c_int(0)
windll.kernel32.SetLastError(10000)
if not windll.kernel32.WriteProcessMemory(self.h_process, address, c_data, length, byref(count)):
print "Failed to write memory."
print "Error Code: ", windll.kernel32.GetLastError()
else:
return True
GetLastError()返回87(0x57),即ERROR_INVALID_PARAMETER。 对于此功能,我直接从Justin Seitz的Gray Hat Python复制了它。 不确定我在做什么错,ReadProcessMemory()可以很好地工作并返回适当的值。
对于地址,我现在选择一个随机位置0x00050000,并传递“ \\ x61”之类的数据来读取之前和之后的位置,而没有任何变化。
我感觉这是一个简单的错误,在此先感谢您的帮助。 导航
当您是对的时候,这是一件特权。 我似乎仍然找不到我要的东西。 这是我的启动过程代码:
class SECURITY_ATTRIBUTES(Structure):
_fields_ = [("Length", DWORD),
("SecDescriptor", LPVOID),
("InheritHandle", BOOL)]
def launch(self, path_to_exe):
CREATE_NEW_CONSOLE = 0x0000010
startupinfo = STARTUPINFO()
process_information = PROCESS_INFORMATION()
security_attributes = SECURITY_ATTRIBUTES()
startupinfo.dwFlags = 0x1
startupinfo.wShowWindow = 0x0
startupinfo.cb = sizeof(startupinfo)
security_attributes.Length = sizeof(security_attributes)
security_attributes.SecDescriptior = None
security_attributes.InheritHandle = True
if windll.kernel32.CreateProcessA(path_to_exe,
None,
byref(security_attributes),
byref(security_attributes),
True,
CREATE_NEW_CONSOLE,
None,
None,
byref(startupinfo),
byref(process_information)):
self.pid = process_information.dwProcessId
else:
print "Couldnt launch: %d" %path_to_exe
print windll.kernel32.GetLastError()
我是否需要以其他方式创建流程? 我应该在SecDescriptor结构中放入什么? MSDN对DACL和ACE并不是很有帮助吗? 感谢到目前为止的所有帮助。
PS-只是一个想法,调试器或其他程序如何不产生进程并能够更改内存?
电话显然没有错。 很可能在0x00050000上没有任何页面,或者这些页面不可写。
为什么不尝试对要写入的字节执行VirtualQuery
并查看其是否可写? 大多数随机地址不是。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.