🔏
RootGuard
HomeSOC OperationsIncident ResponseWindows ForensicsLinux ForensicsKQL Investigations
  • Welcome
    • RootGuard
      • Who Am I?
        • Professional Profile
  • Resources Hub
    • Blogs
      • Articles
        • Safeguarding SMEs: The Strategic Importance of a Security Operations Center (SOC)
      • Posts
        • Roadmap to Becoming a Cybersecurity Specialist
        • Starting a Career in Cybersecurity
        • A Guide to Landing Your First Cybersecurity Analyst Role
        • Moving from Intermediate to Expert Incident Responder
  • SOC Operations
    • Introduction
      • Development Resources
        • SOC Analysts Roadmap
        • Becoming A SOC Analyst
        • SOC Analysts Prep Interview Questions
    • Essential Skills
      • Critical Windows EventIDs to Monitor
    • Junior Analyst Skills
      • Splunk Use Cases
      • KQL Use Cases
        • Reconnaissance (TA0043)
        • Initial Access (TA0001)
        • Execution (TA0002)
        • Persistence (TA0003)
        • Privilege Escalation (TA0004)
        • Defence Evasion (TA0005)
        • Credential Access (TA0006)
        • Discovery (TA0007)
        • Lateral Movement (TA0008)
        • Collection (TA0009)
        • Command and Control (TA0011)
        • Exfiltration (TA0010)
        • Impact (TA0040)
      • Investigating Common Attacks
        • Domain Dominance Attacks - Detection & Analysis
        • Investigating a Suspected AD FS Distributed Key Management (DKM) Attack
        • Authentication From Suspicious DeviceName
        • Identifying Interactive or RemoteInteractive Session From Service Account
        • Identifying Split or Part Archive File Transfers
        • Detect Potential Cleartext Credentials in Command Line
        • Detecting Command Line Interpreters Launched via Scheduled Tasks
        • Detecting Files Containing Potentially Sensitive Data
        • Detecting DeviceNetworkEvents From Windows Processes and Domains by TLD
        • Detecting Silent cmd.exe Execution With Redirected STDERR & STDOUT
        • Detecting Low Prevalence DLL Loaded From Process In User Downloads Directory
        • Detecting Virtual Drive Mounted From Archive
        • Identify Execution of Script From User's Downloads Folder
        • Identify Potential RDP Tunneled Sessions
        • Identify Instances of PowerShell Invoke-WebRequest, IWR or Net.WebClient
        • Identify Processes Launched by PowerShell Remoting (WSMProvHost.exe)
        • Detect DeviceNetworkEvents for LOLBAS with Download or Upload Functions
        • Detect Execution of PSEXESVC via Remote Systems
        • Identify Suspicious String in Service Creation ImagePath
        • Identify File with Double Extensions
        • Detect Potential Cleartext Credentials in Commandline
        • Detect When Large Number of Files Downloaded From OneDrive or SharePoint
        • Identify and Investigate Phishing Attacks with KQL
      • PowerShell for SecOps
        • Powershell Remoting
        • Reconnaissance Discovery
        • Initial Access Discovery
        • Execution Discovery
        • Persistence Discovery
        • Privilege Escalation Discovery
        • Defence Evasion Discovery
        • Credential Access Discovery
        • Discovery
        • Lateral Movement Discovery
        • Collection Discovery
        • Command & Control (C2) Discovery
        • Exfiltration Discovery
        • Impact Discovery
      • Packet Analysis (pcap)
        • Tcpdump
        • Tcpdump (Intermediate)
        • Tshark
        • Ngrep
      • Investigating Suspicious Emails Using KQL
    • Intermediate and Advanced Skills
      • Investigate Using MITRE ATT&CK Methodology
        • Reconnaissance (TA0043) Techniques
        • Resource Development (TA0042) Techniques
        • Initial Access (TA0001) Techniques
        • Command Execution (TA0002) Techniques
        • Persistence (TA0003) Techniques
        • Privilege Escalation (TA0004) Techniques
        • Defence Evasion (TA0005) Techniques
        • Credential Access (TA0006) Techniques
        • Discovery (TA0007) Techniques
        • Lateral Movement (TA0008) Techniques
        • Collection (TA0009) Techniques
        • Command and Control (C2) (TA0011) Techniques
        • Exfiltration (TA0010) Techniques
        • Impact (TA0040) Techniques
    • Vulnerability Management
    • Malware Analysis
  • DFIR
    • Incident Response
      • Incident Triage
        • Triage Types and Processes
        • PowerShell for Detection and Analysis
          • Malware or Compromise Investigation
          • Lateral Movement Discovery
        • Registry Analysis
        • Sysinternals Intrusion Analysis
        • PowerShell Intrusion Analysis
        • Velociraptor Intrusion Analysis
        • Zimmerman Tools Intrusion Analysis
      • KAPE Artifacts Analysis
      • Velociraptor Artifacts Analysis
      • Using The Unified Kill Chain Model to Analyse Individual Cyber Attacks
        • Phase 1 - Gaining an Initial Foothold
          • Gaining Access to the Network
          • Establishing a Foothold
          • Network Discovery
      • Response Strategies
        • Privilege Escalation Assessment
        • Command and Control Assessment
        • Command Execution Assessment
        • Defence Evasion Assessment
        • Detection Assessment
        • Discovery Assessment
        • Exfiltration Assessment
        • Initial Access Assessment
        • Initial Impact Assessment Techniques
        • Lateral Movement Assessment
        • Persistence Assessment
    • Windows Forensics
      • Evidence of Execution
      • Window Artifact Analysis
        • Account Usage
        • User Activity Tracking (Event Logs)
        • Program Execution
        • File and Folder Opening
        • File Download
        • Browser Usage
        • Deleted File or File Knowledge
        • External Device & USB Usage
    • Linux Forensics
      • Linux Commandline Basics
      • Host Compromise Assessment
    • KQL for Defender & Sentinel
      • MDO (Office)
      • MDI (Identity)
      • MDE (Endpoint)
    • Memory Forensics
      • Memory Forensics (Volatility 3)
    • Playbooks
      • First Responder DFIR Playbook
        • Device Isolation
        • Evidence Collection
          • Acquire Triage Image Using KAPE
          • Acquire Triage Data Using Velociraptor
          • Acquire Triage Data Using Powershell
          • Acquire Triage Memory Image
          • Acquire Image Using FTK
          • AXIOM Cyber Data Collection
        • Windows Forensic Artefacts
          • Application Execution
          • File & Folder Knowledge
          • External Device Usage
          • Network Activity
          • Windows Event Logs
        • Initial Analysis
          • Memory Analysis (Vol 3)
          • Axiom Cyber Examiner
  • Detection Engineering
    • AD Attack Detections & Mitigations
      • Kerberoasting
      • Authentication Server Response (AS-REP) Roasting
      • Password Spraying
      • MachineAccountQuota Compromise
      • Unconstrained Delegation
      • Password in Group Policy Preferences (GPP) Compromise
      • Active Directory Certificate Services (AD CS) Compromise
      • Golden Certificate
      • DCSync
      • Dumping ntds.dit
      • Golden Ticket
      • Silver Ticket
      • Golden Security Assertion Markup Language (SAML)
      • Microsoft Entra Connect Compromise
      • One-way Domain Trust Bypass
      • Security Identifier (SID) History Compromise
      • Skeleton Key
      • Active Directory Security Controls
      • Active Directory Events for Detecting Compromise
    • Attack Triage Playbooks (KQL Triage)
      • Windows Malware Detection Playbook
      • Linux Host Intrusion Detection Playbook (CLI)
      • Linux Intrusion Detection Playbook
      • Large-Scale Compromise Detection Playbook
      • Ransomware Detection Playbook
      • Phishing Email Compromise Detection Playbook
      • Scam Detection Playbook
      • Customer Phishing Detection Playbook
      • Insider Abuse Detection Playbook
      • Information Leakage Detection Playbook
      • Social Engineering Detection Playbook
      • Malicious Network Behaviour Detection Playbook
      • Windows Intrusion Detection Playbook
      • Vulnerability Detection Playbook
      • Business Email Compromise Detection Playbook
    • Process Execution (KQL Triage)
    • Threat Hunting
      • Hunting Ransomware Indicators
      • Hunting With KQL
        • Detecting Malware Infection (MITRE ATT&CK: T1566, T1059)
        • Discovery Activities (MITRE ATT&CK: T1016, T1083, T1046)
        • Credential Theft (MITRE ATT&CK: T1003, T1078)
        • Lateral Movement (MITRE ATT&CK: T1076, T1021)
        • Data Theft (MITRE ATT&CK: T1041, T1071)
        • Detecting CommandLine Executions (MITRE ATT&CK: T1059)
        • Windows Security Logs (Identity and Logon Activities)
      • Hunting With Splunk
Powered by GitBook
On this page
  • Introduction
  • How MachineAccountQuota Compromise Works
  • Why MachineAccountQuota Compromise is Dangerous
  • Indicators of MachineAccountQuota Compromise
  • Detection Strategies
  • Mitigation Strategies
  • KQL Detection Query
  • Splunk Detection Query
  • Reference
Edit on GitHub
  1. Detection Engineering
  2. AD Attack Detections & Mitigations

MachineAccountQuota Compromise

Introduction

MachineAccountQuota is an attribute in Active Directory that specifies how many machine accounts a user can create in the domain. By default, this value is set to 10, meaning any authenticated domain user can create up to 10 machine accounts without administrative privileges. While this setting supports certain use cases, it also introduces a security risk if exploited by attackers.

Compromise of MachineAccountQuota occurs when an attacker abuses this privilege to create unauthorised machine accounts. These accounts can then be used for malicious purposes, such as lateral movement, privilege escalation, or persistence, often bypassing standard account monitoring mechanisms.

This technique is categorised under the Persistence and Credential Access tactics in the MITRE ATT&CK Framework.


How MachineAccountQuota Compromise Works

  1. Discovery:

    • Attackers first enumerate the domain to identify the current MachineAccountQuota setting.

    • This can be done using tools like PowerShell or BloodHound.

  2. Creating Machine Accounts:

    • If the quota is greater than 0, attackers create new machine accounts. These accounts often have names ending with $ (e.g., MACHINE01$).

  3. Abusing Machine Accounts:

    • Machine accounts are assigned credentials, just like user accounts. Attackers extract the credentials (password hashes) for further use.

    • These accounts may be leveraged to:

      • Perform lateral movement within the domain.

      • Bypass monitoring systems that focus on user accounts.

      • Establish persistence by hiding malicious activities behind machine accounts.

  4. Further Exploitation:

    • Attackers may use tools like Impacket, Rubeus, or Mimikatz to dump the machine account's credentials, request Kerberos tickets, or escalate privileges.


