CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/external/source/exploits/CVE-2016-4669/macho_to_bin.py
Views: 11778
1
import sys
2
import base64
3
4
fd = open(sys.argv[1], 'rb')
5
macho = fd.read()
6
fd.close()
7
8
magic_start = "\x4F\xF0\x00\x00"*4
9
magic_end = "\x4F\xF0\x01\x00"*4
10
11
start = macho.find(magic_start) + len(magic_start) + 2
12
end = macho.find(magic_end)
13
end = (end & 0xfff0) + 0x10
14
15
print("real len: 0x%x" % (end - start))
16
17
blob = macho[start:start+0x400]
18
print("code start: 0x%x" % start)
19
print("code end: 0x%x" % end)
20
21
fd = open(sys.argv[1] + ".b64", "wb+")
22
fd.write(base64.b64encode(blob))
23
fd.close()
24
25
fd = open(sys.argv[1] + ".bin", "wb+")
26
fd.write(blob)
27
fd.close()
28
29