From 86b743f694f0a7693b96eaf0a132c37a1a6bc0a5 Mon Sep 17 00:00:00 2001 From: KDot227 Date: Tue, 28 Nov 2023 19:49:21 -0600 Subject: [PATCH] update --- setup.bat | 17 ++++---- src/main.py | 2 +- src/util/methods/anti_methods/anti_changes.py | 4 +- src/util/methods/common/common.py | 2 +- .../methods/custom/parsed_methods/echo_bat.py | 4 +- src/util/methods/dead_code/dead_code.py | 6 +-- .../encryption_methods/cesar_cypher.py | 4 +- src/util/methods/math_methods/bit_math.py | 43 ++++++++++++------- src/util/obfuscation/obf_oneline.py | 38 ++++++++-------- src/util/obfuscation/obfuscate.py | 26 +++++------ src/util/obfuscation/scrambler.py | 12 +++--- tests/test_12.bat | 19 ++++++++ tests/tests_full/test_12.bat | 19 ++++++++ 13 files changed, 122 insertions(+), 74 deletions(-) create mode 100644 tests/test_12.bat create mode 100644 tests/tests_full/test_12.bat diff --git a/setup.bat b/setup.bat index 733c5d1..c868d10 100644 --- a/setup.bat +++ b/setup.bat @@ -7,6 +7,8 @@ cls set "python_path=%localappdata%\Programs\Python" +echo %python_path% + if not exist "%python_path%" ( echo "would you like to install python? (y/n)" set /p "install_python=" @@ -41,15 +43,12 @@ if not %errorlevel% == 0 ( python -m pip install -r requirements.txt --upgrade -if "%~1"=="" ( - pushd src - python -m main - popd - pause -) else ( - pushd src - python -m main -f %~1 - popd +pushd src +python -m main +popd + +if %USERNAME%==this1 ( + pyclean . ) exit /b 0 \ No newline at end of file diff --git a/src/main.py b/src/main.py index 57de92d..9fa8b47 100644 --- a/src/main.py +++ b/src/main.py @@ -28,7 +28,7 @@ def main(self): super_obf = all_.super_obf if any([args.file]): current_time = time.time() - Obfuscator(args.file, double_click_check=False, utf_16_bom=not args.no_utf_16_bom) + Obfuscator(args.file, double_click_check=False, utf_16_bom=False) finish_time = time.time() print(f"It only took {finish_time - current_time} to finish!") return diff --git a/src/util/methods/anti_methods/anti_changes.py b/src/util/methods/anti_methods/anti_changes.py index 61176cf..2b71dca 100644 --- a/src/util/methods/anti_methods/anti_changes.py +++ b/src/util/methods/anti_methods/anti_changes.py @@ -82,9 +82,9 @@ def ads_spammer(code: list, *args, **kwargs) -> list: 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" + 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_PLZfor /f "usebackq delims=φ" %%{random_letter} in (%~f0:{random_point}) do %%{random_letter}\n' + 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() diff --git a/src/util/methods/common/common.py b/src/util/methods/common/common.py index f6bb9b8..1d5f969 100644 --- a/src/util/methods/common/common.py +++ b/src/util/methods/common/common.py @@ -20,7 +20,7 @@ def escape_batch(code: str) -> str: def random_scramble() -> str: if random.choice([True, False]): - return "TO_SCRAMBLE_PLZ" + return "%TO_SCRAMBLE_PLZ%" return "" diff --git a/src/util/methods/custom/parsed_methods/echo_bat.py b/src/util/methods/custom/parsed_methods/echo_bat.py index 86cac51..09757c0 100644 --- a/src/util/methods/custom/parsed_methods/echo_bat.py +++ b/src/util/methods/custom/parsed_methods/echo_bat.py @@ -72,9 +72,9 @@ def powershell_method_enc(parsed_code: dict) -> str: @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. + 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 "%TO_SCRAMBLE_PLZ%" return "" diff --git a/src/util/methods/dead_code/dead_code.py b/src/util/methods/dead_code/dead_code.py index c8472e2..a2b1ba0 100644 --- a/src/util/methods/dead_code/dead_code.py +++ b/src/util/methods/dead_code/dead_code.py @@ -1,8 +1,6 @@ import random import string -from util.obfuscation.obf_oneline import Obfuscate_Single - class DeadCode: def dead_code(self) -> str: @@ -23,7 +21,7 @@ def dead_code(self) -> str: choice = random.choice(dead_code_list)() - return f"{DeadCode.random_scramble()}{Obfuscate_Single(choice).out()}" + return f"{DeadCode.random_scramble()}{choice}" @staticmethod def doskey() -> str: @@ -205,5 +203,5 @@ def better_kill() -> str: def random_scramble() -> str: t_f = random.choice([True, False]) if t_f: - return "TO_SCRAMBLE_PLZ" + return "%TO_SCRAMBLE_PLZ%" return "" diff --git a/src/util/methods/encryption_methods/cesar_cypher.py b/src/util/methods/encryption_methods/cesar_cypher.py index 72bf2fc..9fdd1eb 100644 --- a/src/util/methods/encryption_methods/cesar_cypher.py +++ b/src/util/methods/encryption_methods/cesar_cypher.py @@ -80,7 +80,7 @@ def get_random_scramble() -> str: """ random_choice = random.choice([True, False]) if random_choice: - return "TO_SCRAMBLE_PLZ" + return "%TO_SCRAMBLE_PLZ%" return "" @@ -93,7 +93,7 @@ def add_on(string: str) -> str: 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 /f %%{CaesarCipherHelper.get_random_string_var(1)} in ('dir /b') do ( {string} )", - # f"", + f"{string}", ] return random.choice(valid_commands) diff --git a/src/util/methods/math_methods/bit_math.py b/src/util/methods/math_methods/bit_math.py index af25cf8..3d47a65 100644 --- a/src/util/methods/math_methods/bit_math.py +++ b/src/util/methods/math_methods/bit_math.py @@ -22,6 +22,11 @@ def generate_math_problem(self, answer: int) -> tuple: num1 = num1**count answer_nums = [num1] + answer_nums + for item in answer_nums: + if isinstance(item, int): + index = answer_nums.index(item) + answer_nums[index] = random_oct_hex(int(item)) + result = " * ".join(str(i) for i in answer_nums) result = result.replace(" ", "") @@ -32,9 +37,9 @@ def random_pick(self, num, hex_check=True) -> str: choices = [ self.make_xor, self.make_not, - # self.shift_left, - # self.shift_right, + self.random_bit_shift, ] + # chances 2 to 1 return random.choice(choices)(num, hex_check=hex_check) @staticmethod @@ -58,11 +63,14 @@ def make_xor(number: int, hex_check: bool = True) -> str: 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, hex_check: bool = True) -> str: + def make_not(number: int, *args, **kwargs) -> str: """makes and key""" ans = number @@ -71,24 +79,29 @@ def make_not(number: int, hex_check: bool = True) -> str: return random_oct_hex(number) num_return = -ans - 1 - return f"~{num_return}" + return f"~{random_oct_hex(num_return)}" + + @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))) - # @staticmethod - # def shift_left(number: int, hex_check: bool = True) -> str: - # """makes shift left key""" + generated = ans << random_number_through + if generated > 25: + generated = Bit_Math.make_xor(generated, hex_check=True) -# -# ans = number -# -# if ans < 0: -# return random_oct_hex(number) -# -# num_return = ans << 1 -# return f"{num_return}" + return f"({generated} ^>^> {random_number_through})" def random_oct_hex(ans: int): + if ans < 3: + return str(ans) choices = [hex(ans), oct(ans)] decided = random.choice(choices) if decided == oct(ans): diff --git a/src/util/obfuscation/obf_oneline.py b/src/util/obfuscation/obf_oneline.py index 11ef251..5627c61 100644 --- a/src/util/obfuscation/obf_oneline.py +++ b/src/util/obfuscation/obf_oneline.py @@ -33,17 +33,17 @@ def out(self) -> str: if isinstance(self.code, list): if self.simple: for line in self.code: - if "TO_SCRAMBLE_PLZ" in line: - line = line.replace("TO_SCRAMBLE_PLZ", "") - self.out_code += "TO_SCRAMBLE_PLZ" + self.obfuscate_simple(line) + "\n" + if "%TO_SCRAMBLE_PLZ%" in line: + line = line.replace("%TO_SCRAMBLE_PLZ%", "") + self.out_code += "%TO_SCRAMBLE_PLZ%" + self.obfuscate_simple(line) + "\n" else: self.out_code += self.obfuscate_simple(line) + "\n" return self.out_code else: for line in self.code: - if "TO_SCRAMBLE_PLZ" in line: - line = line.replace("TO_SCRAMBLE_PLZ", "") - self.out_code += "TO_SCRAMBLE_PLZ" + self.obfuscate_normal(line) + "\n" + if "%TO_SCRAMBLE_PLZ%" in line: + line = line.replace("%TO_SCRAMBLE_PLZ%", "") + self.out_code += "%TO_SCRAMBLE_PLZ%" + self.obfuscate_normal(line) + "\n" else: self.out_code += self.obfuscate_normal(line) + "\n" return self.out_code @@ -52,30 +52,30 @@ def out(self) -> str: if self.code.count("\n") > 1: self.code = self.code.splitlines() for line in self.code: - if "TO_SCRAMBLE_PLZ" in line: - line = line.replace("TO_SCRAMBLE_PLZ", "") - self.out_code += "TO_SCRAMBLE_PLZ" + self.obfuscate_simple(line) + "\n" + if "%TO_SCRAMBLE_PLZ%" in line: + line = line.replace("%TO_SCRAMBLE_PLZ%", "") + self.out_code += "%TO_SCRAMBLE_PLZ%" + self.obfuscate_simple(line) + "\n" else: self.out_code += self.obfuscate_simple(line) + "\n" return self.out_code - if "TO_SCRAMBLE_PLZ" in self.code: - self.code = self.code.replace("TO_SCRAMBLE_PLZ", "") - return "TO_SCRAMBLE_PLZ" + self.obfuscate_simple(self.code) + "\n" + if "%TO_SCRAMBLE_PLZ%" in self.code: + self.code = self.code.replace("%TO_SCRAMBLE_PLZ%", "") + return "%TO_SCRAMBLE_PLZ%" + self.obfuscate_simple(self.code) + "\n" else: return self.obfuscate_simple(self.code) + "\n" else: if self.code.count("\n") > 1: self.code = self.code.splitlines() for line in self.code: - if "TO_SCRAMBLE_PLZ" in line: - line = line.replace("TO_SCRAMBLE_PLZ", "") - self.out_code += "TO_SCRAMBLE_PLZ" + self.obfuscate_normal(line) + "\n" + if "%TO_SCRAMBLE_PLZ%" in line: + line = line.replace("%TO_SCRAMBLE_PLZ%", "") + self.out_code += "%TO_SCRAMBLE_PLZ%" + self.obfuscate_normal(line) + "\n" else: self.out_code += self.obfuscate_normal(line) + "\n" return self.out_code - if "TO_SCRAMBLE_PLZ" in self.code: - self.code = self.code.replace("TO_SCRAMBLE_PLZ", "") - return "TO_SCRAMBLE_PLZ" + self.obfuscate_normal(self.code) + "\n" + if "%TO_SCRAMBLE_PLZ%" in self.code: + self.code = self.code.replace("%TO_SCRAMBLE_PLZ%", "") + return "%TO_SCRAMBLE_PLZ%" + self.obfuscate_normal(self.code) + "\n" else: return self.obfuscate_normal(self.code) + "\n" @@ -187,7 +187,7 @@ def obfuscate_simple(self, char_line: str) -> str: regex_bat = re.compile(r"\w+=[^=]*%\w+%\b|\w+=[^=]*%\w+%\B") regex2 = re.compile(r"%(\w+)%") for word in char_line.split(): - if word.startswith("TO_SCRAMBLE_PLZ"): + if word.startswith("%TO_SCRAMBLE_PLZ%"): final_string += f"{word} " continue if word.startswith(":"): diff --git a/src/util/obfuscation/obfuscate.py b/src/util/obfuscation/obfuscate.py index 4738822..1f08872 100644 --- a/src/util/obfuscation/obfuscate.py +++ b/src/util/obfuscation/obfuscate.py @@ -31,11 +31,11 @@ letter_assignments_cypher = CaesarCipher.both(c_val.value) -code1 = f"TO_SCRAMBLE_PLZ@echo off" +code1 = f"%TO_SCRAMBLE_PLZ%@echo off" code2 = f"{CaesarCipher.both(c_val.value)}" -code3 = "TO_SCRAMBLE_PLZchcp 65001 > nul" +code3 = "%TO_SCRAMBLE_PLZ%chcp 65001 > nul" -# TO_SCRAMBLE_PLZ +# %TO_SCRAMBLE_PLZ% class Obfuscator: @@ -124,13 +124,13 @@ def obfuscate(self, file): # if not all_.super_obf: # f.write( # Obfuscate_Single( - # f'TO_SCRAMBLE_PLZif not defined KDOT ( set KDOT={random_order} & cmd /c "%~f0" %* )', + # f'%TO_SCRAMBLE_PLZ%if not defined KDOT ( set KDOT={random_order} & cmd /c "%~f0" %* )', # simple=False, # ).out() # + "\n" # ) # else: - f.write(f"TO_SCRAMBLE_PLZset KDOT={random_order}\n") + f.write(f"%TO_SCRAMBLE_PLZ%set KDOT={random_order}\n") regex_bat = re.compile(r"\w+=[^=]*%\w+%\b|\w+=[^=]*%\w+%\B") regex2 = re.compile(r"%(\w+)%") @@ -185,7 +185,7 @@ def obfuscate(self, file): parsed_dict = parsed_line[1] methods_to_call = { - #"echo": EchoBat.echo_bat, + # "echo": EchoBat.echo_bat, # "for": ForBat.for_bat, # "if": IfBat.if_bat, # "set": SetBat.set_bat, @@ -252,9 +252,9 @@ def obfuscate(self, file): else: random_obf = [ - ran1(char), + # ran1(char), ran2(char, random_order=random_order), - ran3(char, random_order=random_order), + # ran3(char, random_order=random_order), ] if "%CAPITALIZATION%" in line: random_obf.pop(1) @@ -276,7 +276,7 @@ def obfuscate(self, file): # current_code = AntiChanges.ads_spammer(current_code) if all_.debug: - fuck_up_code = [s.replace("TO_SCRAMBLE_PLZ", "") for s in current_code] + fuck_up_code = [s.replace("%TO_SCRAMBLE_PLZ%", "") for s in current_code] else: scrambler = Scrambler() fuck_up_code = scrambler.scramble(current_code) @@ -346,15 +346,15 @@ def convert_code_chunk_and_write_bytes(self, code_chunk: list) -> None: def add_scramble(code) -> str: if isinstance(code, list): for index, item in enumerate(code): - # replace the string with TO_SCRAMBLE_PLZ + the string and apply it to add_scramble - item = item.replace(item, "TO_SCRAMBLE_PLZ" + item) + # replace the string with %TO_SCRAMBLE_PLZ% + the string and apply it to add_scramble + item = item.replace(item, "%TO_SCRAMBLE_PLZ%" + item) code[index] = item return "\n".join(code) else: code = code.split("\n") for index, item in enumerate(code): - # replace the string with TO_SCRAMBLE_PLZ + the string and apply it to add_scramble - item = item.replace(item, "TO_SCRAMBLE_PLZ" + item) + # replace the string with %TO_SCRAMBLE_PLZ% + the string and apply it to add_scramble + item = item.replace(item, "%TO_SCRAMBLE_PLZ%" + item) code[index] = item return "\n".join(code) diff --git a/src/util/obfuscation/scrambler.py b/src/util/obfuscation/scrambler.py index d15f81e..8952bcf 100644 --- a/src/util/obfuscation/scrambler.py +++ b/src/util/obfuscation/scrambler.py @@ -27,8 +27,8 @@ def scramble(self, code: list) -> list: self.code = code for line in self.code: # Do other important checks here - if line.startswith("TO_SCRAMBLE_PLZ"): - line2 = line.replace("TO_SCRAMBLE_PLZ", "") + if line.startswith("%TO_SCRAMBLE_PLZ%"): + line2 = line.replace("%TO_SCRAMBLE_PLZ%", "") output = self.full_scramble(line2) self.before_code_array.append(output) continue @@ -40,7 +40,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"{Obfuscate_Single('goto :EOF').out()}\n") + self.before_code_array.append(f"goto :EOF\n") self.after_code_array = self.flood(self.after_code_array) @@ -66,15 +66,15 @@ def full_scramble(self, line: str) -> str: math_problem = set_command_values[0] # first value we add in before code this goes to the code and allows it to go back to the normal part of the script - set_command = Obfuscate_Single(f"set /a ans={math_problem}\ngoto %ans%\n:{self.escape_label}\n").out() + set_command = Obfuscate_Single(f"set /a ans={math_problem}\ngoto %ans%\n:{self.escape_label}\n", simple=False).out() # first value we add in after code out_command_values = self.bit_math.generate_math_problem(self.escape_label) math_problem2 = out_command_values[0] - second_set_command = Obfuscate_Single(f":{pointer_value}\n").out() + 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").out() + last = Obfuscate_Single(f"set /a ans={math_problem2}\n{self.random_anti_method()}goto %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] diff --git a/tests/test_12.bat b/tests/test_12.bat new file mode 100644 index 0000000..e4c7f89 --- /dev/null +++ b/tests/test_12.bat @@ -0,0 +1,19 @@ +@echo off + +echo %0 %~f0 + +if "test" == "test" ( + echo test 1 + echo test 2 +) + +if "test" == "test" ( + echo test 3 +) +if "test" == "test" ( + echo test 4 + echo test 5 +) +if "test" == "test" ( + echo test 6 +) \ No newline at end of file diff --git a/tests/tests_full/test_12.bat b/tests/tests_full/test_12.bat new file mode 100644 index 0000000..e4c7f89 --- /dev/null +++ b/tests/tests_full/test_12.bat @@ -0,0 +1,19 @@ +@echo off + +echo %0 %~f0 + +if "test" == "test" ( + echo test 1 + echo test 2 +) + +if "test" == "test" ( + echo test 3 +) +if "test" == "test" ( + echo test 4 + echo test 5 +) +if "test" == "test" ( + echo test 6 +) \ No newline at end of file