Skip to content

Commit

Permalink
checksec: Do NOT error when passing directory arguments to commandlin…
Browse files Browse the repository at this point in the history
…e tool (#2530)

I often use `checksec *` to lazily avoid typing filenames in a directory.
If the directory contains any other sub-dirs, the command fails.
With this patch, checksec will silently skip dir paths. There's still
TOCTOU issue but I don't think checksec do anything important enough
to explicitly use try/catch to account for that.

Co-authored-by: peace-maker <[email protected]>
  • Loading branch information
tesuji and peace-maker authored Jan 26, 2025
1 parent 6748a78 commit 78d416b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ The table below shows which release corresponds to each branch, and what date th
- [#2526][2526] Properly make use of extra arguments in `packing` utilities. `sign` parameter requires keyword syntax to specify it.
- [#2517][2517] Allow to passthru kwargs on `ssh.__getattr__` convenience function to fix SSH motd problems
- [#2527][2527] Allow setting debugger path via `context.gdb_binary`
- [#2530][2530] Do NOT error when passing directory arguments in `checksec` commandline tool.

[2519]: https://github.com/Gallopsled/pwntools/pull/2519
[2507]: https://github.com/Gallopsled/pwntools/pull/2507
Expand All @@ -89,6 +90,7 @@ The table below shows which release corresponds to each branch, and what date th
[2526]: https://github.com/Gallopsled/pwntools/pull/2526
[2517]: https://github.com/Gallopsled/pwntools/pull/2517
[2527]: https://github.com/Gallopsled/pwntools/pull/2527
[2530]: https://github.com/Gallopsled/pwntools/pull/2530

## 4.15.0 (`beta`)

Expand Down
8 changes: 3 additions & 5 deletions pwnlib/commandline/checksec.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,28 @@
parser.add_argument(
'elf',
nargs='*',
type=argparse.FileType('rb'),
help='Files to check'
)
parser.add_argument(
'--file',
nargs='*',
dest='elf2',
metavar='elf',
type=argparse.FileType('rb'),
help='File to check (for compatibility with checksec.sh)'
)

def main(args):
files = args.elf or args.elf2 or []
files = args.elf or args.elf2 or []

if not files:
parser.print_usage()
return

for f in files:
try:
e = ELF(f.name)
e = ELF(f)
except Exception as e:
print("{name}: {error}".format(name=f.name, error=e))
print("{name}: {error}".format(name=f, error=e))

if __name__ == '__main__':
common.main(__file__, main)

0 comments on commit 78d416b

Please sign in to comment.