diff --git a/pwndbg/__init__.py b/pwndbg/__init__.py index 8c97061fb..f3a6c13cd 100644 --- a/pwndbg/__init__.py +++ b/pwndbg/__init__.py @@ -19,6 +19,7 @@ import pwndbg.commands.vmmap import pwndbg.commands.dt import pwndbg.commands.search import pwndbg.commands.start +import pwndbg.commands.procinfo import pwndbg.commands.auxv import pwndbg.commands.windbg import pwndbg.commands.ida diff --git a/pwndbg/commands/__init__.py b/pwndbg/commands/__init__.py index c4cc50510..eb7604c2b 100644 --- a/pwndbg/commands/__init__.py +++ b/pwndbg/commands/__init__.py @@ -48,7 +48,6 @@ class Command(gdb.Command): def invoke(self, argument, from_tty): argv = self.split_args(argument) - try: return self.function(*argv) except TypeError: diff --git a/pwndbg/commands/procinfo.py b/pwndbg/commands/procinfo.py new file mode 100644 index 000000000..0afed97d9 --- /dev/null +++ b/pwndbg/commands/procinfo.py @@ -0,0 +1,66 @@ +import gdb +import os +import pwndbg.proc +import pwndbg.commands +import pwndbg.auxv +try: + import psutil +except: + psutil = None + +""" +PEDA prints it out like this: + +exe = /bin/bash +fd[0] -> /dev/pts/96 +fd[1] -> /dev/pts/96 +fd[2] -> /dev/pts/96 +pid = 31102 +ppid = 31096 +uid = [287138, 287138, 287138, 287138] +gid = [5000, 5000, 5000, 5000] + +""" + +@pwndbg.commands.Command +def procinfo(): + """ + Display information about the running process. + """ + if not psutil: + print "psutil required but not installed" + return + + exe = repr(str(pwndbg.auxv.get()['AT_EXECFN'])) + + proc = psutil.Process(pwndbg.proc.pid) + + pid = proc.pid + ppid = proc.ppid() + + uids = proc.uids() + uids = [uids.real, uids.effective, uids.saved] + + gids = proc.gids() + gids = [gids.real, gids.effective, gids.saved] + + files = {f.fd:repr(str(f.path)) for f in proc.open_files()} + + for c in proc.connections(): + files[c.fd] = '%s:%s => %s:%s' % (c.laddr + c.raddr) + + for fd in os.listdir("/proc/%d/fd" % pid): + fd = int(fd) + if fd in files: + continue + files[fd] = repr(str(os.path.realpath("/proc/%d/fd/%s" % (pid, fd)))) + + print("%-10s %s" % ("exe", exe)) + print("%-10s %s" % ("pid", pid)) + print("%-10s %s" % ("ppid", ppid)) + print("%-10s %s" % ("uid", uids)) + print("%-10s %s" % ("gid", gids)) + for fd, path in files.items(): + print("%-10s %s" % ("fd[%i]" % fd, path)) + + return diff --git a/pwndbg/commands/start.py b/pwndbg/commands/start.py index f33f156e4..554d02c1b 100644 --- a/pwndbg/commands/start.py +++ b/pwndbg/commands/start.py @@ -21,11 +21,13 @@ def on_start(): break_on_first_instruction = False @pwndbg.commands.Command -def start(): +def start(*a): """ Set a breakpoint at a convenient location in the binary, generally 'main', 'init', or the entry point. """ + run = 'run ' + ' '.join(a) + symbols = ["main", "_main", "start", @@ -37,20 +39,20 @@ def start(): for address in filter(bool, map(pwndbg.symbol.address, symbols)): if address: b = gdb.Breakpoint('*%#x' % address, temporary=True) - gdb.execute('run', from_tty=False, to_string=True) + gdb.execute(run, from_tty=False, to_string=True) break else: - entry() + entry(*a) @pwndbg.commands.Command -def entry(): +def entry(*a): """ Set a breakpoint at the first instruction executed in the target binary. """ global break_on_first_instruction break_on_first_instruction = True - print("Trying experimental breakpoint") - gdb.execute('run', from_tty=False, to_string=True) + run = 'run ' + ' '.join(a) + gdb.execute(run, from_tty=False, to_string=True) diff --git a/pwndbg/proc.py b/pwndbg/proc.py index 6b607e5d2..d848d287f 100644 --- a/pwndbg/proc.py +++ b/pwndbg/proc.py @@ -23,6 +23,10 @@ class module(ModuleType): def alive(self): return gdb.selected_thread() is not None + @property + def exe(self): + auxv = pwndbg.auxv.get() + def OnlyWhenRunning(self, func): def wrapper(*a, **kw): func.__doc__