cryptosploit_modules.asymmetric.rsa.rsactftool

View Source
 0from cryptosploit_modules import BaseModule
 1from os.path import join, dirname
 2from sys import path
 3
 4
 5class RsaCtfToolModule(BaseModule):
 6    tool_path = join(dirname(__file__), "RsaCtfTool")
 7    allowed_attack_methods = {
 8        "brent",
 9        "fermat_numbers_gcd",
10        "comfact_cn",
11        "wiener",
12        "factordb",
13        "smallq",
14        "pollard_rho",
15        "euler",
16        "z3_solver",
17        "neca",
18        "cm_factor",
19        "mersenne_pm1_gcd",
20        "SQUFOF",
21        "small_crt_exp",
22        "fibonacci_gcd",
23        "smallfraction",
24        "boneh_durfee",
25        "roca",
26        "fermat",
27        "londahl",
28        "mersenne_primes",
29        "partial_q",
30        "siqs",
31        "noveltyprimes",
32        "binary_polinomial_factoring",
33        "primorial_pm1_gcd",
34        "pollard_p_1",
35        "ecm2",
36        "cube_root",
37        "system_primes_gcd",
38        "dixon",
39        "ecm",
40        "pastctfprimes",
41        "qicheng",
42        "wolframalpha",
43        "hastads",
44        "same_n_huge_e",
45        "commonfactors",
46        "pisano_period",
47        "nsif",
48        "all",
49    }
50
51    def __init__(self):
52        super().__init__()
53        self.env.check_var = self.check_var
54
55    @staticmethod
56    def check_var(name, value):
57        match name:
58            case "mode":
59                if value in RsaCtfToolModule.allowed_attack_methods:
60                    return True, ""
61                return False, "No such attack mode"
62            case "publickey":
63                if "*" in value or RsaCtfToolModule.check_file(value):
64                    return True, ""
65                return False, "No such file"
66            case "n" | "p" | "q" | "e":
67                try:
68                    int(value)
69                except ValueError:
70                    try:
71                        if value.startswith("0x"):
72                            int(value, 16)
73                        else:
74                            return False, "Value must be int or 0xhex"
75                    except ValueError:
76                        return False, "Value must be int or 0xhex"
77                return True, ""
78            case _:
79                return True, ""
80
81    def run(self):
82        flags = set(iter(self.env)) - {"extra_flags"}
83        flags = filter(
84            lambda x: x[1], zip(flags, map(lambda x: self.env.get_var(x).value, flags))
85        )
86        flags = " ".join(
87            map(lambda x: f"{'--' if len(x[0]) > 1 else '-'}{x[0]} {x[1]}", flags)
88        )
89        if extra_flags := self.env.get_var("extra_flags").value:
90            flags = " ".join([flags, extra_flags])
91        self.command_exec(
92            f'python {join(self.tool_path, "RsaCtfTool.py")} {flags}',
93            {"PYTHONPATH": ":".join(path)},
94        )
95
96
97module = RsaCtfToolModule
#   class RsaCtfToolModule(cryptosploit_modules.BaseModule):
View Source
 6class RsaCtfToolModule(BaseModule):
 7    tool_path = join(dirname(__file__), "RsaCtfTool")
 8    allowed_attack_methods = {
 9        "brent",
10        "fermat_numbers_gcd",
11        "comfact_cn",
12        "wiener",
13        "factordb",
14        "smallq",
15        "pollard_rho",
16        "euler",
17        "z3_solver",
18        "neca",
19        "cm_factor",
20        "mersenne_pm1_gcd",
21        "SQUFOF",
22        "small_crt_exp",
23        "fibonacci_gcd",
24        "smallfraction",
25        "boneh_durfee",
26        "roca",
27        "fermat",
28        "londahl",
29        "mersenne_primes",
30        "partial_q",
31        "siqs",
32        "noveltyprimes",
33        "binary_polinomial_factoring",
34        "primorial_pm1_gcd",
35        "pollard_p_1",
36        "ecm2",
37        "cube_root",
38        "system_primes_gcd",
39        "dixon",
40        "ecm",
41        "pastctfprimes",
42        "qicheng",
43        "wolframalpha",
44        "hastads",
45        "same_n_huge_e",
46        "commonfactors",
47        "pisano_period",
48        "nsif",
49        "all",
50    }
51
52    def __init__(self):
53        super().__init__()
54        self.env.check_var = self.check_var
55
56    @staticmethod
57    def check_var(name, value):
58        match name:
59            case "mode":
60                if value in RsaCtfToolModule.allowed_attack_methods:
61                    return True, ""
62                return False, "No such attack mode"
63            case "publickey":
64                if "*" in value or RsaCtfToolModule.check_file(value):
65                    return True, ""
66                return False, "No such file"
67            case "n" | "p" | "q" | "e":
68                try:
69                    int(value)
70                except ValueError:
71                    try:
72                        if value.startswith("0x"):
73                            int(value, 16)
74                        else:
75                            return False, "Value must be int or 0xhex"
76                    except ValueError:
77                        return False, "Value must be int or 0xhex"
78                return True, ""
79            case _:
80                return True, ""
81
82    def run(self):
83        flags = set(iter(self.env)) - {"extra_flags"}
84        flags = filter(
85            lambda x: x[1], zip(flags, map(lambda x: self.env.get_var(x).value, flags))
86        )
87        flags = " ".join(
88            map(lambda x: f"{'--' if len(x[0]) > 1 else '-'}{x[0]} {x[1]}", flags)
89        )
90        if extra_flags := self.env.get_var("extra_flags").value:
91            flags = " ".join([flags, extra_flags])
92        self.command_exec(
93            f'python {join(self.tool_path, "RsaCtfTool.py")} {flags}',
94            {"PYTHONPATH": ":".join(path)},
95        )
#   RsaCtfToolModule()
View Source
52    def __init__(self):
53        super().__init__()
54        self.env.check_var = self.check_var
#   tool_path = '/home/y73n0k/Desktop/smth/projects/cryptosploit/cryptosploit_modules/src/cryptosploit_modules/asymmetric/rsa/rsactftool/RsaCtfTool'
#   allowed_attack_methods = {'pollard_p_1', 'neca', 'cube_root', 'z3_solver', 'small_crt_exp', 'nsif', 'pastctfprimes', 'smallq', 'pisano_period', 'brent', 'comfact_cn', 'ecm', 'fibonacci_gcd', 'binary_polinomial_factoring', 'fermat', 'wiener', 'commonfactors', 'factordb', 'system_primes_gcd', 'siqs', 'primorial_pm1_gcd', 'all', 'hastads', 'roca', 'pollard_rho', 'noveltyprimes', 'londahl', 'partial_q', 'smallfraction', 'fermat_numbers_gcd', 'qicheng', 'ecm2', 'euler', 'dixon', 'same_n_huge_e', 'SQUFOF', 'wolframalpha', 'mersenne_primes', 'mersenne_pm1_gcd', 'cm_factor', 'boneh_durfee'}
#  
@staticmethod
def check_var(name, value):
View Source
56    @staticmethod
57    def check_var(name, value):
58        match name:
59            case "mode":
60                if value in RsaCtfToolModule.allowed_attack_methods:
61                    return True, ""
62                return False, "No such attack mode"
63            case "publickey":
64                if "*" in value or RsaCtfToolModule.check_file(value):
65                    return True, ""
66                return False, "No such file"
67            case "n" | "p" | "q" | "e":
68                try:
69                    int(value)
70                except ValueError:
71                    try:
72                        if value.startswith("0x"):
73                            int(value, 16)
74                        else:
75                            return False, "Value must be int or 0xhex"
76                    except ValueError:
77                        return False, "Value must be int or 0xhex"
78                return True, ""
79            case _:
80                return True, ""
#   def run(self):
View Source
82    def run(self):
83        flags = set(iter(self.env)) - {"extra_flags"}
84        flags = filter(
85            lambda x: x[1], zip(flags, map(lambda x: self.env.get_var(x).value, flags))
86        )
87        flags = " ".join(
88            map(lambda x: f"{'--' if len(x[0]) > 1 else '-'}{x[0]} {x[1]}", flags)
89        )
90        if extra_flags := self.env.get_var("extra_flags").value:
91            flags = " ".join([flags, extra_flags])
92        self.command_exec(
93            f'python {join(self.tool_path, "RsaCtfTool.py")} {flags}',
94            {"PYTHONPATH": ":".join(path)},
95        )

Required to be overridden in the child class. Function called by the user

View Source
 6class RsaCtfToolModule(BaseModule):
 7    tool_path = join(dirname(__file__), "RsaCtfTool")
 8    allowed_attack_methods = {
 9        "brent",
10        "fermat_numbers_gcd",
11        "comfact_cn",
12        "wiener",
13        "factordb",
14        "smallq",
15        "pollard_rho",
16        "euler",
17        "z3_solver",
18        "neca",
19        "cm_factor",
20        "mersenne_pm1_gcd",
21        "SQUFOF",
22        "small_crt_exp",
23        "fibonacci_gcd",
24        "smallfraction",
25        "boneh_durfee",
26        "roca",
27        "fermat",
28        "londahl",
29        "mersenne_primes",
30        "partial_q",
31        "siqs",
32        "noveltyprimes",
33        "binary_polinomial_factoring",
34        "primorial_pm1_gcd",
35        "pollard_p_1",
36        "ecm2",
37        "cube_root",
38        "system_primes_gcd",
39        "dixon",
40        "ecm",
41        "pastctfprimes",
42        "qicheng",
43        "wolframalpha",
44        "hastads",
45        "same_n_huge_e",
46        "commonfactors",
47        "pisano_period",
48        "nsif",
49        "all",
50    }
51
52    def __init__(self):
53        super().__init__()
54        self.env.check_var = self.check_var
55
56    @staticmethod
57    def check_var(name, value):
58        match name:
59            case "mode":
60                if value in RsaCtfToolModule.allowed_attack_methods:
61                    return True, ""
62                return False, "No such attack mode"
63            case "publickey":
64                if "*" in value or RsaCtfToolModule.check_file(value):
65                    return True, ""
66                return False, "No such file"
67            case "n" | "p" | "q" | "e":
68                try:
69                    int(value)
70                except ValueError:
71                    try:
72                        if value.startswith("0x"):
73                            int(value, 16)
74                        else:
75                            return False, "Value must be int or 0xhex"
76                    except ValueError:
77                        return False, "Value must be int or 0xhex"
78                return True, ""
79            case _:
80                return True, ""
81
82    def run(self):
83        flags = set(iter(self.env)) - {"extra_flags"}
84        flags = filter(
85            lambda x: x[1], zip(flags, map(lambda x: self.env.get_var(x).value, flags))
86        )
87        flags = " ".join(
88            map(lambda x: f"{'--' if len(x[0]) > 1 else '-'}{x[0]} {x[1]}", flags)
89        )
90        if extra_flags := self.env.get_var("extra_flags").value:
91            flags = " ".join([flags, extra_flags])
92        self.command_exec(
93            f'python {join(self.tool_path, "RsaCtfTool.py")} {flags}',
94            {"PYTHONPATH": ":".join(path)},
95        )
#   module()
View Source
52    def __init__(self):
53        super().__init__()
54        self.env.check_var = self.check_var
#   tool_path = '/home/y73n0k/Desktop/smth/projects/cryptosploit/cryptosploit_modules/src/cryptosploit_modules/asymmetric/rsa/rsactftool/RsaCtfTool'
#   allowed_attack_methods = {'pollard_p_1', 'neca', 'cube_root', 'z3_solver', 'small_crt_exp', 'nsif', 'pastctfprimes', 'smallq', 'pisano_period', 'brent', 'comfact_cn', 'ecm', 'fibonacci_gcd', 'binary_polinomial_factoring', 'fermat', 'wiener', 'commonfactors', 'factordb', 'system_primes_gcd', 'siqs', 'primorial_pm1_gcd', 'all', 'hastads', 'roca', 'pollard_rho', 'noveltyprimes', 'londahl', 'partial_q', 'smallfraction', 'fermat_numbers_gcd', 'qicheng', 'ecm2', 'euler', 'dixon', 'same_n_huge_e', 'SQUFOF', 'wolframalpha', 'mersenne_primes', 'mersenne_pm1_gcd', 'cm_factor', 'boneh_durfee'}
#  
@staticmethod
def check_var(name, value):
View Source
56    @staticmethod
57    def check_var(name, value):
58        match name:
59            case "mode":
60                if value in RsaCtfToolModule.allowed_attack_methods:
61                    return True, ""
62                return False, "No such attack mode"
63            case "publickey":
64                if "*" in value or RsaCtfToolModule.check_file(value):
65                    return True, ""
66                return False, "No such file"
67            case "n" | "p" | "q" | "e":
68                try:
69                    int(value)
70                except ValueError:
71                    try:
72                        if value.startswith("0x"):
73                            int(value, 16)
74                        else:
75                            return False, "Value must be int or 0xhex"
76                    except ValueError:
77                        return False, "Value must be int or 0xhex"
78                return True, ""
79            case _:
80                return True, ""
#   def run(self):
View Source
82    def run(self):
83        flags = set(iter(self.env)) - {"extra_flags"}
84        flags = filter(
85            lambda x: x[1], zip(flags, map(lambda x: self.env.get_var(x).value, flags))
86        )
87        flags = " ".join(
88            map(lambda x: f"{'--' if len(x[0]) > 1 else '-'}{x[0]} {x[1]}", flags)
89        )
90        if extra_flags := self.env.get_var("extra_flags").value:
91            flags = " ".join([flags, extra_flags])
92        self.command_exec(
93            f'python {join(self.tool_path, "RsaCtfTool.py")} {flags}',
94            {"PYTHONPATH": ":".join(path)},
95        )

Required to be overridden in the child class. Function called by the user