Why MachineAccountQuota Compromise is Dangerous

  1. Default Configuration Risk:

    • The default value of 10 allows any authenticated domain user to create machine accounts, significantly expanding the attack surface.

  2. Hard-to-Monitor Accounts:

    • Machine accounts are often less scrutinised than user accounts, making them ideal for covert operations.

  3. Persistence and Evasion:

    • Attackers can create machine accounts and use them to maintain access even after compromised user accounts are disabled or locked.

  4. Privilege Escalation:

    • By controlling machine accounts, attackers can escalate privileges or impersonate legitimate systems.


Indicators of MachineAccountQuota Compromise

  1. Unusual Account Creation:

    • Creation of multiple machine accounts (accounts ending with $) by non-administrative users.

  2. High Volume of New Machine Accounts:

    • A significant number of machine accounts created within a short period.

  3. Suspicious Logon Activity:

    • Newly created machine accounts logging into sensitive systems or initiating lateral movement.

  4. Abnormal Usage of Machine Accounts:

    • Machine accounts performing tasks typically associated with user accounts, such as accessing shared resources or running administrative commands.


Detection Strategies

  1. Monitor Account Creation Logs:

    • Windows Event ID 4741: Logs when a computer account is created.

    • Windows Event ID 4720: Logs when a user account is created (occasionally relevant if attackers disguise machine accounts as users).

  2. Look for Anomalous Behavior:

    • Machine accounts (names ending with $) logging in from unusual locations or performing abnormal activities.

  3. Audit Active Directory:

    • Periodically check the MachineAccountQuota setting using PowerShell:

      powershellCopyEditGet-ADDomain | Select-Object Name, ms-DS-MachineAccountQuota
  4. Correlate with Threat Intelligence:

    • Cross-reference newly created accounts with known attack patterns or malicious tools.


Mitigation Strategies

  1. Reduce MachineAccountQuota:

    • Set ms-DS-MachineAccountQuota to 0 for most environments where non-administrative users do not need to create machine accounts:

      powershellCopyEditSet-ADDomain -Identity "DomainName" -MachineAccountQuota 0
  2. Restrict Account Creation Rights:

    • Limit the ability to create machine accounts to specific administrative groups.

  3. Enable Logging and Alerts:

    • Configure alerts for unusual account creation activity (Event ID 4741).

  4. Audit Existing Machine Accounts:

    • Regularly review machine accounts to ensure they are legitimate and necessary.

  5. Monitor for Tools and TTPs:

    • Watch for signs of attacker tools such as BloodHound, Impacket, or Rubeus, which are commonly used to enumerate and exploit Active Directory.


The MachineAccountQuota feature, while useful in specific scenarios, poses a significant security risk if left misconfigured. By understanding how attackers exploit this setting and implementing proactive detection and mitigation strategies, organisations can better protect their Active Directory environments from compromise.

