Skip to content

Instantly share code, notes, and snippets.

@Fitblip
Last active May 26, 2018 06:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fitblip/5218816 to your computer and use it in GitHub Desktop.
Save Fitblip/5218816 to your computer and use it in GitHub Desktop.
Clone of Corelan's PVEString stack tool. Written because perl sucks, and I'm not going to install that garbage on my computer to do one thing.
import sys
string = sys.argv[-1]
lines = []
print "String length : %d" % len(string)
print "Opcodes to push this string onto the stack :"
for i in range(0,len(string),4):
line = string[:4]
if len(string) == 4:
a = "\"\\x68\\x20\\x20\\x20\\x00\""
a += " # PUSH 0x00202020"
a += " ; ( )"
print a
if len(line) == 4:
a = "\"\\x68"
a += "".join(['\\x' + hex(ord(x)).replace('0x','') for x in line]) + "\""
a += " # PUSH 0x" + "".join([hex(ord(x)).replace('0x','') for x in line[::-1]])
a += " ; (" + "".join([x for x in line]) + ")"
lines.append(a)
string = string[4:]
if len(line) == 3:
a = "\"\\x68"
a += "".join(['\\x' + hex(ord(x)).replace('0x','') for x in line])
a += "\\x00"
a += " # PUSH 0x00" + "".join([hex(ord(x)).replace('0x','') for x in line[::-1]])
a += "\""
a += " ; (" + "".join([x for x in line]) + " )"
lines.append(a)
if len(line) == 2:
a = "\"\\x68"
a += "".join(['\\x' + hex(ord(x)).replace('0x','') for x in line])
a += "\\x20"
a += "\\x00"
a += "\""
a += " # PUSH 0x0020" + "".join([hex(ord(x)).replace('0x','') for x in line[::-1]])
a += " ; (" + "".join([x for x in line]) + " )"
lines.append(a)
if len(line) == 1:
a = "\"\\x68"
a += "".join(['\\x' + hex(ord(x)).replace('0x','') for x in line])
a += "\\x20" * 2
a += "\\x00"
a += "\""
a += " # PUSH 0x002020" + "".join([hex(ord(x)).replace('0x','') for x in line[::-1]])
a += " ; (" + "".join([x for x in line]) + " )"
lines.append(a)
for line in lines[::-1]:
print line
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment