def authenticator(self, sock): channel = rpyc.Channel(rpyc.SocketStream(sock)) password = channel.recv().decode('utf-8') if password != self.password: channel.send(AUTH_ERROR) raise rpyc.utils.authenticators.AuthenticationError('Invalid password from client.') channel.send(AUTH_SUCCESS) return sock, self.password
def __init__(self, port, password): channel = rpyc.Channel(rpyc.SocketStream.connect('127.0.0.1', port)) channel.send(password.encode('utf-8')) response = channel.recv() if response == AUTH_ERROR: # TODO: What to raise here. I guess we create a custom error raise ValueError('Invalid password for daemon') self.conn = rpyc.utils.factory.connect_channel(channel, service=ClientService)
def __init__(self, host, port, login, password): channel = rpyc.Channel(rpyc.SocketStream.connect(host, port)) secure = rpyc.core.brine.dump((login, password)) channel.send(secure) response = channel.recv() if response == 'AUTH_ERROR': raise ValueError('Invalid login or password for daemon') self.conn = rpyc.utils.factory.connect_channel(channel)
def __init__(self, host, port, hash): channel = rpyc.Channel(rpyc.SocketStream.connect(host, port)) secure = rpyc.core.brine.dump(hash) channel.send(secure) response = channel.recv() if response == 'AUTH_ERROR': raise ValueError('Invalid hash') self.conn = rpyc.utils.factory.connect_channel(channel)
def _create_client(self): # key = os.path.join(os.path.dirname(__file__), "cert/artap.key") # cert = os.path.join(os.path.dirname(__file__), "cert/artap.crt") channel = rpyc.Channel( rpyc.SocketStream.connect(self.options["hostname"], self.options["port"])) channel.send(self.options["username"].encode('utf-8')) response = channel.recv() AUTH_ERROR = b'error' if response == AUTH_ERROR: raise rpyc.utils.authenticators.AuthenticationError( 'Invalid username for daemon') return rpyc.utils.factory.connect_channel( channel, service=rpyc.core.ClassicService)
def client_authenticator(sock): channel = rpyc.Channel(rpyc.SocketStream(sock)) data = channel.recv() data = rpyc.core.brine.load(data) login = data[0] password = data[1] config_parser = ConfigFileParser.ConfigFileParser() expected_login = config_parser.login() expected_password = config_parser.password() if login != expected_login or password != expected_password: channel.send('AUTH_ERROR') raise rpyc.utils.authenticators.AuthenticationError( 'Invalid password from client.') channel.send('AUTH_SUCCESS') return sock, None
def remote_deploy(): print_blue("\nStarting remote deploy") try: password = getpass.getpass("Connection password:"******"Connecting...") channel = rpyc.Channel( rpyc.SocketStream.connect("arma.uk-sf.com", 18812)) channel.send(password.encode()) response = channel.recv() if response == AUTH_ERROR: raise ValueError("Incorrect password") client = rpyc.utils.factory.connect_channel( channel, CallbackService, config={"sync_request_timeout": 3000}) print("Connected to arma.uk-sf.com") if deploy_all or deploy_extract: print_blue("\nExtracting remote {}".format(file_zip)) client.root.extract_zip(file_zip) if deploy_all or deploy_update: print_blue("\nUpdating repo") client.root.update_repo(file_zip) if deploy_all or deploy_build: print_blue("\nBuilding repo") client.root.build_repo() time.sleep(3) if deploy_all or deploy_cleanup: print_blue("\nCleaning up") client.root.cleanup(file_zip) client.close() except Exception as e: client.close() print_error(e) raise Exception
def connect_on_client(self, launcher_args): """ connect on a client that would be running a bind payload """ launcher = network.conf.launchers["connect"]( connect_on_bind_payload=True) try: launcher.parse_args(shlex.split(launcher_args)) except LauncherError as e: launcher.arg_parser.print_usage() return try: stream = launcher.iterate().next() except socket.error as e: self.handler.display_error( "Couldn't connect to pupy: {}".format(e)) return self.handler.display_success("Connected. Starting session") bgsrv = PupyConnectionThread(self, PupyBindService, rpyc.Channel(stream), config={'connid': launcher.args.host}) bgsrv.start()
def rpyc_loop(launcher): global attempt global debug stream = None for ret in launcher.iterate(): try: if isinstance(ret, tuple): # bind payload server_class, port, address, authenticator, stream, transport, transport_kwargs = ret s = server_class( BindSlaveService, port=port, hostname=address, authenticator=authenticator, stream=stream, transport=transport, transport_kwargs=transport_kwargs, pupy_srv=None, ) s.start() else: # connect payload stream = ret def check_timeout(event, cb, timeout=60): time.sleep(timeout) if not event.is_set(): logging.error('timeout occured!') cb() event = threading.Event() t = threading.Thread(target=check_timeout, args=(event, stream.close)) t.daemon = True t.start() lock = threading.RLock() conn = None try: conn = PupyConnection(lock, None, ReverseSlaveService, rpyc.Channel(stream), config={}) conn._init_service() finally: event.set() attempt = 0 with lock: while not conn.closed: conn.serve(10) except SystemExit: raise except EOFError: pass except Exception as e: if debug: try: logging.exception(e) except: print "Exception ({}): {}".format(type(e), e) finally: if stream is not None: try: stream.close() except: pass