Commit dcdd66f6 authored by Dean Fenster's avatar Dean Fenster

Merge branch 'develop' of github.com:lmacken/pyrasite into develop

* 'develop' of github.com:lmacken/pyrasite:
  Add the ability to control the IPC timeout.
parents a7a4f69a bc40e727
......@@ -64,7 +64,7 @@ class PyrasiteIPC(object):
# shell payloads with netcat.
reliable = True
def __init__(self, pid, reverse='ReversePythonConnection'):
def __init__(self, pid, reverse='ReversePythonConnection', timeout=5):
super(PyrasiteIPC, self).__init__()
self.pid = pid
self.sock = None
......@@ -72,6 +72,7 @@ class PyrasiteIPC(object):
self.hostname = None
self.port = None
self.reverse = reverse
self.timeout = float(timeout)
def __enter__(self):
self.connect()
......@@ -165,7 +166,7 @@ class PyrasiteIPC(object):
"""Wait for the injected payload to connect back to us"""
(clientsocket, address) = self.server_sock.accept()
self.sock = clientsocket
self.sock.settimeout(5)
self.sock.settimeout(self.timeout)
self.address = address
def cmd(self, cmd):
......
......@@ -92,6 +92,10 @@ def main():
help="Set where output is to be printed. 'procstreams'"
" prints output in stdout/stderr of running process"
" and 'localterm' prints output in local terminal.")
parser.add_argument('--ipc-timeout', dest='ipc_timeout', default=5,
action='store', type=int,
help="The number of seconds to wait for the injected"
" code to reply over IPC before giving up.")
if len(sys.argv) == 1:
parser.print_help()
......@@ -129,7 +133,8 @@ def main():
if args.output_type == 'localterm':
# Create new IPC connection to the process.
ipc = pyrasite.PyrasiteIPC(pid, 'ReversePythonConnection')
ipc = pyrasite.PyrasiteIPC(pid, 'ReversePythonConnection',
timeout=ipc_timeout)
ipc.connect()
print("Pyrasite Shell %s" % pyrasite.__version__)
print("Connected to '%s'" % ipc.title)
......
......@@ -15,6 +15,7 @@
#
# Copyright (C) 2011-2013 Red Hat, Inc., Luke Macken <lmacken@redhat.com>
import os
import sys
import pyrasite
......@@ -32,7 +33,8 @@ def shell():
print(usage)
sys.exit(1)
ipc = pyrasite.PyrasiteIPC(pid, 'ReversePythonShell')
ipc = pyrasite.PyrasiteIPC(pid, 'ReversePythonShell',
timeout=os.getenv('PYRASITE_IPC_TIMEOUT') or 5)
ipc.connect()
print("Pyrasite Shell %s" % pyrasite.__version__)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment