Add procinfo, permit passing arguments to start and entry

pull/10/head
Zach Riggle 11 years ago
parent 0a1316d1f1
commit df8006bbae

@ -19,6 +19,7 @@ import pwndbg.commands.vmmap
import pwndbg.commands.dt import pwndbg.commands.dt
import pwndbg.commands.search import pwndbg.commands.search
import pwndbg.commands.start import pwndbg.commands.start
import pwndbg.commands.procinfo
import pwndbg.commands.auxv import pwndbg.commands.auxv
import pwndbg.commands.windbg import pwndbg.commands.windbg
import pwndbg.commands.ida import pwndbg.commands.ida

@ -48,7 +48,6 @@ class Command(gdb.Command):
def invoke(self, argument, from_tty): def invoke(self, argument, from_tty):
argv = self.split_args(argument) argv = self.split_args(argument)
try: try:
return self.function(*argv) return self.function(*argv)
except TypeError: except TypeError:

@ -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

@ -21,11 +21,13 @@ def on_start():
break_on_first_instruction = False break_on_first_instruction = False
@pwndbg.commands.Command @pwndbg.commands.Command
def start(): def start(*a):
""" """
Set a breakpoint at a convenient location in the binary, Set a breakpoint at a convenient location in the binary,
generally 'main', 'init', or the entry point. generally 'main', 'init', or the entry point.
""" """
run = 'run ' + ' '.join(a)
symbols = ["main", symbols = ["main",
"_main", "_main",
"start", "start",
@ -37,20 +39,20 @@ def start():
for address in filter(bool, map(pwndbg.symbol.address, symbols)): for address in filter(bool, map(pwndbg.symbol.address, symbols)):
if address: if address:
b = gdb.Breakpoint('*%#x' % address, temporary=True) 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 break
else: else:
entry() entry(*a)
@pwndbg.commands.Command @pwndbg.commands.Command
def entry(): def entry(*a):
""" """
Set a breakpoint at the first instruction executed in Set a breakpoint at the first instruction executed in
the target binary. the target binary.
""" """
global break_on_first_instruction global break_on_first_instruction
break_on_first_instruction = True break_on_first_instruction = True
print("Trying experimental breakpoint") run = 'run ' + ' '.join(a)
gdb.execute('run', from_tty=False, to_string=True) gdb.execute(run, from_tty=False, to_string=True)

@ -23,6 +23,10 @@ class module(ModuleType):
def alive(self): def alive(self):
return gdb.selected_thread() is not None return gdb.selected_thread() is not None
@property
def exe(self):
auxv = pwndbg.auxv.get()
def OnlyWhenRunning(self, func): def OnlyWhenRunning(self, func):
def wrapper(*a, **kw): def wrapper(*a, **kw):
func.__doc__ func.__doc__

Loading…
Cancel
Save