Skip to content

Commit

Permalink
Add alarm option for process() (#704)
Browse files Browse the repository at this point in the history
* Add `alarm` option for process()

* Add signal to toplevel import
  • Loading branch information
zachriggle committed Aug 29, 2016
1 parent 5140d03 commit 70f9c03
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions pwn/toplevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import os
import re
import socks
import signal
import string
import struct
import subprocess
Expand Down
16 changes: 15 additions & 1 deletion pwnlib/tubes/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import pty
import resource
import select
import signal
import subprocess
import tty

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -357,6 +368,9 @@ def __preexec_fn(self):
except:
pass

if self.alarm is not None:
signal.alarm(self.alarm)

self.preexec_fn()

@property
Expand Down

0 comments on commit 70f9c03

Please sign in to comment.