Advertisement
Python253

is_smb_vulnerable

Apr 11th, 2024 (edited)
695
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.76 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Filename: is_smb_vulnerable.py
  4. # Version: 1.0.0
  5. # Author: Jeoi Reqi
  6. # Additional Script Download: https://pastebin.com/dl/GYB65Yvy
  7.  
  8. import subprocess
  9. import urllib.request
  10. import os
  11.  
  12. """
  13. This script provides options to:
  14. 1. Verify the status of SMB1 protocol.
  15. 2. Download and save 'smb_protocol_manager_eternalblue_vulnerability_checker.py' script in the cwd.
  16. 0. Exit the script.
  17.  
  18. WARNING: Enabling SMB1 is highly insecure and may expose your system to potential attacks.
  19. Only enable SMB1 for testing purposes and if you understand the risks involved.
  20.  
  21. Known exploits that use EternalBlue attack methods:
  22. 1. WannaCry
  23. 2. EternalRocks
  24. 3. Petya
  25. 4. NotPetya
  26. 5. Bad Rabbit
  27. 6. TrickBot
  28. 7. Emotet
  29. 8. Ryuk
  30. 9. GandCrab
  31. 10. SamSam
  32. 11. Smominru
  33. 12. RobbinHood
  34. 13. Dharma
  35.  
  36. The user is prompted to confirm their choice when enabling SMB1.
  37. Numeric options are provided for the user to choose (e.g., 1 for Yes, 2 for No).
  38.  
  39. Note: Changes made to SMB protocols may require system restart to take effect.
  40. """
  41.  
  42. def verify_smb1_status():
  43.     """
  44.    Verify the status of SMB1 protocol.
  45.    This function checks whether SMB1 protocol is enabled or disabled on the system.
  46.    """
  47.     try:
  48.         # Check the value of the SMB1 registry key
  49.         result = subprocess.run(
  50.             [
  51.                 "reg",
  52.                 "query",
  53.                 "HKLM\\SYSTEM\\CurrentControlSet\\Services\\LanmanServer\\Parameters",
  54.                 "/v",
  55.                 "SMB1",
  56.             ],
  57.             capture_output=True,
  58.             text=True,
  59.         )
  60.         if "SMB1    REG_DWORD    0x1" in result.stdout:
  61.             print("\nSMB1 is enabled. \n\t\t:: ⚠️ Warning ⚠ ::\n\n\t- Enabling SMB1 exposes your system to potential vulnerabilities such as EternalBlue.\n\n\t- Disable SMB1 with Option 6 or Remove the registry key with Option 7.")
  62.             print("\nYour machine is at risk from vulnerabilities from exploits such as EternalBlue, Petya, NotPetya & many more malicious attacks.")
  63.             print("Select Option 2: Download & Save [SMB Protocol Manager]\n")
  64.         elif "SMB1    REG_DWORD    0x0" in result.stdout:
  65.             print("\nSMB1 is disabled.\n")
  66.             print("\nAll Clear!\nYour machine is not at risk from vulnerabilities from exploits such as EternalBlue, Petya, NotPetya & many more malicious attacks.")
  67.         else:
  68.             print("\nSMB1 status could not be determined or registry key not found on the system.\n")
  69.     except subprocess.CalledProcessError as e:
  70.         print("\nAn error occurred while checking SMB1 status:", e.stderr)
  71.  
  72. def download_script(url, filename):
  73.     """
  74.    Download script from the provided URL and save it with the given filename.
  75.    """
  76.     try:
  77.         urllib.request.urlretrieve(url, filename)
  78.         print(f"\nScript downloaded successfully and saved as '{filename}' in the current working directory.\n")
  79.     except Exception as e:
  80.         print(f"\nFailed to download script from '{url}': {e}\n")
  81.  
  82. def main():
  83.     while True:
  84.         print(":: [VERIFY SMB VULNERABILITY STATUS] ::\n")
  85.         print("1: Verify SMB1 status")
  86.         print("2: Download & Save [SMB Protocol Manager]")
  87.         print("0: Exit")
  88.  
  89.         choice = input("\nEnter your choice: ")
  90.  
  91.         if choice == "1":
  92.             verify_smb1_status()
  93.         elif choice == "2":
  94.             download_script("https://pastebin.com/raw/GYB65Yvy", "smb_protocol_manager_eternalblue_vulnerability_checker.py")
  95.         elif choice == "0":
  96.             print("\nExiting Program...\nGoodbye!\n")
  97.             break
  98.         else:
  99.             print("\nInvalid choice. Please enter a valid option.\n")
  100.  
  101.         input("\nPress Enter to continue...\n")
  102.  
  103. if __name__ == "__main__":
  104.     main()
  105.  
  106.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement