fix: lint

This commit is contained in:
Albert Koczy 2022-09-24 04:11:20 +02:00 committed by Disconnect3d
parent 9e84c18c44
commit 30cd4c7372
3 changed files with 20 additions and 13 deletions

View File

@ -1,5 +1,9 @@
import argparse import argparse
import gdb import gdb
import pwnlib
from pwnlib import asm
import pwndbg.chain import pwndbg.chain
import pwndbg.commands import pwndbg.commands
import pwndbg.enhance import pwndbg.enhance
@ -7,8 +11,6 @@ import pwndbg.file
import pwndbg.lib.which import pwndbg.lib.which
import pwndbg.wrappers.checksec import pwndbg.wrappers.checksec
import pwndbg.wrappers.readelf import pwndbg.wrappers.readelf
import pwnlib
from pwnlib import asm
parser = argparse.ArgumentParser(description="Calls mprotect. x86_64 only.") parser = argparse.ArgumentParser(description="Calls mprotect. x86_64 only.")
parser.add_argument("addr", help="Page-aligned address to all mprotect on.", type=int) parser.add_argument("addr", help="Page-aligned address to all mprotect on.", type=int)
@ -51,7 +53,6 @@ def mprotect(addr, length, prot):
saved_rdx = pwndbg.gdblib.regs.rdx saved_rdx = pwndbg.gdblib.regs.rdx
saved_rip = pwndbg.gdblib.regs.rip saved_rip = pwndbg.gdblib.regs.rip
prot_int = prot_str_to_val(prot) prot_int = prot_str_to_val(prot)
shellcode_asm = pwnlib.shellcraft.syscall("SYS_mprotect", int(addr), int(length), int(prot_int)) shellcode_asm = pwnlib.shellcraft.syscall("SYS_mprotect", int(addr), int(length), int(prot_int))
@ -60,7 +61,7 @@ def mprotect(addr, length, prot):
saved_instruction_bytes = pwndbg.gdblib.memory.read(pwndbg.gdblib.regs.rip, len(shellcode)) saved_instruction_bytes = pwndbg.gdblib.memory.read(pwndbg.gdblib.regs.rip, len(shellcode))
pwndbg.gdblib.memory.write(pwndbg.gdblib.regs.rip, shellcode) pwndbg.gdblib.memory.write(pwndbg.gdblib.regs.rip, shellcode)
# execute syscall # execute syscall
gdb.execute("nextsyscall") gdb.execute("nextsyscall")
gdb.execute("stepi") gdb.execute("stepi")

View File

@ -1,9 +1,10 @@
import gdb import gdb
import pwnlib
import pwndbg.proc import pwndbg.proc
from pwndbg.gdblib import typeinfo from pwndbg.gdblib import typeinfo
from pwndbg.lib.arch import Arch from pwndbg.lib.arch import Arch
import pwnlib
# TODO: x86-64 needs to come before i386 in the current implementation, make # TODO: x86-64 needs to come before i386 in the current implementation, make
# this order-independent # this order-independent
ARCHS = ("x86-64", "i386", "aarch64", "mips", "powerpc", "sparc", "arm") ARCHS = ("x86-64", "i386", "aarch64", "mips", "powerpc", "sparc", "arm")

View File

@ -5,6 +5,7 @@ import tests
MPROTECT_BINARY = tests.binaries.get("mprotect.out") MPROTECT_BINARY = tests.binaries.get("mprotect.out")
def test_mprotect(start_binary): def test_mprotect(start_binary):
""" """
Tests mprotect command Tests mprotect command
@ -16,16 +17,20 @@ def test_mprotect(start_binary):
# get addr of func # get addr of func
addr = int(gdb.parse_and_eval("&func")) addr = int(gdb.parse_and_eval("&func"))
addr_aligned = pwndbg.lib.memory.page_align(addr) addr_aligned = pwndbg.lib.memory.page_align(addr)
# sizeof # sizeof
size = int(gdb.parse_and_eval("sizeof(func)")) size = int(gdb.parse_and_eval("sizeof(func)"))
size_aligned = pwndbg.lib.memory.page_align(size) size_aligned = pwndbg.lib.memory.page_align(size)
vmmaps_before = gdb.execute("vmmap -x", to_string=True).splitlines() vmmaps_before = gdb.execute("vmmap -x", to_string=True).splitlines()
# mark memory as executable # 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() vmmaps_after = gdb.execute("vmmap -x", to_string=True).splitlines()
# expect vmmaps_after to be one element longer than vmmaps_before # 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] vmmap_entry = [x for x in vmmaps_after if x not in vmmaps_before][0]
assert vmmap_entry.split()[2] == "rwxp" assert vmmap_entry.split()[2] == "rwxp"
# continue execution # continue execution
gdb.execute("continue") gdb.execute("continue")
def test_cannot_run_mprotect_when_not_running(start_binary): def test_cannot_run_mprotect_when_not_running(start_binary):
# expect error message # 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
)