Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- # Filename: smb_protocol_manager_eternalblue_vulnerability_checker.py
- # Version: 1.0.0
- # Author: Jeoi Reqi
- """
- Script to manage SMB (Server Message Block) protocols
- SMB is a network file sharing protocol that allows applications to read and write to files and request services from server programs in a computer network.
- SMB1, SMB2, and SMB3 are different versions of this protocol. SMB1 is known to have security vulnerabilities, such as the EternalBlue exploit.
- It is recommended to disable SMB1 due to its vulnerabilities. SMB2 and SMB3 are more secure and should be used instead.
- This script provides options to:
- 1. Verify the status of SMB1 protocol.
- 2. Verify the status of SMB2 protocol.
- 3. Verify the status of SMB3 protocol.
- 4. Enable SMB2 protocol.
- 5. Enable SMB3 protocol.
- 6. Disable SMB1 protocol.
- 7. Delete SMB1 registry key.
- 8. Create SMB1 registry key with disabled SMB1.
- 9. Enable SMB1 protocol (with a warning message about the potential security risks).
- 0. Exit the script.
- WARNING: Enabling SMB1 is highly insecure and may expose your system to potential attacks.
- Only enable SMB1 for testing purposes and if you understand the risks involved.
- Known exploits that use EternalBlue attack methods:
- 1. WannaCry
- 2. EternalRocks
- 3. Petya
- 4. NotPetya
- 5. Bad Rabbit
- 6. TrickBot
- 7. Emotet
- 8. Ryuk
- 9. GandCrab
- 10. SamSam
- 11. Smominru
- 12. RobbinHood
- 13. Dharma
- The user is prompted to confirm their choice when enabling SMB1.
- Numeric options are provided for the user to choose (e.g., 1 for Yes, 2 for No).
- Note: Changes made to SMB protocols may require system restart to take effect.
- """
- import subprocess
- def verify_smb1_status():
- """
- Verify the status of SMB1 protocol.
- This function checks whether SMB1 protocol is enabled or disabled on the system.
- """
- try:
- # Check the value of the SMB1 registry key
- result = subprocess.run(
- [
- "reg",
- "query",
- "HKLM\\SYSTEM\\CurrentControlSet\\Services\\LanmanServer\\Parameters",
- "/v",
- "SMB1",
- ],
- capture_output=True,
- text=True,
- )
- if "SMB1 REG_DWORD 0x1" in result.stdout:
- 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."
- )
- elif "SMB1 REG_DWORD 0x0" in result.stdout:
- print("\nSMB1 is disabled.\n")
- else:
- print(
- "\nSMB1 status could not be determined or registry key not found on the system.\n"
- )
- except subprocess.CalledProcessError as e:
- print("\nAn error occurred while checking SMB1 status:", e.stderr)
- def verify_smb2_status():
- """
- Verify the status of SMB2 protocol.
- This function checks whether SMB2 protocol is enabled or disabled on the system.
- """
- result = subprocess.run(
- [
- "powershell",
- "-Command",
- '$SMB2Enabled = (Get-SmbServerConfiguration).EnableSMB2Protocol; if ($SMB2Enabled) { Write-Output "SMB2 is enabled" } else { Write-Output "SMB2 is disabled" }',
- ],
- capture_output=True,
- text=True,
- )
- print("\n" + result.stdout.strip() + "\n")
- def verify_smb3_status():
- """
- Verify the status of SMB3 protocol.
- This function checks whether SMB3 protocol is enabled or disabled on the system.
- """
- result = subprocess.run(
- [
- "powershell",
- "-Command",
- '$SMB3Enabled = (Get-SmbServerConfiguration).EnableSMB3Protocol; if ($SMB3Enabled) { Write-Output "SMB3 is enabled" } else { Write-Output "SMB3 is disabled" }',
- ],
- capture_output=True,
- text=True,
- )
- print("\n" + result.stdout.strip() + "\n")
- def enable_smb1():
- """
- Enable the SMB1 protocol.
- This function enables the SMB1 protocol on the system.
- """
- confirm = input(
- "⚠️ WARNING: Enabling SMB1 is highly insecure and may expose your system to potential attacks.\nAre you sure you want to enable SMB1?\n1: Yes\n2: No\nEnter your choice: "
- )
- if confirm == "1":
- try:
- # Check if the registry key exists and is set to 1 (enabled)
- check_registry = subprocess.run(
- [
- "reg",
- "query",
- "HKLM\\SYSTEM\\CurrentControlSet\\Services\\LanmanServer\\Parameters",
- "/v",
- "SMB1",
- ],
- capture_output=True,
- text=True,
- )
- if "SMB1" in check_registry.stdout:
- if "0x1" in check_registry.stdout: # Check if SMB1 is enabled
- print("\nSMB1 is already enabled.\n")
- else:
- # Enable SMB1
- subprocess.run(
- [
- "reg",
- "add",
- "HKLM\\SYSTEM\\CurrentControlSet\\Services\\LanmanServer\\Parameters",
- "/v",
- "SMB1",
- "/t",
- "REG_DWORD",
- "/d",
- "1",
- "/f",
- ],
- capture_output=True,
- text=True,
- timeout=10,
- )
- print("\nSMB1 has been successfully enabled.\n")
- else:
- # Create the registry key if it doesn't exist
- subprocess.run(
- [
- "reg",
- "add",
- "HKLM\\SYSTEM\\CurrentControlSet\\Services\\LanmanServer\\Parameters",
- "/v",
- "SMB1",
- "/t",
- "REG_DWORD",
- "/d",
- "1",
- "/f",
- ],
- capture_output=True,
- text=True,
- timeout=10,
- )
- print("\nSMB1 has been successfully enabled.\n")
- except subprocess.TimeoutExpired:
- print("\nTimeout occurred while trying to enable SMB1.\n")
- elif confirm == "2":
- print("Aborted. SMB1 was not enabled.")
- else:
- print("Invalid choice. Please enter 1 or 2.")
- def enable_smb2():
- """
- Enable the SMB2 protocol.
- This function enables the SMB2 protocol on the system.
- """
- result = subprocess.run(
- ["powershell", "-Command", "(Get-SmbServerConfiguration).EnableSMB2Protocol"],
- capture_output=True,
- text=True,
- )
- if "True" in result.stdout:
- print("\nSMB2 is already enabled.\n")
- else:
- result = subprocess.run(
- [
- "powershell",
- "-Command",
- "Enable-WindowsOptionalFeature -Online -FeatureName SMB2Protocol",
- ],
- capture_output=True,
- text=True,
- )
- if "The operation completed successfully." in result.stdout:
- print("\nSMB2 has been successfully enabled.\n")
- else:
- print("\nFailed to enable SMB2.\n")
- def enable_smb3():
- """
- Enable the SMB3 protocol if supported.
- """
- # Check if SMB3 is supported on the system
- result = subprocess.run(
- [
- "powershell",
- "-Command",
- "Get-WindowsOptionalFeature -Online -FeatureName SMB3Protocol",
- ],
- capture_output=True,
- text=True,
- )
- if "State" in result.stdout and "Enabled" in result.stdout:
- print("\nSMB3 is already enabled.\n")
- elif "State" in result.stdout and "Disabled" in result.stdout:
- # SMB3 is supported but disabled, attempt to enable it
- result = subprocess.run(
- [
- "powershell",
- "-Command",
- "Enable-WindowsOptionalFeature -Online -FeatureName SMB3Protocol",
- ],
- capture_output=True,
- text=True,
- )
- if "The operation completed successfully." in result.stdout:
- print("\nSMB3 has been successfully enabled.\n")
- else:
- print("\nFailed to enable SMB3.\n")
- else:
- # SMB3 is not supported on this system
- print("\nSMB3 is not supported on this system.\n")
- def disable_smb1():
- """
- Disable the SMB1 protocol.
- This function disables the SMB1 protocol on the system.
- """
- try:
- # Check if the registry key exists and is set to 1
- check_registry = subprocess.run(
- [
- "reg",
- "query",
- "HKLM\\SYSTEM\\CurrentControlSet\\Services\\LanmanServer\\Parameters",
- "/v",
- "SMB1",
- ],
- capture_output=True,
- text=True,
- )
- if "SMB1" in check_registry.stdout and "0x1" in check_registry.stdout:
- result = subprocess.run(
- [
- "reg",
- "add",
- "HKLM\\SYSTEM\\CurrentControlSet\\Services\\LanmanServer\\Parameters",
- "/v",
- "SMB1",
- "/t",
- "REG_DWORD",
- "/d",
- "0",
- "/f",
- ],
- capture_output=True,
- text=True,
- timeout=10,
- )
- print("\nSMB1 has been successfully disabled.\n")
- else:
- print(
- "\nThe SMB1 registry key does not exist or SMB1 is already disabled.\n"
- )
- except subprocess.TimeoutExpired:
- print("\nTimeout occurred while trying to disable SMB1.\n")
- def delete_smb1_registry_key():
- """
- Delete the SMB1 protocol registry key.
- This function removes the SMB1 registry key from the system.
- """
- try:
- subprocess.run(
- [
- "reg",
- "delete",
- "HKLM\\SYSTEM\\CurrentControlSet\\Services\\LanmanServer\\Parameters",
- "/v",
- "SMB1",
- "/f",
- ],
- check=True,
- )
- print("\nThe SMB1 registry key has been successfully deleted.\n")
- except subprocess.CalledProcessError:
- print("\nThe SMB1 registry key does not exist.\n")
- def create_smb1_registry_key():
- """
- Create the SMB1 registry key with value 0 to disable SMB1.
- """
- subprocess.run(
- [
- "reg",
- "add",
- "HKLM\\SYSTEM\\CurrentControlSet\\Services\\LanmanServer\\Parameters",
- "/v",
- "SMB1",
- "/t",
- "REG_DWORD",
- "/d",
- "0",
- "/f",
- ]
- )
- def main():
- while True:
- print(":: [SMB PROTOCOL OPTIONS] ::\n")
- print("0: Exit")
- print("1: Verify SMB1 status")
- print("2: Verify SMB2 status")
- print("3: Verify SMB3 status")
- print("4: Enable SMB2")
- print("5: Enable SMB3")
- print("6: Disable SMB1")
- print("7: Delete SMB1 Registry Key")
- print("\n:: ⚠️ WARNING! ⚠️ ::\n")
- print("8: Create SMB1 Registry Key (Disabled SMB1)")
- print("9: Enable SMB1 :: ⚠️ WARNING! ⚠️ ::\n")
- choice = input("Enter your choice: ")
- if choice == "1":
- verify_smb1_status()
- elif choice == "2":
- verify_smb2_status()
- elif choice == "3":
- verify_smb3_status()
- elif choice == "4":
- enable_smb2()
- elif choice == "5":
- enable_smb3()
- elif choice == "6":
- disable_smb1()
- elif choice == "7":
- delete_smb1_registry_key()
- elif choice == "8":
- create_smb1_registry_key()
- elif choice == "9":
- enable_smb1()
- elif choice == "0":
- print("\nExiting Program...\nGoodBye!\n.")
- break
- else:
- print("\nInvalid choice. Please enter a valid option.\n")
- input("\nPress Enter to continue...\n")
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement