• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Gallopsled / pwntools / 13475084749

22 Feb 2025 05:29PM UTC coverage: 70.912% (-0.1%) from 71.055%
13475084749

push

github

tesuji
change checksec=False on ELF class

There is no need to print checksec details every time. Most usecases
only need to view checksec once in a while.

Here is the `checksec=False` set before this patch:

```
> rg '\sELF\(' | rg checksec
pwnlib/libcdb.py:    local_libc = ELF(shell_path, checksec=False).libc
pwnlib/libcdb.py:    libc = ELF(filename, checksec=False)
pwnlib/libcdb.py:        >>> libc_path = ELF(which('ls'), checksec=False).libc.path
pwnlib/libcdb.py:    libc = ELF(libc_path, checksec=False)
pwnlib/elf/elf.py:                return ELF(lib, self._print_checksec)
pwnlib/elf/elf.py:        return ELF(exepath, checksec=False)
pwnlib/elf/elf.py:        return ELF(exepath, checksec=False)
pwnlib/commandline/libcdb.py:            exe = ELF(path, checksec=False)
pwnlib/commandline/checksec.py:            e = ELF(f)
pwnlib/data/templates/pwnup.mako:       ctx.binary = ELF(binary, checksec=False)
```

3600 of 6410 branches covered (56.16%)

10 of 19 new or added lines in 8 files covered. (52.63%)

29 existing lines in 4 files now uncovered.

12833 of 18097 relevant lines covered (70.91%)

0.71 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

33.33
/pwnlib/commandline/debug.py
1
from __future__ import absolute_import
1✔
2
from __future__ import division
1✔
3

4
import argparse
1✔
5
import sys
1✔
6

7
from pwn import *
1✔
8
from pwnlib.commandline import common
1✔
9

10
parser = common.parser_commands.add_parser(
1✔
11
    'debug',
12
    help = 'Debug a binary in GDB',
13
    description = 'Debug a binary in GDB'
14
)
15
parser.add_argument(
1✔
16
    '-x', metavar='GDBSCRIPT',
17
    type=argparse.FileType('r'),
18
    help='Execute GDB commands from this file.'
19
)
20
parser.add_argument(
1✔
21
    '--pid',
22
    type=int,
23
    help="PID to attach to"
24
)
25
parser.add_argument(
1✔
26
    '-c', '--context',
27
    metavar = 'context',
28
    action = 'append',
29
    type   = common.context_arg,
30
    choices = common.choices,
31
    help = 'The os/architecture/endianness/bits the shellcode will run in (default: linux/i386), choose from: %s' % common.choices,
32
)
33
parser.add_argument(
1✔
34
    '--exec',
35

36
    # NOTE: Type cannot be "file" because we may be referring to a remote
37
    #       file, or a file on an Android device.
38
    type=str,
39

40
    dest='executable',
41
    help='File to debug'
42
)
43
parser.add_argument(
1✔
44
    '--process', metavar='PROCESS_NAME',
45
    help='Name of the process to attach to (e.g. "bash")'
46
)
47
parser.add_argument(
1✔
48
    '--sysroot', metavar='SYSROOT',
49
    type=str,
50
    default='',
51
    help="GDB sysroot path"
52
)
53

54
def main(args):
1✔
55
    gdbscript = ''
×
56
    if args.x:
×
57
        gdbscript = args.x.read()
×
58

59
    if context.os == 'android':
×
60
        context.device = adb.wait_for_device()
×
61

62
    if args.executable:
×
63
        if os.path.exists(args.executable):
×
NEW
64
            context.binary = ELF(args.executable) # ???
×
65
            target = context.binary.path
×
66

67
        # This path does nothing, but avoids the "print_usage()"
68
        # path below.
69
        elif context.os == 'android':
×
70
            target = args.executable
×
71
    elif args.pid:
×
72
        target = int(args.pid)
×
73
    elif args.process:
×
74
        if context.os == 'android':
×
75
            target = adb.pidof(args.process)
×
76
        else:
77
            target = pidof(args.process)
×
78

79
        # pidof() returns a list
80
        if not target:
×
81
            log.error("Could not find a PID for %r", args.process)
×
82

83
        target = target[0]
×
84

85
        # pidof will sometimes return all PIDs, including init
86
        if target == 1:
×
87
            log.error("Got PID 1 from pidof.  Check the process name, or use --pid 1 to debug init")
×
88
    else:
89
        parser.print_usage()
×
90
        return 1
×
91

92
    if args.pid or args.process:
×
93
        pid = gdb.attach(target, gdbscript=gdbscript, sysroot=args.sysroot)
×
94

95
        # Since we spawned the gdbserver process, and process registers an
96
        # atexit handler to close itself, gdbserver will be terminated when
97
        # we exit.  This will manifest as a "remote connected ended" or
98
        # similar error message.  Hold it open for the user.
99
        log.info("GDB connection forwarding will terminate when you press enter")
×
100
        pause()
×
101
    else:
102
        gdb.debug(target, gdbscript=gdbscript, sysroot=args.sysroot).interactive()
×
103

104
if __name__ == '__main__':
1!
105
    pwnlib.commandline.common.main(__file__, main)
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc