def SetUpBinaries(self): with test_lib.FakeTime(42): code = "I am a binary file" upload_path = config_lib.CONFIG.Get("Config.aff4_root").Add( "executables/windows/test.exe") maintenance_utils.UploadSignedConfigBlob( code, aff4_path=upload_path, token=self.token) with test_lib.FakeTime(43): code = "I'm a python hack" upload_path = config_lib.CONFIG.Get("Config.python_hack_root").Add("test") maintenance_utils.UploadSignedConfigBlob( code, aff4_path=upload_path, token=self.token) with test_lib.FakeTime(44): component = test_lib.WriteComponent( name="grr-awesome-component", build_system=rdf_client.Uname( architecture="64bit", fqdn="test.host", kernel="3.42-generic", machine="x86_64", node="test.localhost", pep425tag="Linux_debian_64bit", release="Debian", system="Linux", version="4.42"), version="1.2.3.4", raw_data="I'm a component", modules=["grr_awesome"], token=self.token) return component.summary
def InitFromAff4Object(self, client_obj): self.urn = client_obj.urn self.agent_info = client_obj.Get(client_obj.Schema.CLIENT_INFO) self.hardware_info = client_obj.Get(client_obj.Schema.HARDWARE_INFO) self.os_info = rdf_client.Uname( system=client_obj.Get(client_obj.Schema.SYSTEM), node=client_obj.Get(client_obj.Schema.HOSTNAME), release=client_obj.Get(client_obj.Schema.OS_RELEASE), # TODO(user): Check if ProtoString.Validate should be fixed # to do an isinstance() check on a value. Is simple type # equality check used there for performance reasons? version=utils.SmartStr( client_obj.Get(client_obj.Schema.OS_VERSION, "")), kernel=client_obj.Get(client_obj.Schema.KERNEL), machine=client_obj.Get(client_obj.Schema.ARCH), fqdn=client_obj.Get(client_obj.Schema.FQDN), install_date=client_obj.Get(client_obj.Schema.INSTALL_DATE)) self.first_seen_at = client_obj.Get(client_obj.Schema.FIRST_SEEN) self.last_seen_at = client_obj.Get(client_obj.Schema.PING) self.last_booted_at = client_obj.Get(client_obj.Schema.LAST_BOOT_TIME) self.last_clock = client_obj.Get(client_obj.Schema.CLOCK) last_crash = client_obj.Get(client_obj.Schema.LAST_CRASH) if last_crash is not None: self.last_crash_at = last_crash.timestamp self.labels = client_obj.GetLabels() self.interfaces = client_obj.Get(client_obj.Schema.LAST_INTERFACES) kb = client_obj.Get(client_obj.Schema.KNOWLEDGE_BASE) self.users = kb and kb.users or [] self.volumes = client_obj.Get(client_obj.Schema.VOLUMES) return self
def GetPlatformInfo(self, _): self.response_count += 1 return [rdf_client.Uname(system=self.system, node="test_node", release="5", version=self.version, kernel=self.kernel, machine="i386")]
def InitFromClientObject(self, client_obj): # TODO(amoser): Deprecate all urns. self.urn = client_obj.client_id self.client_id = client_obj.client_id self.agent_info = client_obj.startup_info.client_info self.hardware_info = client_obj.hardware_info os_info = rdf_client.Uname() if client_obj.os_version: os_info.version = client_obj.os_version if client_obj.os_release: os_info.release = client_obj.os_release if client_obj.kernel: os_info.kernel = client_obj.kernel if client_obj.arch: os_info.machine = client_obj.arch if client_obj.install_time: os_info.install_date = client_obj.install_time kb = client_obj.knowledge_base if kb: self.knowledge_base = kb if kb.os: os_info.system = kb.os if kb.fqdn: os_info.fqdn = kb.fqdn # TODO(amoser): Deprecate this field in favor of the kb. if kb.users: self.users = sorted(kb.users, key=lambda user: user.username) self.os_info = os_info if client_obj.interfaces: self.interfaces = client_obj.interfaces if client_obj.volumes: self.volumes = client_obj.volumes if client_obj.cloud_instance: self.cloud_instance = client_obj.cloud_instance # TODO(amoser): This should be removed in favor of a timestamp field. # Without self.Set self.age would reference "age" attribute instead of a # protobuf field. self.Set("age", client_obj.timestamp) if client_obj.memory_size: self.memory_size = client_obj.memory_size if client_obj.startup_info.boot_time: self.last_booted_at = client_obj.startup_info.boot_time return self
def InitFromAff4Object(self, client_obj): self.urn = client_obj.urn self.client_id = self.urn.Basename() self.agent_info = client_obj.Get(client_obj.Schema.CLIENT_INFO) self.hardware_info = client_obj.Get(client_obj.Schema.HARDWARE_INFO) self.os_info = rdf_client.Uname( system=client_obj.Get(client_obj.Schema.SYSTEM), release=client_obj.Get(client_obj.Schema.OS_RELEASE), # TODO(user): Check if ProtoString.Validate should be fixed # to do an isinstance() check on a value. Is simple type # equality check used there for performance reasons? version=utils.SmartStr( client_obj.Get(client_obj.Schema.OS_VERSION, "")), kernel=client_obj.Get(client_obj.Schema.KERNEL), machine=client_obj.Get(client_obj.Schema.ARCH), fqdn=(client_obj.Get(client_obj.Schema.FQDN) or client_obj.Get(client_obj.Schema.HOSTNAME)), install_date=client_obj.Get(client_obj.Schema.INSTALL_DATE)) self.knowledge_base = client_obj.Get(client_obj.Schema.KNOWLEDGE_BASE) self.memory_size = client_obj.Get(client_obj.Schema.MEMORY_SIZE) self.first_seen_at = client_obj.Get(client_obj.Schema.FIRST_SEEN) self.last_seen_at = client_obj.Get(client_obj.Schema.PING) self.last_booted_at = client_obj.Get(client_obj.Schema.LAST_BOOT_TIME) self.last_clock = client_obj.Get(client_obj.Schema.CLOCK) last_crash = client_obj.Get(client_obj.Schema.LAST_CRASH) if last_crash is not None: self.last_crash_at = last_crash.timestamp self.labels = [ objects.ClientLabel(name=l.name, owner=l.owner) for l in client_obj.GetLabels() ] self.interfaces = client_obj.Get(client_obj.Schema.INTERFACES) kb = client_obj.Get(client_obj.Schema.KNOWLEDGE_BASE) self.users = kb and kb.users or [] self.volumes = client_obj.Get(client_obj.Schema.VOLUMES) type_obj = client_obj.Get(client_obj.Schema.TYPE) if type_obj: # Without self.Set self.age would reference "age" attribute instead of a # protobuf field. self.Set("age", type_obj.age) self.cloud_instance = client_obj.Get(client_obj.Schema.CLOUD_INSTANCE) return self
def VFSGRRClientToApiClient(client_obj): # TODO(user): Check if ProtoString.Validate should be fixed # to do an isinstance() check on a value. Is simple type # equality check used there for performance reasons? os_version = client_obj.Get(client_obj.Schema.OS_VERSION, "") if os_version is not None: os_version = utils.SmartStr(os_version) last_crash_at = None crash = client_obj.Get(client_obj.Schema.LAST_CRASH) if crash is not None: last_crash_at = crash.timestamp kb = client_obj.Get(client_obj.Schema.KNOWLEDGE_BASE) users = [] if kb: users = kb.users return ApiClient( urn=client_obj.urn, agent_info=client_obj.Get(client_obj.Schema.CLIENT_INFO), hardware_info=client_obj.Get(client_obj.Schema.HARDWARE_INFO), os_info=rdf_client.Uname( system=client_obj.Get(client_obj.Schema.SYSTEM), node=client_obj.Get(client_obj.Schema.HOSTNAME), release=client_obj.Get(client_obj.Schema.OS_RELEASE), version=os_version, kernel=client_obj.Get(client_obj.Schema.KERNEL), machine=client_obj.Get(client_obj.Schema.ARCH), fqdn=client_obj.Get(client_obj.Schema.FQDN), install_date=client_obj.Get(client_obj.Schema.INSTALL_DATE)), first_seen_at=client_obj.Get(client_obj.Schema.FIRST_SEEN), last_seen_at=client_obj.Get(client_obj.Schema.PING), last_booted_at=client_obj.Get(client_obj.Schema.LAST_BOOT_TIME), last_clock=client_obj.Get(client_obj.Schema.CLOCK), last_crash_at=last_crash_at, labels=client_obj.GetLabels(), interfaces=client_obj.Get(client_obj.Schema.LAST_INTERFACES), users=users, volumes=client_obj.Get(client_obj.Schema.VOLUMES))