Ejemplo n.º 1
0
def main():
    import warnings
    warnings.simplefilter("ignore", DeprecationWarning)

    try:
        port = int(sys.argv[1])
    except:
        port = DEFAULT_SERVER_PORT

    conn = None
    if port > 19000:
        # Named server
        try:
            __import__("win32file")
            np_server = NamedPipeStream.create_server(str(port))
            conn = connect_stream(np_server, ModSlaveService)
            try:
                conn.serve_all()
            except Exception:
                pass
            finally:
                if (conn is not None) and not conn.closed:
                    conn.close()
                exit()
        except SystemExit:
            raise
        except:
            conn = None

    if conn is None:
        t = SimpleServer(ModSlaveService, port=port, auto_register=False)
        t.start()
 def connectPL(self):
     rem = CustomMachine(self.host)
     conn = connect_stream(rpyc.SocketStream(rem.connect_sock(18861)),
                           config={'allow_pickle' : True})
     assert conn.root.test() == 1, "%s: RPC Failure" % self.host
     self.conn = conn
     self.connected = True
Ejemplo n.º 3
0
    def connect(self, host, port=8002):
        """
        Setup connection to the node via a secure socket.

        :param host: the node ip.
        :param port: the port behind which c-simple server runs, default is 8002.
        """
        # To avoid trying to connect without anything set up.
        if not (os.path.isfile(self.client_cert) and os.path.isfile(self.client_key)):
            self.gen_certificate(key_length=4096)
        if not os.path.isfile(self.node_cert):
            raise Exception('Server certificate is missing. Cannot initiate the connection')
        try:
            # Connecting the socket
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            s.setblocking(1)
            s.connect((host, port))
            context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
            context.verify_mode = ssl.CERT_REQUIRED
            context.load_verify_locations(self.node_cert)
            context.load_cert_chain(self.client_cert, self.client_key)

            secure_sock = context.wrap_socket(s, server_side=False, server_hostname=host)
            self.conn = factory.connect_stream(SocketStream(secure_sock), service=VoidService)

        except ssl.SSLError as e:
            raise Exception('Could not connect to host {}:{}, getting following ssl error :\n{}'.format(host, port, e))
Ejemplo n.º 4
0
def connect_stream(stream):
    """
    Creates an RPyC connection over the given stream

    :param channel: the :class:`rpyc.core.stream.Stream` instance
    
    :returns: an RPyC connection exposing ``SlaveService``
    """
    return factory.connect_stream(stream, SlaveService)
Ejemplo n.º 5
0
def connect_stream(stream):
    """
    Creates an RPyC connection over the given stream

    :param channel: the :class:`rpyc.core.stream.Stream` instance
    
    :returns: an RPyC connection exposing ``SlaveService``
    """
    return factory.connect_stream(stream, SlaveService)
Ejemplo n.º 6
0
def connect(host,
            port,
            service=VoidService,
            config={},
            ipv6=False,
            keepalive=False,
            timeout=3):
    s = SocketStream.connect(host,
                             port,
                             ipv6=ipv6,
                             keepalive=keepalive,
                             timeout=timeout)
    return connect_stream(s, service, config)
Ejemplo n.º 7
0
def ssl_connect(host,port,keyfile=None,certfile=None,ca_certs=None,ssl_version=None,service=VoidService,config={},ipv6=False):
	ssl_kwargs = {'server_side':False}
	if keyfile:
		ssl_kwargs['keyfile'] = keyfile
	if certfile:
		ssl_kwargs['certfile'] = certfile
	if ca_certs:
		ssl_kwargs['ca_certs'] = ca_certs
	if ssl_version:
		ssl_kwargs['ssl_version'] = ssl_version
	else:
		ssl_kwargs['ssl_version'] = ssl.PROTOCOL_TLSv1
	s = SocketStream.ssl_connect(host,port,ssl_kwargs,ipv6 = ipv6)
	return connect_stream(s,service,config)
Ejemplo n.º 8
0
def main():
    if len(sys.argv) == 2:
        host, port = sys.argv[1].split(":") 

        try:
            s = SSLClient().connect(host, int(port))
            conn = connect_stream(SocketStream(s), ReverseSlave, {})

            while True:
               conn.serve_all()
        except KeyboardInterrupt:
            pass 
        except Exception as e:
            print e
    else:
        print "usage: python implant.py 127.0.0.1:8080"
Ejemplo n.º 9
0
def main():
    if len(sys.argv) == 2:
        host, port = sys.argv[1].split(":")

        try:
            s = SSLClient().connect(host, int(port))
            conn = connect_stream(SocketStream(s), ReverseSlave, {})

            while True:
                conn.serve_all()
        except KeyboardInterrupt:
            pass
        except Exception as e:
            print e
    else:
        print "usage: python implant.py 127.0.0.1:8080"
Ejemplo n.º 10
0
def connect():
    """rpyc.utils.factory.connect() uses default 3s connection timeout
    too short for some computers running big projects,
    use connect_stream() instead and set timeout"""
    stream = None
    if sys.platform == 'win32':
        stream = SocketStream.connect(rpyc_config.HOSTNAME,
                                      rpyc_config.PORT,
                                      timeout=15)
    else:
        stream = SocketStream.unix_connect(rpyc_config.SOCKET_PATH)
    """default sync_request_timeout is 30.0"""
    global _conn
    stream_config = dict(sync_request_timeout=3.0)
    _conn = factory.connect_stream(stream, config=stream_config)
    global bind
    bind = _conn.root.lom_observer_helper.bind
    return _conn.root.Live
Ejemplo n.º 11
0
def tlslite_connect(host,port,username,password,service=VoidService,config={},ipv6=False):
	return connect_stream(SocketStream.tlslite_connect(host,port,username,password,ipv6=ipv6),service,config)
Ejemplo n.º 12
0
def connect(host,port,service=VoidService,config={},ipv6=False):
	return connect_stream(SocketStream.connect(host,port,ipv6=ipv6),service,config)
Ejemplo n.º 13
0
def connect_stream(stream):
    return factory.connect_stream(stream, SlaveService)
Ejemplo n.º 14
0
def connect_stream(stream):
    return factory.connect_stream(stream, SlaveService)