mirror of https://github.com/pwndbg/pwndbg.git
Add parse-seccomp command to resolve bpf filter using ceccomp or seccomp-tools (#3310)
* Add parse-seccomp command using ceccomp or seccomp-tools * Fix Typo * generate doc for parse-seccomp command * remove redundant variable * move parse-seccomp from Commands.Misc to Commands.Linux * Shouldn't use partial read, so set partial to be falsepull/3314/head
parent
2ea5e383bf
commit
962e11ef8a
@ -0,0 +1,23 @@
|
||||
<!-- THIS PART OF THIS FILE IS AUTOGENERATED. DO NOT MODIFY IT. See scripts/generate-docs.sh -->
|
||||
# parse-seccomp
|
||||
|
||||
```text
|
||||
usage: parse-seccomp [-h] addr
|
||||
|
||||
```
|
||||
|
||||
Parse a struct sock_fprog from memory and dump its filter
|
||||
### Positional arguments
|
||||
|
||||
|Positional Argument|Help|
|
||||
| :--- | :--- |
|
||||
|addr|Address of sock_fprog structure in target process memory (e.g. 0xdeadbeef)|
|
||||
|
||||
### Optional arguments
|
||||
|
||||
|Short|Long|Help|
|
||||
| :--- | :--- | :--- |
|
||||
|-h|--help|show this help message and exit|
|
||||
|
||||
<!-- END OF AUTOGENERATED PART. Do not modify this line or the line below, they mark the end of the auto-generated part of the file. If you want to extend the documentation in a way which cannot easily be done by adding to the command help description, write below the following line. -->
|
||||
<!-- ------------\>8---- ----\>8---- ----\>8------------ -->
|
||||
@ -0,0 +1,50 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import shutil
|
||||
import subprocess
|
||||
|
||||
import pwndbg.aglib.memory
|
||||
import pwndbg.aglib.typeinfo
|
||||
import pwndbg.commands
|
||||
from pwndbg.color import message
|
||||
from pwndbg.commands import CommandCategory
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Parse a struct sock_fprog from memory and dump its filter"
|
||||
)
|
||||
parser.add_argument(
|
||||
"addr",
|
||||
type=int,
|
||||
help="Address of sock_fprog structure in target process memory (e.g. 0xdeadbeef)",
|
||||
)
|
||||
|
||||
|
||||
@pwndbg.commands.Command(parser, command_name="parse-seccomp", category=CommandCategory.LINUX)
|
||||
@pwndbg.commands.OnlyWhenRunning
|
||||
def parse_seccomp(addr: int) -> None:
|
||||
"""Parse a struct sock_fprog at a given address and pass filter to external tool."""
|
||||
|
||||
# addr = int(addr) & pwndbg.aglib.arch.ptrmask
|
||||
filter_len = pwndbg.aglib.memory.u16(addr)
|
||||
filter_addr = pwndbg.aglib.memory.u(addr + pwndbg.aglib.typeinfo.ptrsize)
|
||||
|
||||
print(message.success(f"sock_fprog @ {addr:#x}"))
|
||||
print(f" len = {filter_len}")
|
||||
print(f" filter_addr = {filter_addr:#x}")
|
||||
|
||||
filter_size = filter_len * 8
|
||||
filter_bytes = pwndbg.aglib.memory.read(filter_addr, filter_size, partial=False)
|
||||
|
||||
if shutil.which("ceccomp"):
|
||||
proc = subprocess.run(
|
||||
["ceccomp", "disasm", "--color", "always"], input=filter_bytes, capture_output=True
|
||||
)
|
||||
print(proc.stdout.decode())
|
||||
elif shutil.which("seccomp-tools"):
|
||||
proc = subprocess.run(
|
||||
["seccomp-tools", "disasm", "-"], input=filter_bytes, capture_output=True
|
||||
)
|
||||
print(proc.stdout.decode())
|
||||
else:
|
||||
print("install ceccomp or seccomp-tools to parse seccomp")
|
||||
Loading…
Reference in new issue