Port checksec command (#2087)

* use checksec from pwnlib

* formatting changes

* another formatting change ;/
pull/2129/head
Divyansh Singh 2 years ago committed by GitHub
parent da94871adb
commit b87e2a8cdb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -1,10 +1,18 @@
from __future__ import annotations
import argparse
import pwndbg.color
import pwndbg.commands
import pwndbg.gdblib.file
import pwndbg.wrappers.checksec
parser = argparse.ArgumentParser(
description="Prints out the binary security settings using `checksec`."
)
parser.add_argument("-f", "--file", type=str, help="Specify the file to run `checksec` on.")
def color_line(line: str) -> str:
return pwndbg.color.normal(
@ -18,8 +26,9 @@ def color_lines(output: str) -> str:
return "\n".join(map(color_line, output.split("\n")))
@pwndbg.commands.ArgparsedCommand("Prints out the binary security settings using `checksec`.")
@pwndbg.commands.ArgparsedCommand(parser, command_name="checksec")
@pwndbg.commands.OnlyWithFile
def checksec() -> None:
output = pwndbg.wrappers.checksec.get_raw_out(pwndbg.gdblib.file.get_proc_exe_file())
def checksec(file: str) -> None:
local_path = file or pwndbg.gdblib.file.get_proc_exe_file()
output = pwndbg.wrappers.checksec.get_raw_out(local_path)
print(color_lines(output))

@ -1,30 +1,16 @@
from __future__ import annotations
from subprocess import CalledProcessError
from pwnlib.elf import ELF
import pwndbg.commands
import pwndbg.lib.cache
import pwndbg.wrappers
cmd_name = "checksec"
cmd_pwntools = ["pwn", "checksec"]
def get_raw_out(local_path: str) -> str:
elf = ELF(local_path)
output = f"File: {elf.path}\n"
output += f"Arch: {elf.arch}\n"
output += elf.checksec()
return output
@pwndbg.wrappers.OnlyWithCommand(cmd_name, cmd_pwntools)
@pwndbg.lib.cache.cache_until("objfile")
def get_raw_out(local_path: str) -> str:
try:
return pwndbg.wrappers.call_cmd(get_raw_out.cmd + ["--file=" + local_path])
except CalledProcessError:
pass
try:
return pwndbg.wrappers.call_cmd(get_raw_out.cmd + ["--file", local_path])
except CalledProcessError:
pass
return pwndbg.wrappers.call_cmd(get_raw_out.cmd + [local_path])
@pwndbg.wrappers.OnlyWithCommand(cmd_name, cmd_pwntools)
def relro_status(local_path: str) -> str:
relro = "No RELRO"
out = get_raw_out(local_path)
@ -37,7 +23,6 @@ def relro_status(local_path: str) -> str:
return relro
@pwndbg.wrappers.OnlyWithCommand(cmd_name, cmd_pwntools)
def pie_status(local_path: str) -> str:
pie = "No PIE"
out = get_raw_out(local_path)

Loading…
Cancel
Save