Exemple #1
0
class Core:

    def __init__(self, inputfile, phishtank, openphish, cleanmx, output, alivecheck, emailnotifiers):
        logging.debug("Instantiating the '%s' class" % (self.__class__.__name__))

        self._inputfile = inputfile
        self._phishtank = phishtank
        self._openphish = openphish
        self._cleanmx = cleanmx
        self._output = output
        self._alivecheck = alivecheck
        self._emailnotifiers = emailnotifiers

        check_passed = CheckDependencies.run()
        if not check_passed:
            exit()
        else:
            self._cfg = ConfigReader.run()

            if not self._inputfile:
                self._downloader = Downloader(self._cfg, self._phishtank, self._openphish, self._cleanmx)
                self._extractor = Extractor(self._cfg, self._phishtank, self._openphish, self._cleanmx)
                
            if self._alivecheck:
                AliveChecker.config = self._cfg

            if 'json' in self._output:
                JSONAdapter.config = self._cfg
            if 'csv' in self._output:
                CSVAdapter.config = self._cfg
            if 'xml' in self._output:
                XMLAdapter.config = self._cfg

            if self._emailnotifiers:
                EmailNotifiers.config = self._cfg

    def run(self):
        print("Running...")

        if not self._inputfile:
            self._downloader.run()
            ph_ws = self._extractor.run()
        else:
            logging.debug("Reading possible phishing website from '%s'" % (self._inputfile))

            fp = open(self._inputfile, 'rb')
            lines = fp.readlines()
            logging.debug(lines)
            fp.close()
         
            ph_ws = dict()
            cm_elems = []
            for line in lines:
                cm_elem = dict()
                cm_elem['domain'] = line.replace('\n','')
                cm_elem['url'] = line.replace('\n','')
                cm_elem['ip'] = 'n.d.'
                cm_elem['brand'] = 'custom'
                cm_elem['time'] = 'n.d.'
                cm_elem['country'] = 'n.d.'
                cm_elems.append(cm_elem)
            ph_ws['custom'] = cm_elems 

        if self._alivecheck:
            ph_ws = AliveChecker.are_alive(ph_ws)

        if len(ph_ws) > 0:
            if 'json' in self._output:
                JSONAdapter.save_ph_ws(ph_ws)
            if 'csv' in self._output:
                CSVAdapter.save_ph_ws(ph_ws)
            if 'xml' in self._output:
                XMLAdapter.save_ph_ws(ph_ws)

            if self._emailnotifiers:
                EmailNotifiers.notify()
        else:
            logging.debug('Empty phishing_website list')

        print("Done...")