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

Code before:
        coHosts = set()

        if eventName == "DOMAIN_NAME":
            rrsetRecords = self.query("rrset", "name", eventData)
            if rrsetRecords is None:
                return None

            for record in rrsetRecords:
                record = record.get("obj")
                if self.checkForStop():
                    return None

                if self.isTooOld(record.get("time_last")):
                    continue

                if record.get("rrtype") not in (
                    "A",
                    "AAAA",
                    "MX",
                    "NS",
                    "TXT",
                    "CNAME",
                ):
                    continue

                self.emit("RAW_RIR_DATA", str(record), event)
                for data in record.get("rdata"):
                    data = data.rstrip(".")
                    if data in responseData:
                        continue
                    responseData.add(data)

                    if record.get("rrtype") == "A":
                        if not self.sf.validIP(data):
                            self.sf.debug(f"Skipping invalid IP address {data}")
                            continue

                        if self.opts["verify"] and not self.sf.validateIP(
                            eventData, data
                        ):
                            self.sf.debug(
                                f"Host {eventData} no longer resolves to {data}"
                            )
                            continue

                        if not self.getTarget().matches(data):
                            coHosts.add(data)

                        evt = self.emit("IP_ADDRESS", data, event, False)

                    if record.get("rrtype") == "AAAA":

Review comment (suggestion):
`RAW_RIR_DATA` should only be sent once, representing the full contents of the API call, not for every record returned from a single API call.

Code after:
        self.results[eventData] = True

        responseData = set()
        coHosts = set()

        if eventName == "DOMAIN_NAME":
            rrsetRecords = self.query("rrset", "name", eventData)
            if rrsetRecords is None:
                return None

            self.emit("RAW_RIR_DATA", str(rrsetRecords), event)

            for record in rrsetRecords:
                record = record.get("obj")
                if self.checkForStop():
                    return None

                if self.isTooOld(record.get("time_last", 0)):
                    continue

                if record.get("rrtype") not in (
                    "A",
                    "AAAA",
                    "MX",
                    "NS",
                    "TXT",
                    "CNAME",
                ):
                    continue

                for data in record.get("rdata"):
                    data = data.rstrip(".")
                    if data in responseData:
                        continue
                    responseData.add(data)

                    if record.get("rrtype") == "A":
                        if not self.sf.validIP(data):
                            self.sf.debug(f"Skipping invalid IP address {data}")
                            continue

                        if self.opts["verify"] and not self.sf.validateIP(
                            eventData, data
                        ):
                            self.sf.debug(
                                f"Host {eventData} no longer resolves to {data}"
                            )
                            continue

                        if not self.getTarget().matches(data):
                            coHosts.add(data)