Created
July 13, 2015 09:14
-
-
Save duanckham/0b9ec0f55b6593cdffb5 to your computer and use it in GitHub Desktop.
objdump-to-shellcode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from subprocess import Popen, PIPE | |
import sys | |
def shellcode_from_objdump(obj): | |
res = '' | |
p = Popen(['objdump', '-d', obj], stdout=PIPE, stderr=PIPE) | |
(stdoutdata, stderrdata) = p.communicate() | |
if p.returncode == 0: | |
for line in stdoutdata.splitlines(): | |
cols = line.split('\t') | |
if len(cols) > 2: | |
for b in [b for b in cols[1].split(' ') if b != '']: | |
res = res + ('\\x%s' % b) | |
else: | |
raise ValueError(stderrdata) | |
return res | |
if __name__ == '__main__': | |
if len(sys.argv) < 2: | |
print 'Usage: %s <obj_file>' % sys.argv[0] | |
sys.exit(2) | |
else: | |
print 'Shellcode for %s:' % sys.argv[1] | |
print shellcode_from_objdump(sys.argv[1]) | |
sys.exit(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment