Esempio n. 1
0
 def shodan(self):
     """
     connect to the API and grab all IP addresses associated with the provided query
     """
     start_animation("searching Shodan with given query '{}'".format(
         self.query))
     discovered_shodan_hosts = set()
     try:
         req = requests.get(API_URLS["shodan"].format(query=self.query,
                                                      token=self.token),
                            proxies=self.proxy,
                            headers=self.user_agent)
         json_data = json.loads(req.content)
         for match in json_data["matches"]:
             discovered_shodan_hosts.add(match["ip_str"])
         write_to_file(discovered_shodan_hosts, self.host_file)
         return True
     except Exception as e:
         raise AutoSploitAPIConnectionError(str(e))
Esempio n. 2
0
 def search(self):
     """
     connect to the API and pull all the IP addresses that are associated with the
     given query
     """
     start_animation("searching ZoomEye with given query '{}'".format(
         self.query))
     discovered_zoomeye_hosts = set()
     try:
         token = self.__get_auth()
         if self.user_agent is None:
             headers = {
                 "Authorization":
                 "JWT {}".format(str(token["access_token"]))
             }
         else:
             headers = {
                 "Authorization":
                 "JWT {}".format(str(token["access_token"])),
                 "User-Agent": self.user_agent["User-Agent"]  # oops
             }
         params = {"query": self.query, "page": "1", "facet": "ipv4"}
         req = requests.get(API_URLS["zoomeye"][1].format(query=self.query),
                            params=params,
                            headers=headers,
                            proxies=self.proxy)
         _json_data = req.json()
         for item in _json_data["matches"]:
             if len(item["ip"]) > 1:
                 for ip in item["ip"]:
                     discovered_zoomeye_hosts.add(ip)
             else:
                 discovered_zoomeye_hosts.add(str(item["ip"][0]))
         write_to_file(discovered_zoomeye_hosts,
                       self.host_file,
                       mode=self.save_mode)
         return True
     except Exception as e:
         raise AutoSploitAPIConnectionError(str(e))