|
|
|
|
@ -5,6 +5,7 @@ import tests
|
|
|
|
|
|
|
|
|
|
MPROTECT_BINARY = tests.binaries.get("mprotect.out")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_mprotect(start_binary):
|
|
|
|
|
"""
|
|
|
|
|
Tests mprotect command
|
|
|
|
|
@ -16,16 +17,20 @@ def test_mprotect(start_binary):
|
|
|
|
|
# get addr of func
|
|
|
|
|
addr = int(gdb.parse_and_eval("&func"))
|
|
|
|
|
addr_aligned = pwndbg.lib.memory.page_align(addr)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# sizeof
|
|
|
|
|
size = int(gdb.parse_and_eval("sizeof(func)"))
|
|
|
|
|
size_aligned = pwndbg.lib.memory.page_align(size)
|
|
|
|
|
|
|
|
|
|
vmmaps_before = gdb.execute("vmmap -x", to_string=True).splitlines()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# mark memory as executable
|
|
|
|
|
gdb.execute("mprotect {} {} PROT_EXEC|PROT_READ|PROT_WRITE".format(hex(addr_aligned), pwndbg.lib.memory.PAGE_SIZE))
|
|
|
|
|
|
|
|
|
|
gdb.execute(
|
|
|
|
|
"mprotect {} {} PROT_EXEC|PROT_READ|PROT_WRITE".format(
|
|
|
|
|
hex(addr_aligned), pwndbg.lib.memory.PAGE_SIZE
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
vmmaps_after = gdb.execute("vmmap -x", to_string=True).splitlines()
|
|
|
|
|
|
|
|
|
|
# expect vmmaps_after to be one element longer than vmmaps_before
|
|
|
|
|
@ -35,14 +40,14 @@ def test_mprotect(start_binary):
|
|
|
|
|
vmmap_entry = [x for x in vmmaps_after if x not in vmmaps_before][0]
|
|
|
|
|
|
|
|
|
|
assert vmmap_entry.split()[2] == "rwxp"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# continue execution
|
|
|
|
|
gdb.execute("continue")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_cannot_run_mprotect_when_not_running(start_binary):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# expect error message
|
|
|
|
|
assert "mprotect: The program is not being run.\n" == gdb.execute("mprotect 0x0 0x1000 PROT_EXEC|PROT_READ|PROT_WRITE", to_string=True)
|
|
|
|
|
assert "mprotect: The program is not being run.\n" == gdb.execute(
|
|
|
|
|
"mprotect 0x0 0x1000 PROT_EXEC|PROT_READ|PROT_WRITE", to_string=True
|
|
|
|
|
)
|
|
|
|
|
|