Skip to main content

Crate gpo_forge

Crate gpo_forge 

Source
Expand description

gpo-forge — offensive Group Policy Object write payloads.

§What SharpGPOAbuse-class attacks need

Once an attacker has Write on a GPO object (via a delegated OU creator, gPLink write, or SDDL misconfiguration), they can turn that into machine or user compromise by dropping one of a small set of well-known files into SYSVOL:

  • AddLocalAdmin → append a SID to [Group Membership] in Machine\Microsoft\Windows NT\SecEdit\GptTmpl.inf. Applies via the Security CSE on the next gpupdate. Persistent because the CSE sets group membership — it doesn’t merge — so a scheduled reset from a legitimate admin gets clobbered every 90 minutes.

  • NewImmediateTask → drop a ScheduledTasks.xml at Machine\Preferences\ScheduledTasks\ScheduledTasks.xml. The Scheduled Tasks CSE registers the task as SYSTEM at policy-refresh time and runs it exactly once (Immediate). Combined with an attacker-controlled command line this is a clean SYSTEM RCE on every machine the GPO applies to.

Both attacks need three extra pieces the CSE machinery relies on:

  1. gpt.ini at the GPO root, with the Version= field bumped so clients pick up the change.
  2. gPCFileSysPath — the LDAP path pointing at the SYSVOL directory (must exist and match the GUID; the caller already has this).
  3. gPCMachineExtensionNames (LDAP) updated so the CSE actually processes the newly-added file — Windows only runs a CSE if its GUID appears in the extension list.

§What this crate builds

  • add_local_admin_gpttmpl — the full GptTmpl.inf content that adds trustee_sid to BUILTIN\Administrators. Overwrites any existing file — the caller merges if merge semantics are needed.
  • new_immediate_task_xml — the ScheduledTasks.xml content registering an Immediate task that runs command as SYSTEM.
  • gpt_ini — the gpt.ini content with Version=<n>.
  • bump_gpo_version_number — the versionNumber math (upper 16 bits = user counter, lower 16 = computer counter).
  • cse_list_add — merge a required CSE GUID into an existing gPCMachineExtensionNames / gPCUserExtensionNames value.
  • CSE GUID constants (CSE_GUID_*) for the two attacks above.

§What this crate does not do

  • No SYSVOL SMB write. Use smb2-client or your existing SMB layer.
  • No LDAP write for versionNumber / gPCMachineExtensionNames. Use adhammer-ldap / msldap-ext / ldap3.
  • No permission preflight — the caller is expected to verify write ACL on the GPO (via ad-acl) before invoking these builders.

Constants§

CSE_GUID_SCHEDULED_TASKS
Scheduled Tasks Preference CSE — consumes ScheduledTasks.xml.
CSE_GUID_SECURITY
Security CSE — the client-side extension that consumes GptTmpl.inf and applies group-membership + security-options policy.
TOOLEXT_GUID_GPP
The generic Group Policy Preferences (client-side) tool extension GUID paired with every GPP CSE.
TOOLEXT_GUID_SECURITY
The “Security” toolExtensionGuid that must appear on the User side of the extension name list for user policy. For our Machine-scoped attacks we don’t need this.

Functions§

add_local_admin_gpttmpl
Build the full GptTmpl.inf content that adds trustee_sid to BUILTIN\Administrators (*S-1-5-32-544) via the Security CSE’s [Group Membership] section.
bump_gpo_version_number
Compute the new versionNumber value for a GPO’s LDAP attribute.
cse_list_add
Merge required_cse + required_toolext into an existing gPCMachineExtensionNames (or gPCUserExtensionNames) value.
gpt_ini
Build a gpt.ini file with Version=<n>. display_name is written into the (informational) DisplayName= field the ADMX loader shows.
new_immediate_task_xml
Build the ScheduledTasks.xml content that registers an Immediate task running command (with optional arguments) as NT AUTHORITY\SYSTEM exactly once at next policy refresh.
split_gpo_version_number
Split a packed versionNumber into (user, computer) counters.