diff --git a/.gitignore b/.gitignore index 5cf5a46..26fa6f2 100644 --- a/.gitignore +++ b/.gitignore @@ -137,4 +137,5 @@ dmypy.json # binaries vuln-32 -core \ No newline at end of file +core +out \ No newline at end of file diff --git a/ROPgadget/ropgadget/__init__.py b/ROPgadget/ropgadget/__init__.py index 2201b59..c533e3f 100644 --- a/ROPgadget/ropgadget/__init__.py +++ b/ROPgadget/ropgadget/__init__.py @@ -17,12 +17,12 @@ import ropgadget.version import ropgadget.loaders import ropgadget.ropchain -def main(): +def main(arguments=None): import sys from ropgadget.args import Args from ropgadget.core import Core try: - args = Args() + args = Args(arguments) except ValueError as e: print(e) sys.exit(-1) diff --git a/ROPgadget/ropgadget/args.py b/ROPgadget/ropgadget/args.py index 1bb53b0..b46f1e0 100644 --- a/ROPgadget/ropgadget/args.py +++ b/ROPgadget/ropgadget/args.py @@ -84,6 +84,7 @@ architectures supported: parser.add_argument("--rawEndian", type=str, metavar="", help="Specify an endianness for a raw file") 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("--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 6cebb95..f6f93d6 100644 --- a/ROPgadget/ropgadget/core.py +++ b/ROPgadget/ropgadget/core.py @@ -215,7 +215,7 @@ class Core(cmd.Cmd): self.__getGadgets() self.__lookingForGadgets() if self.__options.ropchain: - ROPMaker(self.__binary, self.__gadgets, self.__offset) + ROPMaker(self.__binary, self.__gadgets, self.__options.paddingLen, self.__offset) return True diff --git a/ROPgadget/ropgadget/ropchain/arch/ropmakerx64.py b/ROPgadget/ropgadget/ropchain/arch/ropmakerx64.py index 8369d0c..4bc1977 100644 --- a/ROPgadget/ropgadget/ropchain/arch/ropmakerx64.py +++ b/ROPgadget/ropgadget/ropchain/arch/ropmakerx64.py @@ -14,9 +14,10 @@ from capstone import * class ROPMakerX64(object): - def __init__(self, binary, gadgets, liboffset=0x0): - self.__binary = binary - self.__gadgets = gadgets + def __init__(self, binary, gadgets, paddingLen, liboffset=0x0): + self.__binary = binary + self.__gadgets = gadgets + self.paddingLen = paddingLen # If it's a library, we have the option to add an offset to the addresses self.__liboffset = liboffset @@ -40,7 +41,7 @@ class ROPMakerX64(object): if g != "ret": if g.split()[0] == "ret" and g.split()[1] != "": raise - print("\t[+] Gadget found: 0x%x %s" %(gadget["vaddr"], gadget["gadget"])) + print("# [+] Gadget found: 0x%x %s" %(gadget["vaddr"], gadget["gadget"])) return [gadget, regex.group("dst"), regex.group("src")] except: continue @@ -58,7 +59,7 @@ class ROPMakerX64(object): # we need this to filterout 'ret' instructions with an offset like 'ret 0x6', because they ruin the stack pointer if g.split()[0] == "ret" and g.split()[1] != "": raise - print("\t[+] Gadget found: 0x%x %s" %(gadget["vaddr"], gadget["gadget"])) + print("# [+] Gadget found: 0x%x %s" %(gadget["vaddr"], gadget["gadget"])) return gadget except: continue @@ -70,9 +71,9 @@ class ROPMakerX64(object): if g.split()[0] == "pop": reg = g.split()[1] try: - print("\tp += pack('