Pwntools establishes a standard interface for connecting to locally and remotely binaries. This is accomplished via the pwnlib.tubes module.
Use remote() for easy connection to remote processes.
p = remote('ctf.ironforgecyber.com', 1100)You can also use a listener to connect to a remote process.
1l = listen(1100)
2r = remote('ctf.ironforgecyber.com', l.lport)
3p = l.wait_for_connection()Use process() for easy connection to local processes.
p = process('./win32')We can use gdb.debug() to run a local process within gdb. This takes a secondary argument, gdbscript, which is a string of commands to run in gdb. This is useful for setting breakpoints, etc.
p = gdb.debug('./win32', gdbscript='b *main\nc')People commonly use a separate variable for their gdbscript because it's easier to read. Using a separate string allows you to use triple quotes, making writing multi-line scripts easier.
1cmds = '''
2b *main
3c
4'''
5
6p = gdb.debug('./win32',We can use gdb.attach() to attach to a process. It takes the target to attach to (which, under the hood, is the process ID).
1p = process('./win32')
2gdb.attach(p)