Exemplo n.º 1
0
    def attack(self, publickey, cipher=[], progress=True):
        if is_roca_vulnerable(publickey.n):
            try:
                sageresult = subprocess.check_output(
                    [
                        "sage",
                        "%s/sage/roca_attack.py" % rootpath,
                        str(publickey.n)
                    ],
                    timeout=self.timeout,
                    stderr=subprocess.DEVNULL,
                )

            except (subprocess.CalledProcessError, subprocess.TimeoutExpired):
                return (None, None)

            if b"FAIL" not in sageresult and b":" in sageresult:
                sageresult = sageresult.decode("utf-8").strip()
                p, q = map(int, sageresult.split(":"))
                priv_key = PrivateKey(int(p), int(q), int(publickey.e),
                                      int(publickey.n))
                return (priv_key, None)
            else:
                return (None, None)
        else:
            self.logger.info("[-] This key is not roca, skiping test...")
            return (None, None)
Exemplo n.º 2
0
 def attack(self, publickey, cipher=[], progress=True):
     if is_roca_vulnerable(publickey.n):
         if getpubkeysz(publickey.n) <= 512:
             necaresult = subprocess.check_output(
                 ["neca", "%s" % publickey.n],
                 timeout=self.timeout,
                 stderr=subprocess.DEVNULL,
             )
             necaresult_l = necaresult.decode("utf8").split("\n")
             if b"FAIL" not in necaresult and b"*" in necaresult:
                 for line in necaresult_l:
                     r0 = line.find("N = ")
                     r1 = line.find(" * ")
                     if r0 > -1 and r1 > -1:
                         p, q = list(map(int, line.split("=")[1].split("*")))
                         priv_key = PrivateKey(
                             int(p), int(q), int(publickey.e), int(publickey.n)
                         )
                         return (priv_key, None)
             else:
                 return (None, None)
         else:
             self.logger.info(
                 "[-] This key is roca but > 512 bits, try with roca attack..."
             )
             return (None, None)
     else:
         self.logger.info("[-] This key is not roca, skiping test...")
         return (None, None)
Exemplo n.º 3
0
                        pub_key, priv_key = generate_keys_from_p_q_e_n(None, None, e, n)
                        print(pub_key.decode("utf-8"))
        exit(0)

    if args.isroca:
        pubkeyfilelist = glob(args.publickey)
        for publickey in pubkeyfilelist:
            logger.info("[-] Details for %s:" % publickey)
            with open(publickey, "rb") as key_data_fd:
                try:
                    key = RSA.importKey(key_data_fd.read())
                except:
                    key = None
                    logger.error("[!] Error file format: %s" % publickey)
                if key is not None:
                    if is_roca_vulnerable(key.n):
                        logger.warning("[!] Public key %s: is roca!!!" % publickey)
                    else:
                        logger.info(
                            "[-] Public key %s: is not roca, you are safe" % publickey
                        )
        exit(0)

    # Create pubkey if requested
    if args.createpub:
        pub_key, priv_key = generate_keys_from_p_q_e_n(args.p, args.q, args.e, args.n)
        print(pub_key.decode("utf-8"))
        exit(0)

    # Load keys
    tmpfile = None