Tag: Active Directory

  • Kerberoasting and AS-REP roasting: how service tickets get cracked offline, and what actually stops it

    Kerberoasting and AS-REP roasting: how service tickets get cracked offline, and what actually stops it

    The attack lives mostly outside your logs

    Flow diagram: an attacker with any domain user requests service tickets from the domain controller, carries them offline for cracking, with detection points and a bar comparison of RC4, AES256 and gMSA guessing speed

    The diagram shows where Kerberoasting is visible to defenders and why the encryption type changes the cost of guessing.

    Most Active Directory attacks that matter share one trait: the noisy part happens on the attacker’s own hardware. Kerberoasting is the cleanest example. Tim Medin presented it in 2014, and it still works in 2026 on a depressing share of the domains I get to look at, because it needs nothing but an ordinary domain account.

    Any authenticated user can ask a domain controller for a service ticket (a TGS) for any account that has a service principal name (SPN) registered. The KDC doesn’t check whether you’re allowed to use the service. Authorization is the service’s job. Part of that ticket is encrypted with a key derived from the service account’s password. So the attacker requests tickets for every SPN-bearing account, carries them away, and guesses passwords against them at GPU speed. No lockouts, no failed logons, no traffic to the target service.

    If the service account password is “Summer2019!” the game is over in seconds. If it’s 25 random characters, the game is also over, but in the defender’s favor.

    Why the encryption type decides everything

    The ticket is encrypted with whatever the account supports. For RC4 (etype 23), the key is the account’s NT hash, which is an unsalted MD4 of the password. Cracking it means computing MD4 and a couple of HMAC-MD5 rounds per guess. That is very fast on a GPU. Public hashcat benchmarks put a single modern card in the billions of guesses per second for this mode (hashcat mode 13100).

    For AES256 (etype 18, RFC 3962), the key comes from PBKDF2 with 4096 iterations and a salt built from the realm and principal name. Each guess costs thousands of HMAC computations, and the salt kills precomputed tables. Hashcat handles these too (modes 19600 for etype 17 and 19700 for etype 18), and the speed difference against RC4 is orders of magnitude. I won’t quote an exact ratio because it varies by card and by version.

    The attacker picks the encryption type in the request, and the KDC will usually go along with RC4 if the account allows it. That is why “AES only” on service accounts matters more than most password policy tweaks. It turns a weak password from an instant loss into a slow one, and a strong password from a hard problem into a practically impossible one.

    AS-REP roasting is the same idea, one step earlier

    Kerberos pre-authentication makes a client prove it knows the password before the KDC hands anything back. If an account has the “Do not require Kerberos preauthentication” flag (DONT_REQ_PREAUTH), anyone on the network can send an AS-REQ for that user and get back an AS-REP, part of which is encrypted with the user’s key. No domain credentials are needed at all, which is the difference from Kerberoasting. Hashcat mode 18200 covers the RC4 flavor.

    I’ve never found a legitimate modern reason for this flag. It exists for ancient Kerberos clients and for the occasional “temporary” fix that nobody reverted. One line finds them:

    Get-ADUser -Filter 'DoesNotRequirePreAuth -eq $true' -Properties DoesNotRequirePreAuth |
      Select-Object SamAccountName, Enabled

    Clear the flag, and if something breaks, fix the something.

    Finding your exposure

    Start by listing which user accounts carry SPNs and what encryption they advertise. Computer accounts have random 120-character passwords that rotate, so ignore them. User accounts are the problem.

    Get-ADUser -Filter 'ServicePrincipalName -like "*"' `
      -Properties ServicePrincipalName, PasswordLastSet, 'msDS-SupportedEncryptionTypes' |
      Select-Object SamAccountName, PasswordLastSet,
        @{n='EncTypes';e={$_.'msDS-SupportedEncryptionTypes'}},
        @{n='SPNs';e={$_.ServicePrincipalName -join ';'}}

    An empty or zero `msDS-SupportedEncryptionTypes` means the domain default applies, and for years that default allowed RC4. Microsoft has been tightening the KDC defaults away from RC4 over several rounds of updates, so check your own domain controllers’ behavior instead of assuming. Sort by `PasswordLastSet`. A service account whose password predates the person who currently runs the service is the first one I’d fix.

    The fixes, in the order I’d do them

    First, move service accounts to group managed service accounts (gMSA) wherever the software supports it. The domain generates a long random password and rotates it on a schedule (30 days by default), and nobody ever types it. Kerberoasting a gMSA gets the attacker a ticket they will never crack. Plenty of older software can’t use gMSAs, which is the whole reason the other fixes exist.

    Second, for accounts that must stay as ordinary users, set a long random password. Twenty-five characters from a password manager is fine. Length matters more than complexity rules here, because the attacker is guessing offline against the hash.

    Third, restrict the account to AES:

    Set-ADUser svc_sql -KerberosEncryptionType AES128,AES256

    Test this on a non-production service first. A service host or an old client that only speaks RC4 will start failing, and you want to learn that in a maintenance window. Also, changing the supported types doesn’t change the stored keys until the password is next changed, so reset the password after setting the flag.

    Fourth, strip privileges. A Kerberoastable account in Domain Admins is a disaster waiting for a lazy password. I’ve seen SQL service accounts with domain admin rights because someone once needed to get an install working. Cracking that one ticket is the whole engagement.

    Detection that has a decent signal-to-noise ratio

    Event ID 4769 (a Kerberos service ticket was requested) fires constantly in a normal domain, so alerting on it raw is useless. What works is filtering on shape.

    Ticket Encryption Type 0x17 (RC4) against a user-account SPN, in a domain where almost nothing should still negotiate RC4, is a strong signal. A single account requesting tickets for many different SPNs in a short window is the other. Roasting tools usually enumerate every SPN in one pass, so a burst of 4769 events from one client for dozens of services stands out against a baseline of one or two.

    For AS-REP roasting, look at event 4768 with Pre-Authentication Type 0 for any account. After you’ve cleared the flag, any hit is an attempt against an account that shouldn’t exist.

    My favorite control is cheap. Create a decoy user with an SPN that looks juicy (something like `MSSQLSvc/backup-sql01`), give it a 30-character random password and no real privileges, and alert on any ticket request for it. Nobody has a legitimate reason to request that ticket, so there’s no baseline to tune. The only caveat is that it catches the attacker who roasts everything, not the one who picks a single target.

    What this doesn’t solve

    Everything above makes cracking harder or noisier. None of it stops the ticket request, because the KDC is behaving as designed. If a domain account can be phished or purchased, the attacker gets to try. So pair it with controls on the first foothold: phishing-resistant MFA, tiering so service accounts can’t log on interactively to workstations, and limited blast radius for every account that holds an SPN.

    I’d also be wary of any assessment that reports Kerberoasting as “found 40 roastable accounts” as the finding. The useful measure is how many of those would fall to a 10-billion-guess wordlist attack and what each one can reach. A roastable account with a 25-character password and no privileges is mostly a note. A roastable account with a seven-year-old password in a privileged group is an incident you haven’t had yet.

  • Segmentation and limiting lateral movement

    Segmentation and limiting lateral movement

    Part 2 of 3 in the Surviving ransomware series. Part 1: Backups an attacker can’t delete.

    When NotPetya hit in June 2017, it didn’t need anyone to click anything after the first infection. It spread across networks on its own, using the EternalBlue exploit for SMBv1 (MS17-010) and credentials harvested from memory on machines it had already reached, then running itself remotely with legitimate Windows tools. Maersk lost tens of thousands of machines in a few hours. The White House later put the total global damage at more than $10 billion.

    What made it so destructive wasn’t novel malware engineering. It was flat networks and shared credentials. Every compromised machine could reach thousands of others, and many of them would accept the same admin password.

    Part 1 of this series covered backups an attacker can’t delete. This part is about making the attacker’s path to those backups, and to everything else, as short and noisy as possible.

    Two kinds of segmentation

    Flat network compared with a segmented network of zones and allowlisted flows

    Most people think of segmentation as VLANs and firewalls. That’s half of it. The other half is identity segmentation: which credentials exist on which machines. An attacker moves laterally by combining reachability (can I connect to that host?) with authority (do I have a credential it accepts?). Take away either one and the move fails.

    Network segmentation limits reachability. Identity segmentation limits the value of whatever credentials an attacker steals. You need both, and the identity half is usually cheaper.

    Workstations shouldn’t talk to each other

    In most offices there’s no business reason for one laptop to open an SMB, RDP or WinRM connection to another laptop. Yet in a default Windows domain with file sharing enabled, that’s exactly what’s allowed, and it’s how a single phished laptop becomes fifty.

    Block it. Inbound SMB (445), RDP (3389) and WinRM (5985 and 5986) on workstations should only be accepted from a small management subnet where your admin jump hosts and management tools live. In Group Policy you’d scope the inbound firewall rules to that subnet. The PowerShell equivalent on a single machine shows the idea:

    # Allow inbound SMB, RDP and WinRM only from the management subnet
    $mgmt = "10.20.0.0/24"
    Get-NetFirewallRule -DisplayGroup "File and Printer Sharing",
                                      "Remote Desktop",
                                      "Windows Remote Management" |
      Where-Object { $_.Direction -eq "Inbound" -and $_.Enabled -eq "True" } |
      Set-NetFirewallRule -RemoteAddress $mgmt

    Then check it from an ordinary workstation, not from the admin network:

    Test-NetConnection -ComputerName ws-0142 -Port 445
    # TcpTestSucceeded : False   <- what you want to see

    I’ve watched this single change turn a domain-wide incident into a handful of machines. It’s dull, cheap, and it breaks almost nothing.

    Servers get allowlists, not blocklists

    Servers are harder because they do need to talk to each other, just not to everything. Start from observed flows. VPC flow logs, NetFlow from your switches, or a few weeks of host firewall logging will show you what actually connects to what. Then write rules that permit those flows and drop the rest.

    On a Linux database server, the host firewall alone can enforce most of it:

    # /etc/nftables.conf (excerpt)
    table inet filter {
      chain input {
        type filter hook input priority 0; policy drop;
        ct state established,related accept
        iif "lo" accept
        ip saddr 10.20.0.0/24 tcp dport 22 accept     # admin jump hosts only
        ip saddr 10.30.1.0/24 tcp dport 5432 accept   # application tier only
        icmp type echo-request limit rate 5/second accept
      }
    }

    Host firewalls and network firewalls complement each other. The network layer protects you when a host is misconfigured, and the host layer protects you from the neighbour in the same VLAN. Microsegmentation products automate this at scale, but the principle doesn’t need a product.

    Tier your admin accounts

    Microsoft’s tiering guidance, now folded into its enterprise access model, comes down to one rule: a credential that controls a high-value system must never be typed into, or cached on, a lower-value system. Domain admin accounts don’t log on to workstations. Server admin accounts don’t log on to workstations either. Help desk accounts that do manage workstations have no rights on servers.

    When an attacker dumps credentials from a compromised laptop, tiering decides what they find. With it, they get the laptop user and maybe a workstation-admin account. Without it, they often get domain admin, because someone remoted in to fix a printer driver last month.

    The supporting controls are well documented and mostly free:

    • Windows LAPS, built into Windows since the April 2023 updates, gives every machine a unique, rotated local administrator password, which kills the “same local admin password everywhere” path NotPetya-style tools rely on.
    • The Protected Users group stops its members’ credentials from being cached in ways that are easy to steal, and blocks NTLM authentication for them.
    • Credential Guard isolates secrets in virtualisation-based security so that memory scraping on the endpoint returns far less.
    • Restricting or auditing NTLM reduces relay and pass-the-hash opportunities. Start in audit mode, because something old in your environment will depend on it.

    Admins work from dedicated privileged access workstations or jump hosts in the management subnet. That’s what makes the firewall scoping above workable.

    Put the crown jewels behind their own door

    Some systems deserve their own zone with its own entry controls: domain controllers, backup infrastructure, hypervisor management, PKI, and identity providers. As covered in part 1, the backup server in particular shouldn’t be reachable from general server networks, and shouldn’t trust the production domain.

    The test I use is simple. Pick a random workstation and a random application server, assume both are fully compromised, and ask how many hops it takes to reach a domain controller or the backup console. If the answer is “one” or “it’s in the same VLAN”, that’s your next project.

    See the east-west traffic

    Segmentation also makes detection easier, because it creates boundaries where unusual traffic stands out. A workstation attempting SMB connections to forty other workstations in five minutes should alert. So should a service account authenticating to hosts it has never touched before, or remote service creation (Windows event 7045) on machines where nobody deploys software that way. Firewall drop logs between zones are useful here: once the rules are tight, almost every drop is worth a look.

    Expect it to be incremental

    Nobody segments a flat network in a quarter. Start with the workstation peer-to-peer block and LAPS, which together cover a huge share of real-world spread. Then tier the admin accounts, then wall off the crown jewels, then work through server allowlists one application at a time.

    Even perfect segmentation won’t stop every incident. It buys time and turns a company-wide outage into a contained one, which matters a lot when you get to part 3: actually restoring what was hit, and finding out how long that really takes.

    Other parts: Part 1: Backups an attacker can’t delete. Part 3: Restore testing and your real recovery time.