async def load(self) -> None: """Load HassOS data.""" try: if not self.sys_host.info.cpe: raise NotImplementedError() cpe = CPE(self.sys_host.info.cpe) os_name = cpe.get_product()[0] if os_name not in ("hassos", "haos"): raise NotImplementedError() except NotImplementedError: _LOGGER.info("No Home Assistant Operating System found") return # Store meta data self._available = True self.sys_host.supported_features.cache_clear() self._version = AwesomeVersion(cpe.get_version()[0]) self._board = cpe.get_target_hardware()[0] self._os_name = cpe.get_product()[0] await self.sys_dbus.rauc.update() await self.datadisk.load() _LOGGER.info( "Detect Home Assistant Operating System %s / BootSlot %s", self.version, self.sys_dbus.rauc.boot_slot, )
async def load(self) -> None: """Load HassOS data.""" try: if not self.sys_host.info.cpe: raise NotImplementedError() cpe = CPE(self.sys_host.info.cpe) if cpe.get_product()[0] != "hassos": raise NotImplementedError() except NotImplementedError: _LOGGER.debug("Found no HassOS") return else: self._available = True # Store meta data self._version = cpe.get_version()[0] self._board = cpe.get_target_hardware()[0] await self.sys_dbus.rauc.update() _LOGGER.info("Detect HassOS %s / BootSlot %s", self.version, self.sys_dbus.rauc.boot_slot) with suppress(DockerAPIError): await self.instance.attach(tag="latest")
def config_cpe_match(self, cm): if all("$.vulnerable", cm)[0]: v = PLATFORM.VulnerableConfiguration else: v = PLATFORM.NotVulnerableConfiguration subject = BNode() cveStr = all("$.cpe23Uri", cm)[0] self.triples(subject, v, [(PLATFORM.hasPlatform, cpeURI(cveStr))] + \ self.versionStartExcluding(cm) + self.versionStartIncluding(cm) + self.versionEndExcluding(cm) + self.versionEndIncluding(cm)) #print(cveStr) c = CPE(cveStr) if c.is_hardware(): self.g.add((cpeURI(cveStr), RDF.type, PLATFORM.HardwarePlatform)) elif c.is_application(): self.g.add( (cpeURI(cveStr), RDF.type, PLATFORM.ApplicationPlatform)) elif c.is_operating_system(): self.g.add( (cpeURI(cveStr), RDF.type, PLATFORM.OperatingSystemPlatform)) vendor = "" for i in c.get_vendor(): self.g.add((cpeURI(cveStr), PLATFORM.vendor, self.plEnt(i, "Vendor_", cls=PLATFORM.Vendor))) vendor = i for i in c.get_product(): self.g.add((cpeURI(cveStr), PLATFORM.product, self.plEnt(i, "Product_" + vendor + "_", cls=PLATFORM.Product))) for i in c.get_edition(): self.g.add((cpeURI(cveStr), PLATFORM.edition, self.plEnt(i, "Edition_", cls=PLATFORM.Edition))) for i in c.get_language(): self.g.add((cpeURI(cveStr), PLATFORM.language, self.plEnt(i, "Language_", cls=PLATFORM.Language))) for i in c.get_other(): self.g.add((cpeURI(cveStr), PLATFORM.other, self.plEnt(i, "Other_", cls=PLATFORM.Other))) for i in c.get_software_edition(): self.g.add((cpeURI(cveStr), PLATFORM.softwareEdition, self.plEnt(i, "SoftwareEdition_", cls=PLATFORM.SoftwareEdition))) for i in c.get_target_hardware(): self.g.add((cpeURI(cveStr), PLATFORM.targetHardware, self.plEnt(i, "Hardware_", cls=CORE.Hardware))) for i in c.get_target_software(): self.g.add((cpeURI(cveStr), PLATFORM.targetSoftware, self.plEnt(i, "Software_", cls=CORE.Software))) for i in c.get_update(): if not i == "-": self.g.add((cpeURI(cveStr), PLATFORM.update, Literal(i))) for i in c.get_version(): if not i == "-": self.g.add((cpeURI(cveStr), PLATFORM.version, Literal(i))) return subject
async def load(self): """Load HassOS data.""" try: assert self.sys_host.info.cpe is not None cpe = CPE(self.sys_host.info.cpe) assert cpe.get_product()[0] == 'hassos' except (NotImplementedError, IndexError, AssertionError): _LOGGER.info("Can't detect HassOS") return # Store meta data self._available = True self._version = cpe.get_version()[0] self._board = cpe.get_target_hardware()[0] _LOGGER.info("Detect HassOS %s on host system", self.version)
def filter_generic_cpes(cpe_list: List[str]) -> List[str]: ''' This function takes in a list of CPE strings and filters out any CPEs with any specific information past the version number (edition, lang, etc). Returns a new list of CPE strings. ''' filtered_cpes = [] for cpe in cpe_list: c = CPE(cpe) # yapf: disable if (c.get_update()[0] in EMPTY_WILDCARD_CPE_SET and c.get_edition()[0] in EMPTY_WILDCARD_CPE_SET and c.get_language()[0] in EMPTY_WILDCARD_CPE_SET and c.get_software_edition()[0] in EMPTY_WILDCARD_CPE_SET and c.get_target_software()[0] in EMPTY_WILDCARD_CPE_SET and c.get_target_hardware()[0] in EMPTY_WILDCARD_CPE_SET and c.get_other()[0] in EMPTY_WILDCARD_CPE_SET): # yapf: enable filtered_cpes.append(cpe) return filtered_cpes
async def load(self): """Load HassOS data.""" try: # Check needed host functions assert self.sys_dbus.rauc.is_connected assert self.sys_dbus.systemd.is_connected assert self.sys_dbus.hostname.is_connected assert self.sys_host.info.cpe is not None cpe = CPE(self.sys_host.info.cpe) assert cpe.get_product()[0] == 'hassos' except (AssertionError, NotImplementedError): _LOGGER.debug("Ignore HassOS") return # Store meta data self._available = True self._version = cpe.get_version()[0] self._board = cpe.get_target_hardware()[0] _LOGGER.info("Detect HassOS %s on host system", self.version)
async def load(self) -> None: """Load HassOS data.""" try: if not self.sys_host.info.cpe: raise NotImplementedError() cpe = CPE(self.sys_host.info.cpe) if cpe.get_product()[0] != "hassos": raise NotImplementedError() except NotImplementedError: _LOGGER.info("No Home Assistant Operating System found") return else: self._available = True # Store meta data self._version = cpe.get_version()[0] self._board = cpe.get_target_hardware()[0] await self.sys_dbus.rauc.update() _LOGGER.info("Detect HassOS %s / BootSlot %s", self.version, self.sys_dbus.rauc.boot_slot)
async def load(self) -> None: """Load HassOS data.""" try: # Check needed host functions assert self.sys_dbus.rauc.is_connected assert self.sys_dbus.systemd.is_connected assert self.sys_dbus.hostname.is_connected assert self.sys_host.info.cpe is not None cpe = CPE(self.sys_host.info.cpe) assert cpe.get_product()[0] == "hassos" except (AssertionError, NotImplementedError): _LOGGER.debug("Found no HassOS") return # Store meta data self._available = True self._version = cpe.get_version()[0] self._board = cpe.get_target_hardware()[0] _LOGGER.info("Detect HassOS %s on host system", self.version) with suppress(DockerAPIError): await self.instance.attach()
async def load(self) -> None: """Load OppOS data.""" try: if not self.sys_host.info.cpe: raise NotImplementedError() cpe = CPE(self.sys_host.info.cpe) if cpe.get_product()[0] != "oppos": raise NotImplementedError() except NotImplementedError: _LOGGER.info("No Open Peer Power Operating System found") return else: self._available = True self.sys_host.supported_features.cache_clear() # Store meta data self._version = AwesomeVersion(cpe.get_version()[0]) self._board = cpe.get_target_hardware()[0] await self.sys_dbus.rauc.update() _LOGGER.info("Detect OppOS %s / BootSlot %s", self.version, self.sys_dbus.rauc.boot_slot)
def get_cpe_df(self, debug=False): """Get the list of CPE names for the vulnerability. """ type_list = [] part_list = [] vendor_list = [] product_list = [] version_list = [] update_list = [] edition_list = [] language_list = [] sw_edition_list = [] target_sw_list = [] target_hw_list = [] other_list = [] published_datetime_list = [] for cpe_entry in self.cpe_list: #if(debug): #print(cpe_entry) try: cp = CPE(cpe_entry) if(cp.is_hardware()): type_list.append("HW") elif(cp.is_operating_system()): type_list.append("OS") elif(cp.is_application()): type_list.append("APP") else: type_list.append("UNDEFINED") part_list.append(list_to_string(cp.get_part())) vendor_list.append(list_to_string(cp.get_vendor())) product_list.append(list_to_string(cp.get_product())) version_list.append(list_to_string(cp.get_version())) update_list.append(list_to_string(cp.get_update())) edition_list.append(list_to_string(cp.get_edition())) language_list.append(list_to_string(cp.get_language())) sw_edition_list.append(list_to_string(cp.get_software_edition())) target_sw_list.append(list_to_string(cp.get_target_software())) target_hw_list.append(list_to_string(cp.get_target_hardware())) other_list.append(list_to_string(cp.get_other())) published_datetime_list.append(self.published_datetime) except Exception as inst: print(inst) data = pd.DataFrame() data['type'] = type_list data['part'] = part_list data['vendor'] = vendor_list data['product'] = product_list data['version'] = version_list data['update'] = update_list data['edition'] = edition_list data['language'] = language_list data['sw_edition'] = sw_edition_list data['target_sw'] = target_sw_list data['target_hw'] = target_hw_list data['other'] = other_list data['published_datetime'] = published_datetime_list return data