diff --git a/discordHelper.py b/discordHelper.py index e57ed34..8858e2e 100644 --- a/discordHelper.py +++ b/discordHelper.py @@ -13,7 +13,7 @@ def main(argm): :type argm: argparse.Namespace """ agnostic_path = agnostic_paths.AgnosticPaths(argm) - test_runner = main_runner.run_check(argm, agnostic_path) + main_runner.run_check(argm, agnostic_path) if __name__ == "__main__": diff --git a/discordHelperWin.py b/discordHelperWin.py index 2a76b57..e692095 100644 --- a/discordHelperWin.py +++ b/discordHelperWin.py @@ -7,7 +7,7 @@ import discordHelper import time # All modules must be loaded before the main program is run. -from modules import spidey_test, test_template +from modules import spidey_test, test_template # noqa # Set for pyinstaller if __name__ == "__main__": try: @@ -26,7 +26,8 @@ if __name__ == "__main__": # Will always try to load discordHelper/discordHelper.json # TODO : Document this feature. run_db = os.path.join(directory_path, "test_results_found.json") - argv = rf"--all --autodetect --launch --continue --timeout 10 {db_path}--gen-data {run_db} --db discordHelper/test_results.json".split(" ") + argv = rf"--all --autodetect --launch --continue --timeout 10 {db_path}--gen-data {run_db} \ + --db discordHelper/test_results.json".split(" ") # print(" > Starting the discordHelper with the following arguments:") # print(" > " + " ".join(argv)) diff --git a/modules/adler_test.py b/modules/adler_test.py index fabeda6..511998e 100644 --- a/modules/adler_test.py +++ b/modules/adler_test.py @@ -41,7 +41,11 @@ class AdlerTest(test_template.TestWalkTemplateNoLogs): f"({res}) not ({self.get_expected_result(path, 'adler32')} b).\n" self.is_infected = True if not self.args.continue_on_error: - return self.finish("failure", f"{short_path} is supposed to be {self.get_expected_result(path, 'adler32')} bytes, but it is {adler32(open(path, 'rb').read())} bytes.") + return self.finish( + "failure", + f"{short_path} is supposed to be {self.get_expected_result(path, 'adler32')} " + f"bytes, but it is {adler32(open(path, 'rb').read())} bytes." + ) self.progress = 100 if self.is_infected: @@ -49,4 +53,4 @@ class AdlerTest(test_template.TestWalkTemplateNoLogs): "failure", error_msg ) - return self.finish("success", "Your discord is not infected.") \ No newline at end of file + return self.finish("success", "Your discord is not infected.") diff --git a/modules/agnostic_paths.py b/modules/agnostic_paths.py index 06b16c8..e8ee2c6 100644 --- a/modules/agnostic_paths.py +++ b/modules/agnostic_paths.py @@ -10,7 +10,7 @@ class AgnosticPaths: """ An agnostic path object, containing all methods to access the files and folders in a standard discord install """ - + def __init__(self, args): """ :param args: The arguments passed to the script @@ -36,7 +36,6 @@ class AgnosticPaths: :return: ("windows", "linux", "mac") :rtype: str """ - platform = sys.platform if platform.startswith('win'): self.os = 'windows' @@ -61,7 +60,7 @@ class AgnosticPaths: if self.force_path is not None: return self.force_path if self.os == 'windows': - base_path = os.path.join(os.path.expanduser('~'), "AppData", "Local", f"Discord") + base_path = os.path.join(os.path.expanduser('~'), "AppData", "Local", "Discord") ptb_path = base_path+"PTB" if self.args.autodetect: if os.path.exists(ptb_path): @@ -87,7 +86,7 @@ class AgnosticPaths: def get_version(self): """ - Looks for the version file in the discord folder + Looks for the version file in the discord folder and return the latest version of the discord build :return: The version build :rtype: str @@ -121,7 +120,7 @@ class AgnosticPaths: Lists all files in the path /discord_path/args[0]/args[1].../args[n] :param args: The path as a list of parameters list("folder1", "folder2", ..., "foldern") :type args: str - :return: The list of all files and folders in the given path + :return: The list of all files and folders in the given path :rtype: list[str] """ return os.listdir(self(*args)) @@ -155,7 +154,7 @@ class AgnosticPaths: if not os.path.exists(_path): raise FileNotFoundError(f"Could not find {_path}") return _path - + def get_path(self): """ The main path of the discord install diff --git a/modules/argument_parser.py b/modules/argument_parser.py index 3bf5c4c..0837a45 100644 --- a/modules/argument_parser.py +++ b/modules/argument_parser.py @@ -14,7 +14,8 @@ def parse(_args): parser.add_argument('-v', '--version', action='version', version='%(prog)s 1.0') parser.add_argument('-d', '--debug', action='store_true', help='Debug mode') parser.add_argument('-s', '--silent', action='store_true', help='Silent mode') - parser.add_argument("--continue_on_error", "--continue", action="store_true", help="Continue the analysis in case of failure") + parser.add_argument("--continue_on_error", "--continue", + action="store_true", help="Continue the analysis in case of failure") parser.add_argument("--timeout", default=1, type=int, help="Timeout for the tests") # Post actions @@ -40,10 +41,12 @@ def parse(_args): parser.add_argument('--file-name', action='store_true', help="Test the name of the files in the discord folder") parser.add_argument('--file-extension', action='store_true', help="Test the extension of the files in the discord folder") parser.add_argument('--file-date', action='store_true', help="Test the date of the files in the discord folder") - parser.add_argument('--analyze', action='store_true', help="Analyze the files in the discord folder for known js obfuscators") + parser.add_argument('--analyze', action='store_true', + help="Analyze the files in the discord folder for known js obfuscators") parser.add_argument('--all', action='store_true', help="Run all tests in parallel, and wait for a potential interupt") parser.add_argument("--no-eval", action="store_true", help="Check for the eval function wich is a HUGE red flag") - parser.add_argument("--const-abuse", "--no-const", action="store_true", help="Check for the abuse of the const: keyword, wich is massively used for obfucation") + parser.add_argument("--const-abuse", "--no-const", action="store_true", + help="Check for the abuse of the const: keyword, wich is massively used for obfucation") parser.add_argument("--test-walk", action="store_true", help="Test walk function") parser.add_argument("--max-errors", default=5, type=int, help="Maximum number of errors before the analysis is stopped") diff --git a/modules/main_runner.py b/modules/main_runner.py index 2be05b0..c4329d2 100644 --- a/modules/main_runner.py +++ b/modules/main_runner.py @@ -34,16 +34,16 @@ queue_lock = threading.Lock() processes_lock = threading.Lock() CLEAR_CODE = colored(r""" - _______ _ -(_______) | - _ | | _____ _____ ____ + _______ _ +(_______) | + _ | | _____ _____ ____ | | | || ___ (____ |/ ___) -| |_____| || ____/ ___ | | +| |_____| || ____/ ___ | | \______)\_)_____)_____|_| """, 'green') INFECTED_CODE = colored(r""" - _ ___ _ + _ ___ _ | | / __) _ | | | |____ _| |__ _____ ____ _| |_ _____ __| | | | _ (_ __) ___ |/ ___|_ _) ___ |/ _ | @@ -51,12 +51,21 @@ INFECTED_CODE = colored(r""" |_|_| |_||_| |_____)\____) \__)_____)\____| """, 'red') +UNKNOWN_CODE = colored(r""" + _ _ _ +(_) (_) | | + _ _ ____ | | _ ____ ___ _ _ _ ____ +| | | | _ \| |_/ ) _ \ / _ \| | | | _ \ +| |___| | | | | _ (| | | | |_| | | | | | | | + \_____/|_| |_|_| \_)_| |_|\___/ \___/|_| |_| +""", 'yellow') + LOGO = colored(r""" - __ \ _) | | | | - | | | __| __| _ \ __| _` | | | _ \ | __ \ _ \ __| - | | | \__ \ ( ( | | ( | ___ | __/ | | | __/ | - ____/ _| ____/ \___| \___/ _| \__,_| _| _| \___| _| .__/ \___| _| - _| + __ \ _) | | | | + | | | __| __| _ \ __| _` | | | _ \ | __ \ _ \ __| + | | | \__ \ ( ( | | ( | ___ | __/ | | | __/ | + ____/ _| ____/ \___| \___/ _| \__,_| _| _| \___| _| .__/ \___| _| + _| """, "cyan") @@ -79,8 +88,11 @@ class TestRunner: self.version = agnpath.version self.start_time = start_time - self.is_infected = 0 - self.detections = 0 + self.is_infected = 0 # Only set to 1 if the certainty is high enough + self.is_unknown = 0 # Unknown if the file is infected or not + self.threat_level = 0 # The threat level of the infection, 0 is the lowest, can only be increased + self.errors = 0 + self.bad_database = False # Set to true if the database is not valid self.test_run = {} self.loaded_test_modules = {} @@ -108,6 +120,7 @@ class TestRunner: print(colored(f" > Opening specified database {self.args.database}", "green")) # TODO : Only if verbose with open(self.args.database, "r") as f: self.base_data = json.load(f) + self.check_database() return self.base_data elif os.path.exists(resource_path(default_database)): # Try opening the default database print(colored( @@ -116,6 +129,7 @@ class TestRunner: )) with open(resource_path(default_database), "r") as f: self.base_data = json.load(f) + self.check_database() return self.base_data else: @@ -126,6 +140,52 @@ class TestRunner: self.base_data = {} return self.base_data + def check_database(self): + """ + Check if the database is valid set self.bad_database to True if it is not + """ + if not self.base_data: + print(colored(" > The database is empty", "red")) + self.bad_database = True + return False + + if "global" not in self.base_data: + print(colored(" > The database is missing the global section", "red")) + self.bad_database = True + else: + if "discord_version" not in self.base_data["global"]: + print(colored(" > The database is missing a version field", "red")) + self.bad_database = True + else: + if self.base_data["global"]["discord_version"] != self.version: + print(colored( + f" > The database is from a different version ({self.base_data['global']['discord_version']})," + f" you are using {self.version}", "red" + )) + self.bad_database = True + if "ptb" not in self.base_data["global"]: + print(colored(" > The database is missing a ptb field", "red")) + self.bad_database = True + else: + if self.base_data["global"]["ptb"] != self.ptb: + print(colored( + f' > The database is for Discord {self.base_data["global"]["ptb"]} ' + f'you are using Discord{self.ptb}', "red" + )) + self.bad_database = True + if "os" not in self.base_data["global"]: + print(colored(" > The database is missing an os field", "red")) + self.bad_database = True + else: + if self.base_data["global"]["os"] != self.os_name: + print(colored( + f" > The database is for {self.base_data['global']['os']}, you are using {self.os_name}", "red" + )) + self.bad_database = True + if "tests" not in self.base_data: + print(colored(" > The database is missing the test results", "red")) + self.bad_database = True + def update_module_list(self): """ Gets the list of modules to be loaded (in accordance to the config) @@ -204,7 +264,7 @@ class TestRunner: except KeyboardInterrupt: RUN_OVER = True return - except: + except Exception: sys.exit() def post_test_runner(self): @@ -443,7 +503,10 @@ def print_final_status(testrunner, start_time, args): else: color = "red" print(INFECTED_CODE) - print(colored(f"\nThe test sequence is now finished, DiscordHelper ran for {round(time.time() - start_time,2)} seconds", color)) + print(colored( + f"\nThe test sequence is now finished, DiscordHelper ran for " + f"{round(time.time() - start_time,2)} seconds", color + )) SIZE = args.size for test, test_object in testrunner.dict_of_processes.items(): if test_object.status_code == "success": diff --git a/modules/size_test.py b/modules/size_test.py index 349d1c3..ccdddb5 100644 --- a/modules/size_test.py +++ b/modules/size_test.py @@ -1,6 +1,4 @@ -import asyncio import os -import time from modules import test_template @@ -32,7 +30,10 @@ class SizeTest(test_template.TestWalkTemplateNoLogs): f"({res} b) not ({self.get_expected_result(path, 'size')} b).\n" self.is_infected = True if not self.args.continue_on_error: - return self.finish("failure", f"{short_path} is supposed to be {self.get_expected_result(path, 'size')} bytes, but it is {os.path.getsize(path)} bytes.") + return self.finish( + "failure", + f"{short_path} is supposed to be {self.get_expected_result(path, 'size')}" + f" bytes, but it is {os.path.getsize(path)} bytes.") self.progress = 100 if self.is_infected: @@ -41,4 +42,3 @@ class SizeTest(test_template.TestWalkTemplateNoLogs): error_msg ) return self.finish("success", "Your discord is not infected.") - diff --git a/modules/spidey_test.py b/modules/spidey_test.py index 14ccf50..6782d8b 100644 --- a/modules/spidey_test.py +++ b/modules/spidey_test.py @@ -1,6 +1,4 @@ -import asyncio import os -import time from modules import test_template