Skip to content

Instantly share code, notes, and snippets.

@retornam
Forked from offlinemark/pushgen.py
Created September 22, 2022 19:51
Show Gist options
  • Save retornam/bf32b1fe7edc6c6df2b87aa9ead62b79 to your computer and use it in GitHub Desktop.
Save retornam/bf32b1fe7edc6c6df2b87aa9ead62b79 to your computer and use it in GitHub Desktop.
Shellcode helper. Given a string, generate push instructions to push string onto stack.
#!/usr/bin/env python
'''
Tool for writing shellcode. Give it a string to push onto the stack and it
generates the corresponding push instructions.
'''
import sys
def print_word(word):
print 'push', '0x' + word[::-1].encode('hex')
if len(sys.argv) != 2:
print 'usage: <program> text'
sys.exit()
if len(sys.argv[1]) % 4 != 0:
print 'text must be multiple of 4. pad your slashes or something.'
sys.exit()
chunks = map(lambda x: sys.argv[1][x:x+4], range(0, len(sys.argv[1]), 4))[::-1]
map(print_word, chunks)
@retornam
Copy link
Author

import binascii
def stack_str(s):
    rev = s[::-1]
    return binascii.hexlify(rev)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment