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

Code before:

class sfp_dnsdumpster(SpiderFootPlugin):

    meta = {
        "name": "DNSDumpster",
        "summary": "Passive subdomain enumeration using HackerTarget's DNSDumpster",
        "useCases": ["Investigate", "Footprint", "Passive"],
        "categories": ["Passive DNS"],
        "dataSource": {
            "website": "https://dnsdumpster.com/",
            "model": "FREE_NOAUTH_UNLIMITED",
            "description": "DNSdumpster.com is a FREE domain research tool that can discover hosts related to a domain.",
        }
    }

    # Default options
    opts = {}

    # Option descriptions
    optdescs = {}

    def setup(self, sfc, userOpts=dict()):
        self.sf = sfc
        self.sf.debug("Setting up sfp_dnsdumpster")
        self.state = self.tempStorage()
        self.state.update({
            "events": [],
        })
        self.__dataSource__ = "DNS"

        self.opts.update(userOpts)

    def watchedEvents(self):
        return ["DOMAIN_NAME"]

    def producedEvents(self):
        return ["INTERNET_NAME", "INTERNET_NAME_UNRESOLVED"]

    def query(self, domain):
        ret = []
        # first, get the CSRF tokens
        url = "https://dnsdumpster.com"
        res1 = self.sf.fetchUrl(
            url,
            useragent=self.opts.get("_useragent", "Spiderfoot")
        )
        if res1["code"] not in ["200"]:
            self.sf.error(f"Bad response code \"{res1['code']}\" from DNSDumpster")
        else:
            self.sf.debug(f"Valid response code \"{res1['code']}\" from DNSDumpster")
        html = BeautifulSoup(str(res1["content"]), features="lxml")

Review comment (suggestion):
I like the approach taken here but for now can you make this consistent with all other modules (using `self.results`)? We'll move to a better state management approach later on.

Code after:

class sfp_dnsdumpster(SpiderFootPlugin):

    meta = {
        "name": "DNSDumpster",
        "summary": "Passive subdomain enumeration using HackerTarget's DNSDumpster",
        "useCases": ["Investigate", "Footprint", "Passive"],
        "categories": ["Passive DNS"],
        "dataSource": {
            "website": "https://dnsdumpster.com/",
            "model": "FREE_NOAUTH_UNLIMITED",
            "description": "DNSdumpster.com is a FREE domain research tool that can discover hosts related to a domain.",
        }
    }

    # Default options
    opts = {}

    # Option descriptions
    optdescs = {}

    def setup(self, sfc, userOpts=dict()):
        self.sf = sfc
        self.sf.debug("Setting up sfp_dnsdumpster")
        self.results = self.tempStorage()
        self.opts.update(userOpts)

    def watchedEvents(self):
        return ["DOMAIN_NAME", "INTERNET_NAME"]

    def producedEvents(self):
        return ["INTERNET_NAME", "INTERNET_NAME_UNRESOLVED"]

    def query(self, domain):
        ret = []
        # first, get the CSRF tokens
        url = "https://dnsdumpster.com"
        res1 = self.sf.fetchUrl(
            url,
            useragent=self.opts.get("_useragent", "Spiderfoot")
        )
        if res1["code"] not in ["200"]:
            self.sf.error(f"Bad response code \"{res1['code']}\" from DNSDumpster")
        else:
            self.sf.debug(f"Valid response code \"{res1['code']}\" from DNSDumpster")
        html = BeautifulSoup(str(res1["content"]), features="lxml")
        csrftoken = None
        csrfmiddlewaretoken = None
        try:
            for cookie in res1["headers"].get("set-cookie", "").split(";"):
                k, v = cookie.split('=', 1)