async def create_source(self, report): def add_fact(fact_list, trait, value): fact_list.append(Fact(trait, value, collected_by='pathfinder')) return fact_list[-1:][0] if not report: return None facts = [] relationships = [] for host in report.hosts.values(): ip_fact = add_fact(facts, 'scan.host.ip', host.ip) if host.hostname: relationships.append( Relationship( ip_fact, 'has_hostname', add_fact(facts, 'scan.host.hostname', host.hostname), ) ) for num, port in host.ports.items(): port_fact = add_fact(facts, 'scan.host.port', num) for cve_ in port.cves: cve_fact = add_fact(facts, 'scan.found.cve', cve_) relationships.append( Relationship(ip_fact, 'has_vulnerability', cve_fact) ) relationships.append( Relationship(port_fact, 'has_vulnerability', cve_fact) ) source = Source(report.id, report.name, facts, relationships) source.access = BaseWorld.Access.RED await self.data_svc.store(source) return source
async def _load_sources(self, plugin): for filename in glob.iglob('%s/sources/*.yml' % plugin.data_dir, recursive=False): for src in self.strip_yml(filename): source = Source( identifier=src['id'], name=src['name'], facts=[Fact(trait=f['trait'], value=str(f['value'])) for f in src.get('facts')], adjustments=await self._create_adjustments(src.get('adjustments')), rules=[Rule(**r) for r in src.get('rules', [])] ) source.access = plugin.access await self.store(source)