mirror of
https://github.com/whokilleddb/lordran.polymorphic.shellcode
synced 2026-06-06 16:59:23 +00:00
69 lines
1.7 KiB
Python
69 lines
1.7 KiB
Python
import sys
|
|
import ctypes
|
|
from ctypes import wintypes
|
|
import argparse
|
|
|
|
def test_shellcode(shellcode_file):
|
|
"""
|
|
Test shellcode in a controlled environment.
|
|
For security research purposes only.
|
|
"""
|
|
# Read shellcode from file
|
|
try:
|
|
with open(shellcode_file, 'rb') as f:
|
|
shellcode = f.read()
|
|
except Exception as e:
|
|
print(f"Error reading shellcode file: {e}")
|
|
return False
|
|
|
|
# Print shellcode length for verification
|
|
print(f"Shellcode size: {len(shellcode)} bytes")
|
|
|
|
# Allocate memory with RWX permissions
|
|
rwx = 0x40 # PAGE_EXECUTE_READWRITE
|
|
ctypes.windll.kernel32.VirtualAlloc.restype = ctypes.c_void_p
|
|
ptr = ctypes.windll.kernel32.VirtualAlloc(
|
|
None,
|
|
len(shellcode),
|
|
0x1000, # MEM_COMMIT
|
|
rwx
|
|
)
|
|
|
|
if not ptr:
|
|
print("Memory allocation failed")
|
|
return False
|
|
|
|
# Copy shellcode to allocated memory
|
|
buffer = (ctypes.c_char * len(shellcode)).from_buffer_copy(shellcode)
|
|
ctypes.memmove(ptr, buffer, len(shellcode))
|
|
|
|
# Create function pointer
|
|
function = ctypes.cast(ptr, ctypes.CFUNCTYPE(None))
|
|
|
|
print("Executing shellcode...")
|
|
|
|
# Execute
|
|
function()
|
|
|
|
# Clean up
|
|
ctypes.windll.kernel32.VirtualFree(
|
|
ctypes.c_void_p(ptr),
|
|
0,
|
|
0x8000 # MEM_RELEASE
|
|
)
|
|
|
|
return True
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description='Shellcode testing harness for security research')
|
|
parser.add_argument('shellcode_file', help='Path to the shellcode binary file')
|
|
args = parser.parse_args()
|
|
|
|
if test_shellcode(args.shellcode_file):
|
|
print("Shellcode execution completed")
|
|
else:
|
|
print("Shellcode execution failed")
|
|
|
|
if __name__ == '__main__':
|
|
main()
|