TDCTF Academy Logo TDCTF ACADEMY

Lab 8: ️ Steganography Dasar - Menyembunyikan dan Menemukan Data dalam File

Target Skill: Mahasiswa mampu menyembunyikan data dalam file media (gambar/audio) dan mendeteksinya menggunakan tools forensik
Tools: steghide, zsteg, strings, xxd, binwalk, python3
Durasi: 30 menit
Level: Beginner


Mengapa Steganography Penting?

Perbedaan Steganography vs Cryptography:

  • Kriptografi - pesan diacak (terlihat mencurigakan)
  • Steganografi - pesan disembunyikan (terlihat biasa)

Attacker menggunakan steganography untuk:

  • Menyembunyikan data curian dalam foto (data exfiltration)
  • Menyembunyikan C2 configuration dalam gambar
  • Komunikasi rahasia yang tidak terdeteksi firewall
  • Malware yang mengambil perintah dari gambar di internet

Learning Objectives

  1. Memahami konsep LSB (Least Significant Bit) steganography
  2. Menyembunyikan teks dalam gambar dengan steghide
  3. Mendeteksi data tersembunyi dengan zsteg dan strings
  4. Menganalisis perbedaan file asli vs file stego

️ Tools & Setup

sudo apt install -y steghide zsteg
pip3 install Pillow 2>/dev/null || pip install Pillow 2>/dev/null

Langkah Praktikum

Step 1: Buat File Cover (Gambar Dasar)

Kita butuh gambar untuk menyembunyikan data. Buat gambar PNG sederhana:

cd ~ && mkdir forensics-lab8 && cd forensics-lab8

python3 << 'PYEOF'
from PIL import Image
import numpy as np

# Buat gambar RGB 200x200 dengan gradien warna
img = Image.new('RGB', (200, 200))
pixels = img.load()

for x in range(200):
for y in range(200):
pixels[x, y] = (x, y, (x + y) % 256)

img.save('gambar-cover.png')
print("✅ gambar-cover.png - 200x200 RGB gradient")

# Buat BMP version juga
img.save('gambar-cover.bmp')
print("✅ gambar-cover.bmp - 200x200 BMP version")
PYEOF

Step 2: Buat File Rahasia

# File rahasia untuk disembunyikan
cat > pesan-rahasia.txt << 'EOF'
=== DATA CURIAN ===
Database Server: db01.company.internal
Username: db_admin
Password: S3cur3P@ssw0rd!2024

Kartu Kredit:
- 4111-2222-3333-4444 (exp: 12/26, CVV: 123)
- 5555-6666-7777-8888 (exp: 06/25, CVV: 456)

Alamat C2 Server: https://c2.malware-control.com:8443

=== END DATA CURIAN ===
EOF

echo "✅ File rahasia dibuat: pesan-rahasia.txt"

Step 3: Sembunyikan Data dengan Steghide

steghide menyembunyikan data dalam gambar JPEG / BMP / WAV dengan enkripsi AES:

# Steghide butuh passphrase - ini simulasi
echo "=== Menyembunyikan data ==="
steghide embed -cf gambar-cover.bmp -ef pesan-rahasia.txt -p "passphrase123" -f
echo "✅ Data disembunyikan dalam gambar-cover.bmp"

# Cek ukuran - file hampir sama
echo ""
echo "=== Perbandingan Ukuran ==="
ls -lh gambar-cover.bmp gambar-cover.png pesan-rahasia.txt

# File hasil stego akan lebih besar sedikit (karena header + data terenkripsi)

Step 4: Ekstrak Data dari Stego Image

# Ekstrak dengan passphrase yang benar
echo "=== Ekstrak Data ==="
steghide extract -sf gambar-cover.bmp -p "passphrase123" -f
echo ""
echo "=== Isi Data Terekstrak ==="
cat pesan-rahasia.txt

Step 5: Deteksi - Bandingkan File Asli vs Stego

# Buat gambar bersih (tanpa stego) untuk perbandingan
python3 << 'PYEOF'
from PIL import Image
img = Image.new('RGB', (200, 200))
pixels = img.load()
for x in range(200):
for y in range(200):
pixels[x, y] = (x, y, (x + y) % 256)
img.save('gambar-bersih.bmp')
print("✅ gambar-bersih.bmp - original (no stego)")
PYEOF

# Bandingkan file
echo "=== Perbandingan File ==="
ls -lh gambar-bersih.bmp gambar-cover.bmp

echo ""
echo "=== Strings Analysis ==="
echo "--- File Bersih ---"
strings gambar-bersih.bmp | head -5
echo ""
echo "--- File Stego ---"
strings gambar-cover.bmp | head -10

Step 6: LSB Steganography - Deteksi Manual

Teknik LSB (Least Significant Bit): bit terakhir dari setiap pixel warna diubah untuk menyimpan data.

# Simulasi LSB dengan Python
python3 << 'PYEOF'
from PIL import Image
import numpy as np

# 1. Buat gambar dengan LSB steganography sederhana
img = Image.new('RGB', (100, 100))
pixels = img.load()

# Isi pixel dengan warna solid (biru)
for x in range(100):
for y in range(100):
pixels[x, y] = (0, 0, 255)

# Simpan pesan di LSB
pesan = "RAHASIA: Password admin = 12345"
bits = []
for char in pesan:
bits.extend([int(b) for b in format(ord(char), '08b')])

# Tulis bit ke LSB pixel (100 pixel pertama)
for i, bit in enumerate(bits[:300]):
x = i // 100
y = i % 100
r, g, b = pixels[x, y]
# Ubah LSB dari channel biru
pixels[x, y] = (r, g, (b & 0xFE) | bit)

