Skip to content

Instantly share code, notes, and snippets.

@deqline
Last active April 2, 2021 11:42
Show Gist options
  • Save deqline/d3db374bdda0477edabf8aa814fddd24 to your computer and use it in GitHub Desktop.
Save deqline/d3db374bdda0477edabf8aa814fddd24 to your computer and use it in GitHub Desktop.
Generates shellcode from a masm compiled file. Instructions in file comments!.
# Create a shellcode.ASM file
# the shellcode shall reside in the text segment
# compile it using ml64 /c shellcode.ASM
# run this file
f = open("shellcode.obj", "rb")
stream = f.read()
SizeOfFileHeader = 0x14
SizeOfBuffer = int.from_bytes(stream[SizeOfFileHeader+0x10:SizeOfFileHeader+0x14], "little") #SizeOfRaw Text segment
PtrToRaw = int.from_bytes(stream[SizeOfFileHeader+0x14:SizeOfFileHeader+0x18], "little") #File offset of text segment
TextBuffer = stream[PtrToRaw:PtrToRaw+SizeOfBuffer]
print("Writing:",TextBuffer)
f.close()
f1 = open("shellcode.bin", "wb")
f1.write(TextBuffer)
f1.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment