Beispiel #1
0
    def wiener(self):
        # this attack module can be optional based on sympy and wiener_attack.py existing
        try:
            from wiener_attack import WienerAttack
        except ImportError:
            print("[!] Warning: Wiener attack module missing (wiener_attack.py) or SymPy not installed?")
            return

        # Wiener's attack
        wiener = WienerAttack(self.pub_key.n, self.pub_key.e)
        if wiener.p is not None and wiener.q is not None:
            self.pub_key.p = wiener.p
            self.pub_key.q = wiener.q
            self.priv_key = PrivateKey(int(self.pub_key.p), int(self.pub_key.q),
                                       int(self.pub_key.e), int(self.pub_key.n))

        return
Beispiel #2
0
    def wiener(self):
        # this attack module can be optional
        try:
            from wiener_attack import WienerAttack
        except ImportError:
            if self.args.verbose:
                print "[*] Warning: Wiener attack module missing (wiener_attack.py)"
            return

        # Wiener's attack
        wiener = WienerAttack(self.pub_key.n, self.pub_key.e)
        if wiener.p is not None and wiener.q is not None:
            self.pub_key.p = wiener.p
            self.pub_key.q = wiener.q
            self.priv_key = PrivateKey(long(self.pub_key.p), long(self.pub_key.q),
                                       long(self.pub_key.e), long(self.pub_key.n))

        return
Beispiel #3
0
    def wiener(self):
        # this attack module can be optional based on sympy and wiener_attack.py existing
        try:
            from wiener_attack import WienerAttack
        except ImportError:
            if self.args.verbose:
                print(
                    "[!] Warning: Wiener attack module missing (wiener_attack.py) or SymPy not installed?"
                )
            return

        # Wiener's attack
        wiener = WienerAttack(self.pub_key.n, self.pub_key.e)
        if wiener.p is not None and wiener.q is not None:
            self.pub_key.p = wiener.p
            self.pub_key.q = wiener.q
            self.priv_key = PrivateKey(int(self.pub_key.p),
                                       int(self.pub_key.q),
                                       int(self.pub_key.e),
                                       int(self.pub_key.n))

        print("\t[+] Performing Alternative Weiner Attack")
        key_data = self.wiener_alt(self.pub_key.n, self.pub_key.e)
        if key_data is not None:
            key = RSA.importKey(key_data)
            print("[*] n: " + str(self.pub_key.n))
            print("[*] e: " + str(self.pub_key.e))
            print("[*] d: " + str(key.d))
            print("[*] p: " + str(key.p))
            self.pub_key.p = key.p
            print("[*] q: " + str(key.q))
            self.pub_key.q = key.q
            self.priv_key = PrivateKey(int(self.pub_key.p),
                                       int(self.pub_key.q),
                                       int(self.pub_key.e),
                                       int(self.pub_key.n))

        return
Beispiel #4
0
            try:
                pub_key.prime_factors()
                priv_key = PrivateKey(long(pub_key.p), long(pub_key.q),
                                      long(pub_key.e), long(pub_key.n))

                if args.uncipher is not None:
                    unciphered = priv_key.decrypt(cipher)
            except FactorizationError:
                unciphered = None

        if unciphered is None and priv_key is None:
            if args.verbose:
                print "Try Wiener's attack"

            # Wiener's attack
            wiener = WienerAttack(pub_key.n, pub_key.e)
            if wiener.p is not None and wiener.q is not None:
                pub_key.p = wiener.p
                pub_key.q = wiener.q
                priv_key = PrivateKey(long(pub_key.p), long(pub_key.q),
                                      long(pub_key.e), long(pub_key.n))

                if args.uncipher is not None:
                    unciphered = priv_key.decrypt(cipher)
    # user define p,q,e,n
    elif unciphered is None and priv_key is None:
        if args.verbose:
            print "Crack with p,q"

        pqne_list = args.pqne.split(',')
        nump = long(pqne_list[0])