Skip to content

Instantly share code, notes, and snippets.

@itsecurityco
Last active January 28, 2018 01:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itsecurityco/3296117a5cba35635c31f7281756e03c to your computer and use it in GitHub Desktop.
Save itsecurityco/3296117a5cba35635c31f7281756e03c to your computer and use it in GitHub Desktop.
This script takes a filename as argument and will produce the opcodes to push this string onto the stack
#!/usr/bin/env python
# Author: @itseco
# This script takes a filename as argument
# and will produce the opcodes
# to push this string onto the stack
# Original file: pvePushString.pl (www.corelan.be)
import sys
if len(sys.argv) < 2:
print " usage: %s \"String to put on stack\"" % sys.argv[0]
exit(0)
# Convert string to bytes
str_to_push = sys.argv[1]
str_this_hex = ""
byte_cnt = 0
str_hex = ""
str_opcodes = ""
str_push = ""
print "String lenght : %d" % len(str_to_push)
print "Opcodes to push this string onto the stack :\n"
for str_this_char in str_to_push:
str_this_hex = "\\x" + str_this_char.encode("hex")
if byte_cnt < 3:
str_hex += str_this_hex
byte_cnt += 1
else:
str_push = str_hex + str_this_hex
str_push = str_push.replace("\\x", "")
str_hex = '"\\x68%s" //PUSH 0x%s%s%s%s' % (str_hex + str_this_hex, str_push[6:8], str_push[4:6], str_push[2:4], str_push[0:2])
str_opcodes = str_hex + "\n" + str_opcodes
str_hex = ""
byte_cnt = 0
# Last line
if len(str_hex) > 0:
while len(str_hex) < 12:
str_hex += "\\x20"
str_push = str_hex
str_push = str_push.replace("\\x", "")
str_hex = '"\\x68%s\\x00" //PUSH 0x00%s%s%s' % (str_hex, str_push[4:6], str_push[2:4], str_push[0:2])
str_opcodes = str_hex + "\n" + str_opcodes
else:
# add line with spaces + null byte (string terminator)
str_opcodes = '"\\x68\\x20\\x20\\x20\\x20" //PUSH 0x00202020' + "\n" + str_opcodes
print str_opcodes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment