New Admins and Rare Processes
Some of the strongest detections need no knowledge of any particular attack. They ask only: has this ever happened here before? An account that becomes a domain admin for the first time, an admin logon from an account that never had admin rights, a parent process starting a child it has never started on any machine. Attackers need privileges and they need to run programs, and both leave first-time events behind. This lesson builds two "first seen" and "rare" detections on synthetic data and shows how to keep them from drowning in legitimate change.
The idea: baselines of what is normal
A first-seen rule keeps a set of known values per entity (the members of each privileged group, the hosts each admin uses, the parent → child process pairs) built from a look-back period, typically 14 to 90 days, and alerts on anything outside it. A rare rule counts how often and on how many hosts each value occurs, and alerts on the long tail. Both need the baseline to be clean (built before the intrusion) and maintained (updated as the environment changes).
Detection 1: a new member of a privileged group
Windows records group membership changes on domain controllers: Event ID 4728 (member added to a security-enabled global group), 4732 (local group, which includes domain-local groups such as Administrators on DCs) and 4756 (universal group). Event ID 4672 records a logon that received special privileges, which is how first-time admin activity shows up even without a group change. More IDs are in The Key Event IDs and Sysmon.
import pandas as pd
PRIVILEGED = {"Domain Admins", "Enterprise Admins", "Administrators", "Schema Admins", "Backup Operators"}
baseline_members = {"Domain Admins": {"adm-alice", "adm-bob"}, "Administrators": {"adm-alice", "adm-bob", "svc-backup"},
"Backup Operators": {"svc-backup"}}
baseline_4672 = {"adm-alice", "adm-bob", "svc-backup", "SYSTEM"} # accounts that logged on with privileges in 30 days
today = pd.DataFrame([
("09:12", 4728, "adm-bob", "Helpdesk", "carol"), # normal: helpdesk is not privileged
("10:02", 4672, "adm-alice", "", ""),
("11:30", 4732, "adm-alice", "Administrators", "adm-dave"), # change ticket CHG-311: new admin
("02:41", 4728, "svc-backup", "Domain Admins", "hank"), # the service account adds a user at night
("02:44", 4672, "hank", "", ""),
("15:05", 4672, "adm-dave", "", ""),
], columns=["time", "id", "actor", "group", "member"])
APPROVED_CHANGES = {("Administrators", "adm-dave"): "CHG-311"}
for r in today.sort_values("time").itertuples():
if r.id in (4728, 4732, 4756) and r.group in PRIVILEGED and r.member not in baseline_members.get(r.group, set()):
ticket = APPROVED_CHANGES.get((r.group, r.member))
sev = "info (approved " + ticket + ")" if ticket else "HIGH"
print(f"{r.time} {r.id} new member {r.member} in {r.group} by {r.actor}: {sev}")
elif r.id == 4672 and r.actor not in baseline_4672:
print(f"{r.time} {r.id} first privileged logon of {r.actor}")02:41 4728 new member hank in Domain Admins by svc-backup: HIGH
02:44 4672 first privileged logon of hank
11:30 4732 new member adm-dave in Administrators by adm-alice: info (approved CHG-311)
15:05 4672 first privileged logon of adm-dave
Four of the six events are reported, at two levels. The approved change (adm-dave, ticket CHG-311) is information, and so is adm-dave's first privileged logon that afternoon, which the change explains. The night-time pair is the alert: the backup service account adding a regular user, hank, to Domain Admins at 02:41, and hank logging on with privileges three minutes later. A service account changing group membership is wrong in itself; whoever controls it (see DCSync and Replication Rights and A Small Detection Pipeline for how that happens) now has a domain admin of their own. carol's addition to Helpdesk is ignored because Helpdesk is not in the privileged list, which is only correct if Helpdesk really has no admin rights: groups that can reset admins' passwords are privileged too.
Detection 2: rare parent → child processes
Office applications start a few children (a browser for a link, a print helper); they rarely start PowerShell, rundll32.exe or mshta.exe, and when they do it is often a malicious document. Rather than listing every bad pair, stack all pairs across the fleet for a week and look at the bottom of the list. The synthetic week below covers 40 workstations.
import numpy as np, pandas as pd
rng = np.random.default_rng(11)
hosts = [f"ws{i:02d}" for i in range(1, 41)]
common = [("explorer.exe", "chrome.exe"), ("explorer.exe", "outlook.exe"), ("explorer.exe", "winword.exe"),
("explorer.exe", "excel.exe"), ("outlook.exe", "chrome.exe"), ("svchost.exe", "taskhostw.exe"),
("services.exe", "svchost.exe"), ("winword.exe", "splwow64.exe"), ("explorer.exe", "teams.exe")]
rows = [(h, *common[rng.integers(len(common))]) for h in hosts for _ in range(60)]
rows += [("ws07", "cmd.exe", "lab-inventory.exe")] * 3 + [("ws21", "cmd.exe", "lab-inventory.exe")] * 3 # IT tool
rows += [("ws31", "excel.exe", "cmd.exe")] * 2 # finance macro
rows += [("ws15", "winword.exe", "powershell.exe"), ("ws15", "powershell.exe", "rundll32.exe"), # the intrusion
("ws15", "rundll32.exe", "whoami.exe")]
ev = pd.DataFrame(rows, columns=["host", "parent", "child"])
stack = (ev.groupby(["parent", "child"])
.agg(events=("host", "size"), hosts=("host", "nunique"), on=("host", lambda s: ",".join(sorted(set(s))) if s.nunique() <= 3 else "(many)"))
.sort_values(["hosts", "events"]))
print(f"{len(ev)} process events, {len(stack)} distinct parent>child pairs\n")
print("bottom of the stack (rarest pairs):")
print(stack.head(6).to_string())
suspicious_parents = {"winword.exe", "excel.exe", "outlook.exe", "powershell.exe", "rundll32.exe", "mshta.exe"}
rare = stack[(stack.hosts <= 2) & stack.index.get_level_values("parent").isin(suspicious_parents)]
print("\nALERTS (rare pair with a high-risk parent):")
for (p, c), r in rare.iterrows():
print(f" {p} > {c} on {r.on} ({r.events} events)")2411 process events, 14 distinct parent>child pairs
bottom of the stack (rarest pairs):
events hosts on
parent child
powershell.exe rundll32.exe 1 1 ws15
rundll32.exe whoami.exe 1 1 ws15
winword.exe powershell.exe 1 1 ws15
excel.exe cmd.exe 2 1 ws31
cmd.exe lab-inventory.exe 6 2 ws07,ws21
outlook.exe chrome.exe 244 40 (many)
ALERTS (rare pair with a high-risk parent):
powershell.exe > rundll32.exe on ws15 (1 events)
rundll32.exe > whoami.exe on ws15 (1 events)
winword.exe > powershell.exe on ws15 (1 events)
excel.exe > cmd.exe on ws31 (2 events)
2,411 events collapse into 14 pairs, and the bottom of the stack is where the story is. The three rarest pairs are all on ws15 and form a chain: Word started PowerShell, PowerShell started rundll32.exe, and that ran whoami.exe, which is what an intruder types first to see who they are. The finance macro on ws31 (excel.exe > cmd.exe, twice) also alerts: rare and with a risky parent, but benign. The IT inventory tool on two hosts is rare as well, but its parent cmd.exe is not on the high-risk list, so it stays in the hunting view rather than the alert queue.
How these rules are kept useful
- Approved change feeds. Join group changes with the change-management system (as
APPROVED_CHANGESdoes); an approved change becomes information, an unapproved one an alert. - Peer groups. "Rare" is relative: a process that is rare across the company may be normal for the five developers. Stack within peer groups (department, server role) as well as fleet-wide.
- Baseline updates with quarantine. Add new values to the baseline only after they have been seen for a while without an incident, so an attacker's first actions do not become "normal" the next day.
- Severity by the target. A new Domain Admin is always high; a new local admin on one workstation is medium.
How the weaknesses are fixed
Detection catches privilege changes and odd executions; prevention reduces them:
- Few standing admins. Tiered administration, just-in-time elevation and the Protected Users group make a new admin a rare, reviewable event (Tiered Administration and PAWs).
- Least privilege for service accounts.
svc-backupshould not have rights to change Domain Admins at all; review ACLs (Weak ACLs and Attack Paths). - Block risky child processes. Attack surface reduction rules on Windows can block Office applications from creating child processes; macros from the Internet are blocked by default in current Office versions; application control (WDAC, AppLocker) restricts what runs at all.
Pitfalls
- Baselines built on compromised data. If the intruder was already present during the look-back, their activity is "normal". Build baselines from a period you have reason to trust, and review the baseline itself.
- Name-based pairs.
powershell.exerenamed tonotepad.exebreaks name stacking; stack on hashes or original file names from the PE header (Sysmon'sOriginalFileName) too. - Alerting on every rare pair. The bottom of the stack also contains new software and one-off admin tasks; restrict alerts to high-risk parents and children, and send the rest to a hunting queue (Hypothesis-Driven Hunting).
Practice
1. Why is the 4672 of `hank` at 02:44 more convincing evidence than the 4728 alone?
The 4728 shows a change; the 4672 shows that the new member actually used the privileges three minutes later. Together they show intent and use, at night, by an account that had never had privileges.
2. Stack by child only (ignoring the parent). Which pairs would you lose?
cmd.exe appears as a child of excel.exe only, whoami.exe of rundll32.exe only, but powershell.exe might be common as a child of explorer.exe (admins open it) and would no longer look rare. The parent → child relationship carries the context; children alone lose it.
3. The finance macro on ws31 alerts every month at closing. What do you do?
Confirm with the owner what the macro does, then add a narrow allow-list entry (host ws31 or the finance peer group, parent excel.exe, child cmd.exe, and the exact command line or script hash) with an owner and an expiry date; better, ask finance to replace the macro with a tool that does not spawn a shell.
Test yourself
What does a first-seen rule compare an event against?
- A list of known malware hashes
- A baseline of values seen for that entity over a look-back period
- The CVSS score
- The firewall rules
Which Windows event ID records a member added to a security-enabled global group such as Domain Admins?
- 4624
- 4728
- 4688
- 1102
Why stack parent > child pairs across the fleet?
- To find the most common programs
- Rare pairs at the bottom of the stack, such as winword.exe > powershell.exe on one host, point to unusual and often malicious execution
- To measure CPU use
- To count users
What is the main danger in building a baseline from the last 30 days?
- It is too small
- If the intruder was already active, their behaviour becomes part of 'normal'
- It uses too much disk
- None