diff --git a/pwn/toplevel.py b/pwn/toplevel.py index 631efc344..e6b0bed4f 100644 --- a/pwn/toplevel.py +++ b/pwn/toplevel.py @@ -6,6 +6,7 @@ import os import re import socks +import signal import string import struct import subprocess diff --git a/pwnlib/tubes/process.py b/pwnlib/tubes/process.py index a1ba91ddc..6d60f9f04 100644 --- a/pwnlib/tubes/process.py +++ b/pwnlib/tubes/process.py @@ -6,6 +6,7 @@ import pty import resource import select +import signal import subprocess import tty @@ -97,6 +98,8 @@ class process(tube): Where the process is running, used for logging purposes. display(list): List of arguments to display, instead of the main executable name. + alarm(int): + Set a SIGALRM alarm timeout on the process. Attributes: proc(subprocess) @@ -183,6 +186,10 @@ class process(tube): >>> process(['sh','-c','ulimit -s'], aslr=0).recvline() 'unlimited\n' + + >>> io = process(['sh','-c','sleep 10; exit 7'], alarm=2) + >>> io.poll(block=True) == -signal.SIGALRM + True """ PTY = PTY @@ -206,7 +213,8 @@ def __init__(self, argv, aslr = None, setuid = None, where = 'local', - display = None): + display = None, + alarm = None): super(process, self).__init__(timeout, level = level) #: `subprocess.Popen` object @@ -253,6 +261,9 @@ def __init__(self, argv, #: Directory the process was created in self.cwd = cwd or os.path.curdir + #: Alarm timeout of the process + self.alarm = alarm + self.preexec_fn = preexec_fn self.display = display or self.program @@ -357,6 +368,9 @@ def __preexec_fn(self): except: pass + if self.alarm is not None: + signal.alarm(self.alarm) + self.preexec_fn() @property