Commit d1c076f8 authored by Jake's avatar Jake

Add the ability to control the IPC timeout.

parent 8c5545aa
...@@ -64,7 +64,7 @@ class PyrasiteIPC(object): ...@@ -64,7 +64,7 @@ class PyrasiteIPC(object):
# shell payloads with netcat. # shell payloads with netcat.
reliable = True reliable = True
def __init__(self, pid, reverse='ReversePythonConnection'): def __init__(self, pid, reverse='ReversePythonConnection', timeout=5):
super(PyrasiteIPC, self).__init__() super(PyrasiteIPC, self).__init__()
self.pid = pid self.pid = pid
self.sock = None self.sock = None
...@@ -72,6 +72,7 @@ class PyrasiteIPC(object): ...@@ -72,6 +72,7 @@ class PyrasiteIPC(object):
self.hostname = None self.hostname = None
self.port = None self.port = None
self.reverse = reverse self.reverse = reverse
self.timeout = float(timeout)
def __enter__(self): def __enter__(self):
self.connect() self.connect()
...@@ -165,7 +166,7 @@ class PyrasiteIPC(object): ...@@ -165,7 +166,7 @@ class PyrasiteIPC(object):
"""Wait for the injected payload to connect back to us""" """Wait for the injected payload to connect back to us"""
(clientsocket, address) = self.server_sock.accept() (clientsocket, address) = self.server_sock.accept()
self.sock = clientsocket self.sock = clientsocket
self.sock.settimeout(5) self.sock.settimeout(self.timeout)
self.address = address self.address = address
def cmd(self, cmd): def cmd(self, cmd):
......
...@@ -92,6 +92,10 @@ def main(): ...@@ -92,6 +92,10 @@ def main():
help="Set where output is to be printed. 'procstreams'" help="Set where output is to be printed. 'procstreams'"
" prints output in stdout/stderr of running process" " prints output in stdout/stderr of running process"
" and 'localterm' prints output in local terminal.") " 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: if len(sys.argv) == 1:
parser.print_help() parser.print_help()
...@@ -129,7 +133,8 @@ def main(): ...@@ -129,7 +133,8 @@ def main():
if args.output_type == 'localterm': if args.output_type == 'localterm':
# Create new IPC connection to the process. # Create new IPC connection to the process.
ipc = pyrasite.PyrasiteIPC(pid, 'ReversePythonConnection') ipc = pyrasite.PyrasiteIPC(pid, 'ReversePythonConnection',
timeout=ipc_timeout)
ipc.connect() ipc.connect()
print("Pyrasite Shell %s" % pyrasite.__version__) print("Pyrasite Shell %s" % pyrasite.__version__)
print("Connected to '%s'" % ipc.title) print("Connected to '%s'" % ipc.title)
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
# #
# Copyright (C) 2011-2013 Red Hat, Inc., Luke Macken <lmacken@redhat.com> # Copyright (C) 2011-2013 Red Hat, Inc., Luke Macken <lmacken@redhat.com>
import os
import sys import sys
import pyrasite import pyrasite
...@@ -32,7 +33,8 @@ def shell(): ...@@ -32,7 +33,8 @@ def shell():
print(usage) print(usage)
sys.exit(1) sys.exit(1)
ipc = pyrasite.PyrasiteIPC(pid, 'ReversePythonShell') ipc = pyrasite.PyrasiteIPC(pid, 'ReversePythonShell',
timeout=os.getenv('PYRASITE_IPC_TIMEOUT') or 5)
ipc.connect() ipc.connect()
print("Pyrasite Shell %s" % pyrasite.__version__) 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