File: checksec.py

package info (click to toggle)
pwntools 4.15.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 18,508 kB
  • sloc: python: 59,870; ansic: 48,351; asm: 45,047; sh: 396; makefile: 256
file content (44 lines) | stat: -rw-r--r-- 949 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from __future__ import absolute_import
from __future__ import division

import argparse
import sys

from pwn import *
from pwnlib.commandline import common

parser = common.parser_commands.add_parser(
    'checksec',
    help = 'Check binary security settings',
    description = 'Check binary security settings',
)
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 []

    if not files:
        parser.print_usage()
        return

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

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