def main(unused_args): client_plugins.RegisterPlugins() if flags.FLAGS.remote_debugging_port: _start_remote_debugging(flags.FLAGS.remote_debugging_port) elif flags.FLAGS.break_on_start: pdb.set_trace() if (flags.FLAGS.unprivileged_server_pipe_input != -1 and flags.FLAGS.unprivileged_server_pipe_output != -1 and flags.FLAGS.unprivileged_server_interface): communication.Main( communication.Channel.FromSerialized( pipe_input=flags.FLAGS.unprivileged_server_pipe_input, pipe_output=flags.FLAGS.unprivileged_server_pipe_output), interface_registry.GetConnectionHandlerForInterfaceString( flags.FLAGS.unprivileged_server_interface), flags.FLAGS.unprivileged_user, flags.FLAGS.unprivileged_group) return # Allow per platform configuration. config.CONFIG.AddContext( contexts.CLIENT_CONTEXT, "Context applied when we run the client process.") client_startup.ClientInit() if flags.FLAGS.install: installer.RunInstaller() sys.exit(0) if config.CONFIG["Client.fleetspeak_enabled"]: fleetspeak_client.GRRFleetspeakClient().Run() return errors = config.CONFIG.Validate(["Client", "CA", "Logging"]) if errors and list(errors.keys()) != ["Client.private_key"]: raise config_lib.ConfigFormatError(errors) if config.CONFIG["Client.fleetspeak_enabled"]: raise ValueError( "This is not a Fleetspeak client, yet 'Client.fleetspeak_enabled' is " "set to 'True'.") enrollment_necessary = not config.CONFIG.Get("Client.private_key") # Instantiating the client will create a private_key so we need to use a flag. client = comms.GRRHTTPClient(ca_cert=config.CONFIG["CA.certificate"], private_key=config.CONFIG.Get( "Client.private_key", default=None)) if enrollment_necessary: logging.info("No private key found, starting enrollment.") client.InitiateEnrolment() client.Run()
def testSendMessagesWithAnnotations(self, mock_worker_class, mock_conn_class): # We stub out the worker class since it starts threads in its # __init__ method. del mock_worker_class # Unused mock_conn = mock.Mock() mock_conn.Send.return_value = 123 mock_conn_class.return_value = mock_conn client_id = "C.0123456789abcdef" flow_id = "01234567" client = fleetspeak_client.GRRFleetspeakClient() grr_messages = [] expected_annotations = fs_common_pb2.Annotations() # 500 bytes translates to ~19 annotations. while expected_annotations.ByteSize() < 500: grr_message = rdf_flows.GrrMessage( session_id="%s/%s" % (client_id, flow_id), name="TestClientAction", request_id=2, response_id=len(grr_messages) + 1) annotation = expected_annotations.entries.add() annotation.key = fleetspeak_client._DATA_IDS_ANNOTATION_KEY annotation.value = "%s:2:%d" % (flow_id, len(grr_messages) + 1) grr_messages.append(grr_message) client._sender_queue.put(grr_message) # Add an extra GrrMessage whose annotation will not be captured. extra_message = rdf_flows.GrrMessage(session_id="%s/%s" % (client_id, flow_id), name="TestClientAction", request_id=3, response_id=1) grr_messages.append(extra_message) client._sender_queue.put(extra_message) self.assertLess(len(grr_messages), fleetspeak_client._MAX_MSG_LIST_MSG_COUNT) self.assertLess(sum(len(x.SerializeToBytes()) for x in grr_messages), fleetspeak_client._MAX_MSG_LIST_BYTES) client._SendOp() mock_conn.Send.assert_called_once() send_args, _ = mock_conn.Send.call_args fs_message = send_args[0] packed_message_list = rdf_flows.PackedMessageList.protobuf() fs_message.data.Unpack(packed_message_list) message_list = communicator.Communicator.DecompressMessageList( rdf_flows.PackedMessageList.FromSerializedBytes( packed_message_list.SerializeToString())) self.assertListEqual(list(message_list.job), grr_messages) self.assertEqual(fs_message.annotations, expected_annotations)
def main(unused_args): client_plugins.RegisterPlugins() if flags.FLAGS.remote_debugging_port: _start_remote_debugging(flags.FLAGS.remote_debugging_port) elif flags.FLAGS.break_on_start: pdb.set_trace() # Allow per platform configuration. config.CONFIG.AddContext( contexts.CLIENT_CONTEXT, "Context applied when we run the client process.") client_startup.ClientInit() if flags.FLAGS.install: installer.RunInstaller() sys.exit(0) is_pyinstaller_binary = getattr(sys, "frozen", False) if is_pyinstaller_binary and platform.system() == "Windows": # Since `Client.install_path` is shared with the Sandbox, Sandbox # initialization makes only sense if we run from a proper installation. # This is the case if this is a PyInstaller binary. sandbox.InitSandbox( "{}_{}".format(config.CONFIG["Client.name"], config.CONFIG["Source.version_string"]), [config.CONFIG["Client.install_path"]]) if config.CONFIG["Client.fleetspeak_enabled"]: fleetspeak_client.GRRFleetspeakClient().Run() return errors = config.CONFIG.Validate(["Client", "CA", "Logging"]) if errors and list(errors.keys()) != ["Client.private_key"]: raise config_lib.ConfigFormatError(errors) if config.CONFIG["Client.fleetspeak_enabled"]: raise ValueError( "This is not a Fleetspeak client, yet 'Client.fleetspeak_enabled' is " "set to 'True'.") enrollment_necessary = not config.CONFIG.Get("Client.private_key") # Instantiating the client will create a private_key so we need to use a flag. client = comms.GRRHTTPClient(ca_cert=config.CONFIG["CA.certificate"], private_key=config.CONFIG.Get( "Client.private_key", default=None)) if enrollment_necessary: logging.info("No private key found, starting enrollment.") client.InitiateEnrolment() client.Run()
def main(unused_args): config.CONFIG.AddContext( contexts.CLIENT_CONTEXT, "Context applied when we run the client process.") client_startup.ClientInit() if flags.FLAGS.install: installer.RunInstaller() if flags.FLAGS.break_on_start: pdb.set_trace() else: fleetspeak_client.GRRFleetspeakClient().Run()
def main(unused_args): if flags.FLAGS.remote_debugging_port: _start_remote_debugging(flags.FLAGS.remote_debugging_port) elif flags.FLAGS.break_on_start: pdb.set_trace() if flags.FLAGS.filesystem_server_socket != -1: communication.Main(flags.FLAGS.filesystem_server_socket, server_lib.Dispatch) return # Allow per platform configuration. config.CONFIG.AddContext(contexts.CLIENT_CONTEXT, "Context applied when we run the client process.") client_startup.ClientInit() if flags.FLAGS.install: installer.RunInstaller() sys.exit(0) if config.CONFIG["Client.fleetspeak_enabled"]: fleetspeak_client.GRRFleetspeakClient().Run() return errors = config.CONFIG.Validate(["Client", "CA", "Logging"]) if errors and list(errors.keys()) != ["Client.private_key"]: raise config_lib.ConfigFormatError(errors) if config.CONFIG["Client.fleetspeak_enabled"]: raise ValueError( "This is not a Fleetspeak client, yet 'Client.fleetspeak_enabled' is " "set to 'True'.") enrollment_necessary = not config.CONFIG.Get("Client.private_key") # Instantiating the client will create a private_key so we need to use a flag. client = comms.GRRHTTPClient( ca_cert=config.CONFIG["CA.certificate"], private_key=config.CONFIG.Get("Client.private_key", default=None)) if enrollment_necessary: logging.info("No private key found, starting enrollment.") client.InitiateEnrolment() client.Run()
def main(unused_args): config.CONFIG.AddContext(contexts.CLIENT_CONTEXT, "Context applied when we run the client process.") client_startup.ClientInit() if flags.FLAGS.install: installer.RunInstaller() if not config.CONFIG["Client.fleetspeak_enabled"]: raise ValueError( "This is a Fleetspeak client, yet 'Client.fleetspeak_enabled' is " "'False'.") if flags.FLAGS.break_on_start: pdb.set_trace() else: fleetspeak_client.GRRFleetspeakClient().Run()
def testBrokenFSConnection(self, mock_worker_class, mock_con_class): # We stub out the worker class since it starts threads in its # __init__ method. del mock_worker_class # Unused mock_conn = mock.Mock() mock_conn.Recv.side_effect = IOError("Broken FS Connection") mock_con_class.return_value = mock_conn with mock.patch.object(logging, "critical") as l: client = fleetspeak_client.GRRFleetspeakClient() try: client._RunInLoop(client._ReceiveOp) except fleetspeak_client.BrokenFSConnectionError: pass self.assertEqual(l.call_count, 1) self.assertIn("Broken local Fleetspeak connection", l.call_args[0][0])