Esempio n. 1
0
    def Run(self, unused_arg, ttl=None):
        """Returns the startup information."""
        logging.debug("Sending startup information.")

        response = rdfvalue.StartupInfo(boot_time=long(psutil.BOOT_TIME * 1e6),
                                        client_info=GetClientInformation())

        self.grr_worker.SendReply(
            response,
            session_id=self.well_known_session_id,
            response_id=0,
            request_id=0,
            priority=rdfvalue.GrrMessage.Priority.LOW_PRIORITY,
            message_type=rdfvalue.GrrMessage.Type.MESSAGE,
            require_fastpoll=False,
            ttl=ttl)
Esempio n. 2
0
    def ProcessMessage(self, message=None, event=None):
        """Handle a startup event."""
        _ = event
        # We accept unauthenticated messages so there are no errors but we don't
        # store the results.
        if (message.auth_state !=
                rdfvalue.GrrMessage.AuthorizationState.AUTHENTICATED):
            return

        client_id = message.source

        client = aff4.FACTORY.Create(client_id,
                                     "VFSGRRClient",
                                     mode="rw",
                                     token=self.token)
        old_info = client.Get(client.Schema.CLIENT_INFO)
        old_boot = client.Get(client.Schema.LAST_BOOT_TIME, 0)
        startup_info = rdfvalue.StartupInfo(message.args)
        info = startup_info.client_info

        # Only write to the datastore if we have new information.
        new_data = (info.client_name, info.client_version, info.revision,
                    info.build_time, info.client_description)
        old_data = (old_info.client_name, old_info.client_version,
                    old_info.revision, old_info.build_time,
                    old_info.client_description)

        if new_data != old_data:
            client.Set(client.Schema.CLIENT_INFO(info))

        client.AddLabels(*info.labels, owner="GRR")

        # Allow for some drift in the boot times (5 minutes).
        if abs(int(old_boot) - int(startup_info.boot_time)) > 300 * 1e6:
            client.Set(client.Schema.LAST_BOOT_TIME(startup_info.boot_time))

        client.Close()

        flow.Events.PublishEventInline("ClientStartup",
                                       message,
                                       token=self.token)
Esempio n. 3
0
    def ProcessMessage(self, message=None, event=None):
        client_id = message.source
        # Older client versions do not sent the RDFValue type name explicitly.
        if event is None:
            event = rdfvalue.StartupInfo(message.args)

        client_info = event.client_info

        if client_info.client_version < 2910:
            python_hack_root_urn = config_lib.CONFIG.Get(
                "Config.python_hack_root")
            hack_urn = python_hack_root_urn.Add("find_fix.py")

            fd = aff4.FACTORY.Open(hack_urn, token=self.token)
            python_blob = fd.Get(fd.Schema.BINARY)
            if python_blob is None:
                raise flow.FlowError("Python hack %s not found." % hack_urn)

            self.CallClient(client_id,
                            "ExecutePython",
                            python_code=python_blob)