Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.

Commit

Permalink
Run ROPgadget with subprocess.Popen
Browse files Browse the repository at this point in the history
  • Loading branch information
nurmukhametov committed Feb 8, 2020
1 parent 8092a28 commit 008297b
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions Exrop.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,28 @@
import code

def parseRopGadget(filename, opt=""):
cmd = 'ROPgadget {} --binary {} --multibr --only "pop|xchg|add|sub|xor|mov|ret|jmp|call|syscall|leave" --dump | tail -n +3 | head -n -2'.format(opt, filename)
with popen(cmd) as fp:
sample_gadgets = dict()
datas = fp.read().strip().split("\n")
datas.sort(key=len) # sort by length
for data in datas:
addr,insns = data.split(" : ")
insstr,opcode_hex = insns.split(" // ")
opcode = bytes.fromhex(opcode_hex)
addr = int(addr, 16)
from subprocess import Popen, PIPE, STDOUT
import re

cmd = ['ROPgadget', '--binary', filename, '--multibr', '--only',
'pop|xchg|add|sub|xor|mov|ret|jmp|call|syscall|leave', '--dump']
if opt:
cmd.append(opt)
process = Popen(cmd, stdout=PIPE, stderr=STDOUT)
stdout, _ = process.communicate()
output_lines = stdout.splitlines()
output_lines.sort(key=len)

sample_gadgets = dict()
regexp = re.compile(b"(0x.*) : (.*) // (.*)")
for line in output_lines:
match = regexp.match(line)
if match:
addr = int(match.group(1).decode(), 16)
insstr = match.group(2).decode()
opcode = bytes.fromhex(match.group(3).decode())
sample_gadgets[addr] = (insstr,opcode)
return sample_gadgets
return sample_gadgets

class Exrop(object):
def __init__(self, binary):
Expand Down

0 comments on commit 008297b

Please sign in to comment.