Wednesday, September 22, 2010

Auditing & hardening Local file Inclusion (LFI)

Setelah beberapa jam coding, akhirnya selesai juga. Yach, mungkin cara ini juga digunakan oleh WebEr lainnya, tapi mungkin saja beda penulisan code tapi memiliki tujuan yang sama.

Local File Inclusion terjadi karena penggunaan metode GET yang digunakan ntuk menginclude atau memanggil halaman web pada halaman index/utama.

Lebih jelasnya ini adalah contoh source code yang vulnerability LFI:

echo("Home | ");
echo("Contact Us | ");
echo("Services");

if(empty($_GET[page])){
$page = "home.php";
}else{
$page = $_GET[page].".php";
}
include("$page");

Untuk menutup celah ini, modifikasi codenya menjadi:

echo("Home | ");
echo("Contact Us | ");
echo("Services");
$hal = array(
0 => "home",
1 => "contact",
2 => "services"
);
for($x=0;$x<=2;$x++){
if(empty($_GET[page])){
$page = "home.php";
include("$page");
exit;
}elseif ($_GET[page] == $hal[$x]){
$page = $_GET[page].".php";
include("$page");
exit;
}
}

Semoga bermanfaat!^_^)

0 Komentar: