A. CSRF Attack
- Untuk mencoba serangan, anda bisa mendownload project web yang sudah tersedia untuk penetrasi, download di sini -> https://github.com/raesene/bWAPP
- Kemudian download aplikasi sender penetrasi tambahan Burp Suite di sini -> https://portswigger.net/burp/communitydownload
- Setelah anda download, install pada localhost anda. Jika bingung, bisa lihat tutorial berikut -> https://www.youtube.com/watch?v=F3QcgmCuEC0
- Jika sudah terinstall, masuk ke halaman Login
http://localhost/bwapp/login.php
![](https://i0.wp.com/www.rumahcoding.co.id/wp-content/uploads/2019/04/image-74-1024x671.png?resize=750%2C491&ssl=1)
5. Kemudian login dengan Login : bee, Password : bug
![](https://i0.wp.com/www.rumahcoding.co.id/wp-content/uploads/2019/04/image-75-1024x699.png?resize=750%2C512&ssl=1)
6. Untuk serangan CSRF terbagi menjadi beberapa serangan, kita coba satu – persatu. Sekarang kita coba CSRF (Change Password) kemudian pilih Hack
![](https://i0.wp.com/www.rumahcoding.co.id/wp-content/uploads/2019/05/image.png?resize=561%2C402&ssl=1)
7. Setelah masuk ke halaman yang di tuju, klik kanan -> View page source ( Google Chrome )
![](https://i0.wp.com/www.rumahcoding.co.id/wp-content/uploads/2019/05/image-1-1024x576.png?resize=750%2C422&ssl=1)
8. Kemdian block baris code seeperti gambar di bawah, copy + paste di editor anda.
![](https://i0.wp.com/www.rumahcoding.co.id/wp-content/uploads/2019/05/image-2.png?resize=642%2C456&ssl=1)
9. Buatlah sebuah file csrf.html simpan di lokasi yang anda inginkan. Paste code di atas.
![](https://i0.wp.com/www.rumahcoding.co.id/wp-content/uploads/2019/05/image-3.png?resize=750%2C532&ssl=1)
10. Sekarang copy + paste url pada halaman ganti password
![](https://i0.wp.com/www.rumahcoding.co.id/wp-content/uploads/2019/05/image-4-1024x576.png?resize=750%2C422&ssl=1)
![](https://i0.wp.com/www.rumahcoding.co.id/wp-content/uploads/2019/05/image-5.png?resize=750%2C531&ssl=1)
11. Sekarang kita akan mengganti password menggunakan file crsf.html yang dibuat, ubah code seperti gambar berikut
![](https://i0.wp.com/www.rumahcoding.co.id/wp-content/uploads/2019/05/image-6.png?resize=750%2C496&ssl=1)
12. untuk melakukan perubahan password, buka file csrf.html pada browser anda, klik Change
![](https://i0.wp.com/www.rumahcoding.co.id/wp-content/uploads/2019/05/image-8.png?resize=591%2C253&ssl=1)
![](https://i0.wp.com/www.rumahcoding.co.id/wp-content/uploads/2019/05/image-9.png?resize=750%2C630&ssl=1)
13. Kemudian coba anda login dengan password baru yang dibuat lewat file csrf.html
![](https://i0.wp.com/www.rumahcoding.co.id/wp-content/uploads/2019/05/image-10.png?resize=680%2C678&ssl=1)
B. Solution
- Untuk mengatasi serangan CSRF (Change Password) , pada bagian form input, tambahkan current password field seperti gambar di bawah
![](https://i0.wp.com/www.rumahcoding.co.id/wp-content/uploads/2019/05/image-12.png?resize=750%2C378&ssl=1)
2. Pada saat handling request get password_curr , tambahkan code berikut ( Sesuaikan nama tabel dan kolom )
if(isset($_REQUEST["password_curr"])) { $password_curr = $_REQUEST["password_curr"]; $password_curr = mysqli_real_escape_string($link, $password_curr); $password_curr = hash("sha1", $password_curr, false); $sql = "SELECT password FROM users WHERE login = '" . $login . "' AND password = '" . $password_curr . "'"; // Debugging // echo $sql; $recordset = $link->query($sql); if(!$recordset) { die("Connect Error: " . $link->error); } // Debugging // echo "<br />Affected rows: "; // printf($link->affected_rows); $row = $recordset->fetch_object(); if($row) { // Debugging // echo "<br />Row: "; // print_r($row); $sql = "UPDATE users SET password = '" . $password_new . "' WHERE login = '" . $login . "'"; // Debugging // echo $sql; $recordset = $link->query($sql); if(!$recordset) { die("Connect Error: " . $link->error); } // Debugging // echo "<br />Affected rows: "; // printf($link->affected_rows); $message = "<font color=\"green\">The password has been changed!</font>"; } else { $message = "<font color=\"red\">The current password is not valid!</font>"; } }
0 Comments