Advertisement
Python253

show_win_credentials

Jun 23rd, 2024
507
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.51 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Filename: show_win_credentials.py
  4. # Version: 1.0.0
  5. # Author: Jeoi Reqi
  6.  
  7. """
  8. Description:
  9.    This script retrieves and displays all credentials stored in the Windows Credential Manager.
  10.  
  11. Requirements:
  12.    - Python 3.x
  13.    - Windows OS (10+)
  14.    - pywin32 (Python extensions for Windows)
  15.  
  16. Functions:
  17.    - get_all_credentials():
  18.        Retrieves and prints all credentials stored in Credential Manager.
  19.        
  20. Credential Types:
  21.    #1 (GENERIC):
  22.        - Generic credentials that typically store username/password pairs for network resources.
  23.  
  24.    #2 (DOMAIN_PASSWORD):
  25.        - Credentials used to authenticate against a Windows domain controller using a password.
  26.  
  27.    #3 (DOMAIN_CERTIFICATE):
  28.        - Credentials that store certificates used for domain authentication.
  29.  
  30.    #4 (DOMAIN_VISIBLE_PASSWORD):
  31.        - Domain credentials displayed and stored in a visible form.
  32.  
  33.    #5 (GENERIC_CERTIFICATE):
  34.        - Generic credentials storing certificates for authentication.
  35.  
  36.    #6 (DOMAIN_EXTENDED):
  37.        - Domain credentials with additional information like smart card data beyond username and password.
  38.  
  39. Usage:
  40.    - Ensure Python 3.x is installed.
  41.    - Install pywin32 package (`pip install pywin32`).
  42.    - Run the script (`python show_credentials.py`).
  43.  
  44. Additional Notes:
  45.    - Make sure to run the script with appropriate permissions to access Credential Manager.
  46. """
  47.  
  48. import win32cred
  49. import sys
  50.  
  51. def get_all_credentials():
  52.     """
  53.    Retrieves and prints all credentials stored in the Windows Credential Manager.
  54.    
  55.    Raises:
  56.        Exception: If there is an error while retrieving credentials.
  57.    """
  58.     try:
  59.         creds = win32cred.CredEnumerate()
  60.         if not creds:
  61.             print("No credentials found in Credential Manager")
  62.             return
  63.        
  64.         for cred in creds:
  65.             target_name = cred['TargetName']
  66.             username = cred['UserName']
  67.             credential_type = cred['Type']
  68.            
  69.             print(f"- Target Name: {target_name}")
  70.             print(f"- Username: {username if username else 'N/A'}")
  71.             print(f"- Credential Type: {credential_type}")
  72.             print("-----")
  73.     except Exception as e:
  74.         print(f"Failed to retrieve credentials: {str(e)}")
  75.         sys.exit(1)
  76.  
  77. if __name__ == "__main__":
  78.     print("\n\t\tGathering Stored Credentials...\n\n-----")
  79.     get_all_credentials()
  80.     print("\n\t\tExiting Program...\t   GoodBye!\n")
  81.  
  82.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement