Skip to content

Commit 78d416b

Browse files
tesujipeace-maker
andauthored
checksec: Do NOT error when passing directory arguments to commandline 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]>
1 parent 6748a78 commit 78d416b

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ The table below shows which release corresponds to each branch, and what date th
8181
- [#2526][2526] Properly make use of extra arguments in `packing` utilities. `sign` parameter requires keyword syntax to specify it.
8282
- [#2517][2517] Allow to passthru kwargs on `ssh.__getattr__` convenience function to fix SSH motd problems
8383
- [#2527][2527] Allow setting debugger path via `context.gdb_binary`
84+
- [#2530][2530] Do NOT error when passing directory arguments in `checksec` commandline tool.
8485

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

9395
## 4.15.0 (`beta`)
9496

pwnlib/commandline/checksec.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,28 @@
1515
parser.add_argument(
1616
'elf',
1717
nargs='*',
18-
type=argparse.FileType('rb'),
1918
help='Files to check'
2019
)
2120
parser.add_argument(
2221
'--file',
2322
nargs='*',
2423
dest='elf2',
2524
metavar='elf',
26-
type=argparse.FileType('rb'),
2725
help='File to check (for compatibility with checksec.sh)'
2826
)
2927

3028
def main(args):
31-
files = args.elf or args.elf2 or []
29+
files = args.elf or args.elf2 or []
3230

3331
if not files:
3432
parser.print_usage()
3533
return
3634

3735
for f in files:
3836
try:
39-
e = ELF(f.name)
37+
e = ELF(f)
4038
except Exception as e:
41-
print("{name}: {error}".format(name=f.name, error=e))
39+
print("{name}: {error}".format(name=f, error=e))
4240

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

0 commit comments

Comments
 (0)