Skip to content

Commit

Permalink
checksec: more forgiving when passed directory arguments
Browse files Browse the repository at this point in the history
I often use `checksec *` to lazily avoid typing
filename in a directory. If the directory contains any other
sub-dirs, the command fails. With this patch, checksec will
silently skip dir paths. There is TOCTOU issue but I don't think
checksec do anything important enough to explicitly use try/catch
to account for that.
  • Loading branch information
tesuji committed Jan 22, 2025
1 parent cff58e1 commit 4d9455e
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions pwnlib/commandline/checksec.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,19 @@
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 []
files = [open(f, 'rb') for f in filter(os.path.isfile, files)]

if not files:
parser.print_usage()
Expand Down

0 comments on commit 4d9455e

Please sign in to comment.