Repository: smicallef/spiderfoot
File: modules/sfp_leakix.py (Python)

Code before:
            if eventName == "IP_ADDRESS":
                data = self.queryApi("host", eventData)
            if eventName == "DOMAIN_NAME":
                data = self.queryApi("domain", eventData)

            if data is None:
                self.sf.debug("No information found for host " + eventData)
                return None

            evt = SpiderFootEvent('RAW_RIR_DATA', str(data), self.__name__, event)
            self.notifyListeners(evt)

            services = data.get("Services")

            if services:
                for service in services:
                    ip = service.get('ip')
                    if ip and eventName != "IP_ADDRESS":
                        evt = SpiderFootEvent("IP_ADDRESS", ip, self.__name__, event)
                        self.notifyListeners(evt)
                    port = service.get('port')
                    if port:
                        evt = SpiderFootEvent("TCP_PORT_OPEN", eventData + ':' + port, self.__name__, event)
                        self.notifyListeners(evt)
                    hostname = service.get('hostname')
                    if hostname and eventName == "DOMAIN_NAME" and hostname.endswith(eventData):
                        evt = SpiderFootEvent("INTERNET_NAME", hostname, self.__name__, event)
                        self.notifyListeners(evt)
                    headers = service.get('headers')
                    if headers:
                        servers = headers.get('Server')
                        if servers:
                            for server in servers:
                                if server:
                                    evt = SpiderFootEvent('WEBSERVER_BANNER', server, self.__name__, event)
                                    self.notifyListeners(evt)

                    geoip = service.get('geoip')
                    if geoip:
                        location = ', '.join([_f for _f in [geoip.get('city_name'), geoip.get('region_name'), geoip.get('country_name')] if _f])
                        if location:
                            evt = SpiderFootEvent("GEOINFO", location, self.__name__, event)
                            self.notifyListeners(evt)

                    software = service.get('software')
                    if software:
                        software_version = ' '.join([_f for _f in [software.get('name'), software.get('version')] if _f])
                        if software_version:
                            evt = SpiderFootEvent("SOFTWARE_USED", software_version, self.__name__, event)
                            self.notifyListeners(evt)


Review comment (suggestion):
Instead of `.endswith()` you should use `self.getTarget().matches()` as other modules do when verifying if a host is within the target scope.

Code after:

        if eventName in ["IP_ADDRESS", "DOMAIN_NAME"]:
            if eventName == "IP_ADDRESS":
                data = self.queryApi("host", eventData)
            if eventName == "DOMAIN_NAME":
                data = self.queryApi("domain", eventData)

            if data is None:
                self.sf.debug("No information found for host " + eventData)
                return None

            evt = SpiderFootEvent('RAW_RIR_DATA', str(data), self.__name__, event)
            self.notifyListeners(evt)

            services = data.get("Services")

            if services:
                for service in services:
                    ip = service.get('ip')
                    if ip and eventName != "IP_ADDRESS" and self.sf.validIP(ip):
                        evt = SpiderFootEvent("IP_ADDRESS", ip, self.__name__, event)
                        self.notifyListeners(evt)
                    port = service.get('port')
                    if port:
                        evt = SpiderFootEvent("TCP_PORT_OPEN", eventData + ':' + port, self.__name__, event)
                        self.notifyListeners(evt)
                    hostname = service.get('hostname')
                    if hostname and eventName == "DOMAIN_NAME" and self.getTarget().matches(hostname):
                        if self.opts["verify"] and not self.sf.resolveHost(hostname):
                            self.sf.debug(f"Host {hostname} could not be resolved")
                            evt = SpiderFootEvent("INTERNET_NAME_UNRESOLVED", hostname, self.__name__, event)
                        else:
                            evt = SpiderFootEvent("INTERNET_NAME", hostname, self.__name__, event)
                        self.notifyListeners(evt)
                    headers = service.get('headers')
                    if headers:
                        servers = headers.get('Server')
                        if servers:
                            for server in servers:
                                if server:
                                    evt = SpiderFootEvent('WEBSERVER_BANNER', server, self.__name__, event)
                                    self.notifyListeners(evt)

                    geoip = service.get('geoip')
                    if geoip:
                        location = ', '.join([_f for _f in [geoip.get('city_name'), geoip.get('region_name'), geoip.get('country_name')] if _f])
                        if location:
                            evt = SpiderFootEvent("GEOINFO", location, self.__name__, event)
                            self.notifyListeners(evt)

                    software = service.get('software')