Exemplo n.º 1
0
    def attack_single_key(self, publickey, attacks_list=[], test=False):
        """Run attacks on single keys"""

        if len(attacks_list) == 0:
            self.args.attack = "all"

        self.load_attacks(attacks_list)
        if test:
            for attack in self.implemented_attacks:
                self.logger.info("[*] Testing %s" % attack.get_name())
                try:
                    try:
                        if attack.test():
                            self.logger.info("[*] Success")
                        else:
                            self.logger.error("[!] Failure")
                    except NotImplementedError:
                        self.logger.warning("[!] Test not implemented")
                except Exception:
                    self.logger.error("[!] Failure")
            exit(0)

        # Read keyfile
        with open(publickey, "rb") as pubkey_fd:
            self.publickey = PublicKey(pubkey_fd.read(), publickey)

        # Read n/e from publickey file
        if not self.args.n or not self.args.e:
            self.args.n = self.publickey.n
            self.args.e = self.publickey.e

        # Loop through implemented attack methods and conduct attacks
        for attack_module in self.implemented_attacks:
            self.logger.info(
                "[*] Performing %s attack on %s." %
                (attack_module.get_name(), self.publickey.filename))
            try:
                if not attack_module.can_run():
                    continue

                self.priv_key, unciphered = attack_module.attack(
                    self.publickey, self.cipher)
                if unciphered is not None and unciphered is not []:
                    if isinstance(unciphered, list):
                        self.unciphered = self.unciphered + unciphered
                    else:
                        self.unciphered.append(unciphered)
                if self.can_stop_tests():
                    break
            except FactorizationError:
                self.logger.warning("Timeout")

        self.print_results_details(publickey)
        if self.args.sendtofdb == True:
            if self.priv_key != None:
                send2fdb(self.priv_key.n, [self.priv_key.p, self.priv_key.q])
        return self.get_boolean_results()
Exemplo n.º 2
0
 def priv_key_send2fdb(self):
     if self.args.sendtofdb == True:
         if self.priv_key is not None:
             if type(self.priv_key) is PrivateKey:
                 send2fdb(self.priv_key.n, [self.priv_key.p, self.priv_key.q])
             else:
                 if len(self.priv_key) > 0:
                     for privkey in list(set(self.priv_key)):
                         send2fdb(privkey.n, [privkey.p, privkey.q])
Exemplo n.º 3
0
    def attack_multiple_keys(self, publickeys, attacks_list):
        """Run attacks on multiple keys"""
        self.logger.info("[*] Multikey mode using keys: " +
                         ", ".join(publickeys))
        self.load_attacks(attacks_list, multikeys=True)

        # Read keyfiles
        publickeys_obj = []
        for publickey in publickeys:
            try:
                with open(publickey, "rb") as pubkey_fd:
                    publickeys_obj.append(
                        PublicKey(pubkey_fd.read(), publickey))
            except Exception:
                self.logger.error("[*] Key format not supported : %s." %
                                  publickey)
                continue

        if len(publickeys_obj) == 0:
            self.logger.error("No key loaded.")
            exit(1)

        self.publickey = publickeys_obj
        self.pre_check_attack(self.publickeys)
        # Loop through implemented attack methods and conduct attacks
        for attack_module in self.implemented_attacks:
            if isinstance(self.publickey, list):
                self.logger.info("[*] Performing %s attack." %
                                 attack_module.get_name())
                try:
                    if not attack_module.can_run():
                        continue

                    self.priv_key, unciphered = attack_module.attack(
                        self.publickey, self.cipher)

                    if unciphered is not None and unciphered is not []:
                        if isinstance(unciphered, list):
                            self.unciphered = self.unciphered + unciphered
                        else:
                            self.unciphered.append(unciphered)
                    if self.can_stop_tests():
                        self.logger.info(
                            f"[*] Attack success with {attack_module.get_name()} method !"
                        )
                        break
                except FactorizationError:
                    self.logger.warning("Timeout")

        public_key_name = ",".join(publickeys)
        self.print_results_details(public_key_name)
        if self.args.sendtofdb == True:
            if len(self.priv_key) > 0:
                for privkey in list(set(self.priv_key)):
                    send2fdb(privkey.n, [privkey.p, privkey.q])
        return self.get_boolean_results()
Exemplo n.º 4
0
    def attack_single_key(self, publickey, attacks_list=[]):
        """Run attacks on single keys"""

        if len(attacks_list) == 0:
            self.args.attack = "all"

        self.load_attacks(attacks_list)

        # Read keyfile
        with open(publickey, "rb") as pubkey_fd:
            self.publickey = PublicKey(pubkey_fd.read(), publickey)

        # Read n/e from publickey file
        if not self.args.n or not self.args.e:
            self.args.n = self.publickey.n
            self.args.e = self.publickey.e

        # Loop through implemented attack methods and conduct attacks
        for attack_module in self.implemented_attacks:
            self.logger.info(
                "[*] Performing %s attack on %s."
                % (attack_module.__name__.split(".")[-1], self.publickey.filename)
            )
            try:
                self.priv_key, unciphered = attack_module.attack(
                    self, self.publickey, self.cipher
                )
                if unciphered is not None and unciphered is not []:
                    if isinstance(unciphered, list):
                        self.unciphered = self.unciphered + unciphered
                    else:
                        self.unciphered.append(unciphered)
                if self.can_stop_tests():
                    break
            except FactorizationError:
                self.logger.warning("Timeout")

        self.print_results_details(publickey)
        if self.args.sendtofdb == True:
            if self.priv_key != None:
                send2fdb(self.priv_key.n, [self.priv_key.p, self.priv_key.q])
        return self.get_boolean_results()