img.save('lsb-stego.bmp')
print(f"✅ lsb-stego.bmp - LSB stego, pesan: '{pesan}'")
print(f" Panjang pesan: {len(pesan)} chars = {len(pesan)*8} bits")

# 2. Baca LSB untuk ekstrak
print("\n=== Ekstrak LSB ===")
img2 = Image.open('lsb-stego.bmp')
px2 = img2.load()

bits_extracted = []
for x in range(100):
for y in range(100):
r, g, b = px2[x, y]
bits_extracted.append(b & 1) # Ambil LSB

# Konversi bits ke teks
chars = []
for i in range(0, len(bits_extracted), 8):
if i + 8 <= len(bits_extracted):
byte = bits_extracted[i:i+8]
char_code = int(''.join(str(b) for b in byte), 2)
if 32 <= char_code <= 126: # Printable ASCII
chars.append(chr(char_code))
else:
break

pesan_extracted = ''.join(chars)
print(f"Pesan ditemukan: '{pesan_extracted}'")
PYEOF

Step 7: Deteksi dengan Zsteg

zsteg secara otomatis mendeteksi LSB steganography di PNG/BMP:

# Zsteg - automatic LSB detection
echo "=== zsteg - Deteksi LSB ==="
zsteg lsb-stego.bmp 2>/dev/null || echo "zsteg tidak support bmp, coba PNG..."

# Convert ke PNG
python3 -c "
from PIL import Image
Image.open('lsb-stego.bmp').save('lsb-stego.png')
print('✅ lsb-stego.png converted')
"

zsteg lsb-stego.png 2>/dev/null || echo "zsteg butuh install lengkap"

️ Analisis & Pertanyaan

1. Metode Steganography Populer

Metode Media Tools Deteksi
LSB Gambar (PNG/BMP) zsteg, manual Python Pixel noise analysis
Append Akhir file strings, hexdump Ukuran file anomali
EXIF Metadata gambar exiftool Metadata anomali
Palette GIF 256 warna Specific tools Warna ganjil
Spread Spectrum Audio spectrogram Noise dalam audio
Text Whitespace/HTML Specific tools Format anomali

2. Indikator Steganography

Indikator Penjelasan
Ukuran file tidak wajar Jauh lebih besar dari seharusnya
Metadata mencurigakan Comment field aneh, judul aneh
Warna pixel tidak natural Pola bit LSB tidak random
File di dalam file binwalk mendeteksi file kedua
Strings aneh Teks acak / random di tengah gambar

Laporan Temuan

Finding 1: Password Exfiltration via Steganography (Critical)

Parameter Value
File Carrier gambar-cover.bmp
Method Steghide (AES encrypted)
Passphrase passphrase123
Extracted Data 16 lines, incl. DB credentials & credit card numbers

Dampak: Data sensitif perusahaan bocor dalam gambar innocuous

Finding 2: LSB Steganography in BMP (High)

Parameter Value
File lsb-stego.bmp
Method LSB (Least Significant Bit)
Detected by zsteg / manual analysis
Hidden Message "RAHASIA: Password admin = 12345"

Dampak: Pesan rahasia mudah disembunyikan dan sulit dideteksi kasat mata


Korelasi OWASP / CWE / CAPEC

Kerangka ID Deskripsi
CWE CWE-200 Exposure of Sensitive Information
CWE CWE-319 Cleartext Transmission of Sensitive Information
CWE CWE-538 File and Directory Information Exposure
CAPEC CAPEC-646 Steganography (Encoding Data in Media)
CAPEC CAPEC-647 LSB Steganography
CAPEC CAPEC-648 Steganography via Image Metadata

️ Remediasi

Ancaman Deteksi Pencegahan
Stego in images zsteg, steghide extract Firewall egress untuk gambar mencurigakan
LSB stego Statistical analysis Re-encode gambar (strip LSB)
Append data strings + binwalk Validasi hash file
Stego in audio Spectrogram analysis Convert format audio
# Hapus potensi stego dari gambar (re-encode)
convert gambar.jpg -strip gambar-bersih.jpg

# Atau timpa LSB dengan noise (destructive)
python3 -c "
from PIL import Image
import numpy as np
img = Image.open('gambar.jpg')
arr = np.array(img)
arr[:, :, -1] ^= np.random.randint(0, 2, arr[:,:,0].shape) # flip LSB random
Image.fromarray(arr).save('gambar-sanitasi.jpg')
"

Kesimpulan & Refleksi

Apa yang dipelajari:

  • Steganography menyembunyikan data dalam media tanpa mengubah tampilan
  • LSB mengubah bit terakhir pixel - tidak terlihat oleh mata manusia
  • steghide mengenkripsi + menyembunyikan data sekaligus
  • Deteksi stego butuh analisis statistik, bukan visual
  • File yang sama ukurannya belum tentu sama isinya

Refleksi untuk mahasiswa:

"Orang jahat tidak selalu mengirim pesan yang terlihat mencurigakan. Kadang data rahasia ada di foto kucing yang di-post di Facebook. Steganography adalah alasan kenapa DLP (Data Loss Prevention) harus menganalisis konten, bukan hanya header atau ekstensi file."


Referensi


🔬 Lab 8 Selesai! Lanjut ke Lab 9: Windows Registry Forensics


Generated by @farishhz Agent Pentest Pipeline - TDCTF Security Academy

PADA HALAMAN INI