forked from ahhh/Injectors
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpyPE_mutation.py
69 lines (59 loc) · 1.33 KB
/
pyPE_mutation.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
#http://breakinsecurity.com/pe-format-manipulation-with-pefile/
#32 and 64bit support
import pefile
import string
import random
import os
import mmap
def cleanterminal():
'''
Clean the terminal window and set title
'''
os.system("cls" if os.name == "nt" else "clear")
os.system("title pyPE_mutator")
def banner():
print ">> Obfuscating PE sections"
def uniqestr(length):
'''
Create a random string
'''
return ''.join(random.choice(string.lowercase) for i in range(length))
def modify():
'''
Path to executables
'''
input = "PsExec.exe"
output = uniqestr(10)+".exe"
'''
Load executable
'''
originalpe = pefile.PE(input)
'''
Parse unmodified sections and replace
the name with random strings
'''
print "\n[!] Original pe section names"
for section in originalpe.sections:
print "\t[+] "+section.Name.decode('utf-8')
section.Name = "."+uniqestr(4).encode()
'''
Write the changes in another executable
'''
originalpe.write(output)
'''
Load new executable
'''
modifiedpe = pefile.PE(output)
print "\n[!] Modifying pe sections names"
'''
Parse modified section names
'''
for section in modifiedpe.sections:
print "\t[+] "+section.Name.decode('utf-8')
if __name__ == '__main__':
'''
Run all the functions
'''
cleanterminal()
banner()
modify()