(self, dork, pages=1, resource='host')
| 66 | logger.error(str(ex)) |
| 67 | |
| 68 | def search(self, dork, pages=1, resource='host'): |
| 69 | if resource == 'host': |
| 70 | resource = 'protocol,ip,port' |
| 71 | else: |
| 72 | resource = 'protocol,host' |
| 73 | |
| 74 | dork = b64encode(dork.encode()).decode() |
| 75 | search_result = set() |
| 76 | |
| 77 | try: |
| 78 | for page in range(1, pages + 1): |
| 79 | time.sleep(1) |
| 80 | url = ( |
| 81 | f"{self.api_url}/search/all?email={self.user}&key={self.token}&qbase64={dork}&" |
| 82 | f"fields={resource}&page={page}" |
| 83 | ) |
| 84 | resp = requests.get(url, headers=self.headers, timeout=60) |
| 85 | if resp and resp.status_code == 200 and "results" in resp.json(): |
| 86 | content = resp.json() |
| 87 | for match in content['results']: |
| 88 | if resource == "protocol,ip,port": |
| 89 | ip = match[1] |
| 90 | if is_ipv6_address_format(ip): |
| 91 | ip = f'[{ip}]' |
| 92 | search_result.add("%s://%s:%s" % (match[0], ip, match[2])) |
| 93 | else: |
| 94 | if '://' not in match[1]: |
| 95 | search_result.add("%s://%s" % (match[0], match[1])) |
| 96 | else: |
| 97 | search_result.add(match[1]) |
| 98 | else: |
| 99 | logger.error("[PLUGIN] Fofa:{}".format(resp.text)) |
| 100 | except Exception as ex: |
| 101 | logger.error(str(ex)) |
| 102 | return search_result |
| 103 | |
| 104 | |
| 105 | if __name__ == "__main__": |
no test coverage detected