The MachineAccountQuota attribute in Active Directory defines the number of machine accounts a user can create in the domain. Attackers exploit this setting to register new machine accounts and abuse these accounts for lateral movement, persistence, or further exploitation. Detecting MachineAccountQuota abuse requires monitoring account creations and anomalous behaviours related to machine accounts.

KQL Detection Query

To detect MachineAccountQuota compromise using KQL in Microsoft Sentinel or other platforms you can monitor for unusual creation of machine accounts (accounts ending with $) by non-administrative users. These activities are primarily logged under Windows Security Event ID 4741 (A computer account was created).

Query for Detecting MachineAccountQuota Compromise

SecurityEvent
| where EventID == 4741  // Computer account creation
| extend CreatedAccount = TargetUserName, InitiatorAccount = SubjectUserName
| where CreatedAccount endswith "$"  // Focus on machine accounts
| summarize CreationCount = count(), 
            CreatedAccounts = make_set(CreatedAccount), 
            UniqueInitiators = dcount(InitiatorAccount), 
            Initiators = make_set(InitiatorAccount), 
            FirstSeen = min(TimeGenerated), 
            LastSeen = max(TimeGenerated) 
    by InitiatorAccount
| where CreationCount > 5  // Threshold: Adjust based on baseline activity
| extend SuspiciousScore = case(
    CreationCount > 10, "High",
    CreationCount > 5, "Medium",
    "Low"
)
| where SuspiciousScore in ("High", "Medium")  // Focus on suspicious activity
| project InitiatorAccount, CreationCount, CreatedAccounts, UniqueInitiators, Initiators, FirstSeen, LastSeen, SuspiciousScore
| sort by SuspiciousScore desc, CreationCount desc

Query Breakdown

  1. Target Event:

    • EventID 4741: Captures the creation of computer accounts in Active Directory.

  2. Focus on Machine Accounts:

    • Filters accounts with names ending in $ (standard naming convention for machine accounts).

  3. Aggregate Data:

    • Groups activities by the InitiatorAccount (the user who created the accounts).

    • Tracks:

      • CreationCount: Total number of machine accounts created.

      • CreatedAccounts: List of machine accounts created.

      • UniqueInitiators: Number of unique users initiating account creation.

      • Initiators: Names of users initiating the activity.

  4. Threshold for Suspicion:

    • Flags users who create more than 5 machine accounts within a specific time period.

    • Assigns a SuspiciousScore based on the volume of accounts created:

      • High: More than 10 accounts.

      • Medium: More than 5 accounts.

  5. Output:

    • Provides key details for investigation, including the initiator, the created accounts, and the time range of activity.

Advanced Query with Temporal Analysis

SecurityEvent
| where EventID == 4741
| extend CreatedAccount = TargetUserName, InitiatorAccount = SubjectUserName
| where CreatedAccount endswith "$"
| bin TimeGenerated span=15m  // Group events into 15-minute intervals
| summarize CreationCount = count(), CreatedAccounts = make_set(CreatedAccount) 
    by InitiatorAccount, bin(TimeGenerated, 15m)
| where CreationCount > 3  // Adjust based on environment baseline
| extend SuspiciousScore = case(
    CreationCount > 5, "High",
    CreationCount > 3, "Medium",
    "Low"
)
| where SuspiciousScore in ("High", "Medium")
| project TimeGenerated, InitiatorAccount, CreationCount, CreatedAccounts, SuspiciousScore
| sort by TimeGenerated, SuspiciousScore desc, CreationCount desc

Customisations

  1. Whitelist Known Legitimate Activity:

    • Exclude trusted service accounts or administrators:

      | where not (InitiatorAccount in ("trusted_admin", "service_account"))
  2. Tune Thresholds:

    • Adjust thresholds for CreationCount and TimeGenerated based on your environment’s baseline.

  3. Correlate with Other Events:

    • Combine this query with events like logon activity (Event ID 4624) or privilege escalation to detect related malicious behaviour.


Additional Recommendations

  1. Audit MachineAccountQuota Settings:

    • Periodically check the ms-DS-MachineAccountQuota value in your domain:

      Get-ADDomain | Select-Object Name, ms-DS-MachineAccountQuota
  2. Enable Alerts:

    • Configure alerts for SuspiciousScore = High to notify SOC analysts of potential abuse.

  3. Dashboard Integration:

    • Visualize trends in machine account creation for proactive monitoring.

Splunk Detection Query

The MachineAccountQuota attribute in Active Directory defines the number of machine accounts a user can create in the domain. Attackers exploit this setting to register new machine accounts and abuse these accounts for lateral movement, persistence, or further exploitation. Detecting MachineAccountQuota abuse requires monitoring account creations and anomalous behaviours related to machine accounts.

Splunk Query for MachineAccountQuota Compromise Detection

index=windows EventCode=4741 OR EventCode=4720
| eval AccountName = coalesce(TargetUserName, AccountName)
| eval EventDescription = case(
    EventCode == 4741, "Computer Account Created",
    EventCode == 4720, "User Account Created",
    true(), "Unknown Event"
)
| stats count AS CreationCount, 
        values(EventDescription) AS EventTypes, 
        values(AccountName) AS CreatedAccounts, 
        values(CallerUserName) AS Initiators, 
        dc(AccountName) AS UniqueCreatedAccounts, 
        min(_time) AS FirstSeen, 
        max(_time) AS LastSeen 
    BY CallerUserName
| where UniqueCreatedAccounts > 5  // Threshold: High volume of account creations
| eval SuspiciousActivity = case(
    UniqueCreatedAccounts > 10, "High",
    UniqueCreatedAccounts > 5, "Medium",
    true(), "Low"
)
| where SuspiciousActivity IN ("High", "Medium")
| table CallerUserName, CreationCount, UniqueCreatedAccounts, CreatedAccounts, EventTypes, FirstSeen, LastSeen, SuspiciousActivity
| sort - SuspiciousActivity, -CreationCount

Query Breakdown

  1. Target Events:

    • EventCode 4741: Logs when a computer account is created.

    • EventCode 4720: Logs when a user account is created. This helps identify any abuse disguised as user account creation.

    • EventCode 4624: This event is generated when an object successfully logs on

    • EventCode 4724: This event is generated when an attempt is made to reset an object’s password.

  2. Field Normalisation:

    • Combines TargetUserName and AccountName to identify the newly created accounts.

    • Tracks the CallerUserName, which is the initiator of the account creation.

  3. Event Grouping:

    • Aggregates account creation events by the initiator (CallerUserName).

    • Captures the number of unique accounts created (UniqueCreatedAccounts) and the types of events involved (EventTypes).

  4. Suspicious Thresholds:

    • Flags initiators creating more than 5 unique accounts as potentially suspicious.

    • Assigns "High" severity if more than 10 accounts are created in a short timeframe.

  5. Final Output:

    • Displays key details for investigation:

      • CallerUserName: Who created the accounts.

      • CreatedAccounts: The accounts that were created.

      • EventTypes: Types of events (computer or user account creations).

      • SuspiciousActivity: Risk level based on the volume of account creations.

Advanced Query with Temporal Analysis

index=windows EventCode=4741 OR EventCode=4720
| eval AccountName = coalesce(TargetUserName, AccountName)
| bin _time span=15m  // Group events into 15-minute intervals
| stats count AS CreationCount, 
        values(AccountName) AS CreatedAccounts, 
        dc(AccountName) AS UniqueCreatedAccounts 
    BY CallerUserName, _time
| where UniqueCreatedAccounts > 3  // Adjust based on environment baseline
| eval SuspiciousActivity = case(
    UniqueCreatedAccounts > 5, "High",
    UniqueCreatedAccounts > 3, "Medium",
    true(), "Low"
)
| where SuspiciousActivity IN ("High", "Medium")
| table _time, CallerUserName, CreationCount, UniqueCreatedAccounts, CreatedAccounts, SuspiciousActivity
| sort - _time, -SuspiciousActivity, -CreationCount

Customisations

  1. Threshold Tuning:

    • Adjust UniqueCreatedAccounts > 5 based on normal activity in your domain.

    • Fine-tune bin _time span=15m to capture short bursts of activity.

  2. Whitelist Legitimate Activity:

    • Exclude known service accounts or administrators:

      | where NOT CallerUserName IN ("trusted_admin", "service_account")
  3. Account Filtering:

    • Focus specifically on machine accounts (accounts ending with $):

      | where like(AccountName, "%$")

Additional Recommendations

  1. Audit MachineAccountQuota Settings:

    • Regularly check the ms-DS-MachineAccountQuota setting in your Active Directory:

      Get-ADDomain | Select-Object Name, ms-DS-MachineAccountQuota
  2. Correlate with Other Events:

    • Look for lateral movement or privilege escalation attempts following the creation of machine accounts.

  3. Create Alerts:

    • Configure alerts in Splunk for "High" SuspiciousActivity.

Reference

PreviousPassword SprayingNextUnconstrained Delegation

Last updated 4 months ago

Microsoft Identity and Access documentation
Detecting and mitigating Active Directory compromises
Best Practices for Securing Active Directory
Securing Domain Controllers Against Attack
Top 25 Active Directory Security Best Practices
Active Directory Security Best Practices