Cyber Security: target SQL Injection ke id serderhana
Revision as of 13:58, 22 April 2025 by Onnowpurbo (talk | contribs) (Created page with "Berikut ini adalah contoh file PHP sederhana yang bisa digunakan untuk '''testing SQLMap'''. File ini menerima parameter `id` melalui URL (misalnya: `http://localhost/test.php...")
Berikut ini adalah contoh file PHP sederhana yang bisa digunakan untuk testing SQLMap. File ini menerima parameter `id` melalui URL (misalnya: `http://localhost/test.php?id=1`) dan menjalankan query langsung ke database tanpa proteksi — rentan terhadap SQL Injection — sehingga SQLMap bisa mendeteksinya dan melakukan pengujian.
PERINGATAN: Script ini tidak boleh dijalankan di server publik karena sangat rentan. Gunakan hanya di lingkungan lokal atau virtual machine untuk pembelajaran atau pengujian.
test.php
<?php // Koneksi ke database $host = 'localhost'; $user = 'root'; $pass = '123456'; $dbname = 'testdb'; $conn = new mysqli($host, $user, $pass, $dbname); // Cek koneksi if ($conn->connect_error) { die("Koneksi gagal: " . $conn->connect_error); } // Ambil parameter dari URL $id = $_GET['id'] ?? '1'; // Query rentan SQL Injection $sql = "SELECT * FROM users WHERE id = $id"; $result = $conn->query($sql); // Tampilkan hasil if ($result->num_rows > 0) { while ($row = $result->fetch_assoc()) { echo "ID: " . $row["id"] . "<br>"; echo "Username: " . $row["username"] . "<br>"; echo "Email: " . $row["email"] . "<br>"; } } else { echo "0 hasil."; } $conn->close(); ?>
Struktur Database Sederhana (`testdb`)
Akses mysql
mysql -u root -p123456
Gunakan ini di MySQL untuk setup cepat:
CREATE DATABASE testdb; USE testdb; CREATE TABLE users ( id INT PRIMARY KEY AUTO_INCREMENT, username VARCHAR(50), email VARCHAR(100) ); INSERT INTO users (username, email) VALUES ('admin', 'admin@example.com'), ('user1', 'user1@example.com'), ('user2', 'user2@example.com');
Contoh Penggunaan SQLMap
Setelah file `test.php` jalan di localhost:
sqlmap -u "http://localhost/test.php?id=1" --batch --dbs
Kalau mau, aku bisa bantu buatin script SQL-nya, file `.sql`, atau setup-nya di XAMPP atau Docker juga. Mau lanjut ke mana?