Advertisement
Python253

cve_2021_3156_sudo_buffer_overflow

Apr 10th, 2024
980
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.90 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Filename: cve_2021_3156_sudo_buffer_overflow.py
  4. # Version: 1.0.0
  5. # Author: Jeoi Reqi
  6. # Vulnerability Source: https://nvd.nist.gov/vuln/detail/CVE-2021-3156
  7.  
  8. """
  9. Description:
  10. This script identifies systems vulnerable to CVE-2021-3156, the Sudo Buffer Overflow Vulnerability.
  11. The vulnerability arises in Sudo versions prior to 1.9.5p2 due to an off-by-one error, potentially leading to privilege escalation.
  12.  
  13. Requirements:
  14. - Python 3.x
  15.  
  16. Usage:
  17. Execute the script using `python cve_2021_3156_sudo_buffer_overflow.py`.
  18.  
  19. Functions:
  20. - check_for_vulnerability(): Determines if the system is vulnerable.
  21. """
  22.  
  23. def check_for_vulnerability():
  24.     """
  25.    Determines if the system is vulnerable to CVE-2021-3156.
  26.    """
  27.     print("Checking for CVE-2021-3156 Sudo Buffer Overflow Vulnerability...\n")
  28.    
  29.     try:
  30.         import subprocess
  31.         import re
  32.        
  33.         output = subprocess.check_output(["sudo", "--version"])
  34.         version = re.search(r"Sudo version (\d+\.\d+\.\d+)", output.decode())
  35.        
  36.         if version:
  37.             sudo_version = version.group(1)
  38.            
  39.             if sudo_version < "1.9.5p2":
  40.                 print(f"Your system's Sudo version ({sudo_version}) is vulnerable.")
  41.                 print("Immediate action is recommended to mitigate the risk.")
  42.             else:
  43.                 print(f"Your system's Sudo version ({sudo_version}) is not vulnerable to CVE-2021-3156.")
  44.                 print("No further action is required at this time.")
  45.         else:
  46.             print("Failed to retrieve Sudo version. Please ensure Sudo is installed on your system.")
  47.    
  48.     except Exception as e:
  49.         print("An error occurred:", e)
  50.         print("Failed to check for vulnerability. Please ensure Sudo is installed and accessible on your system.")
  51.  
  52. if __name__ == "__main__":
  53.     check_for_vulnerability()
  54.  
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement