[PortSwigger Web Security Academy] Lab: Web shell upload via Content-Type restriction bypass write up

zzsla·2023년 8월 20일
0

문제 정보

This lab contains a vulnerable image upload function. It attempts to prevent users from uploading unexpected file types, but relies on checking user-controllable input to verify this.
To solve the lab, upload a basic PHP web shell and use it to exfiltrate the contents of the file /home/carlos/secret. Submit this secret using the button provided in the lab banner.
You can log in to your own account using the following credentials: wiener:peter

문제

lab에 들어가면 가상 blog 사이트가 나온다.

분석

이미지 업로드 기능이 취약하다
파일을 업로드 할 때 user-controllable 입력을 검사한다.
wiener:peter으로 로그인 가능하다.
목표
php webshell을 업로드해서 /home/carlos/secret을 보고 lab 배너에 값을 넣는다.

주어진 계정에 로그인 한 뒤에 My account에 들어가면 avatar 이미지 업로드하는 곳이 있다. 거기에 webshell을 올리기 위해 간단한 webshell을 제작한다.
<?php echo file_get_contents('/home/carlos/secret'); ?>

그리고 나서 webshell를 넣고 업로드를 하면 error가 발생한다. error 내용은 image/jpegimage/png만 허용된다고 나온다.

burpsuite에 proxy http history를 살펴보면 error에 application/x-php가 나온 것을 생각했을 때 Content-Type으로 MIME유형과 일치하는지 확인하는 것으로 보인다.

즉 webshell을 보낼 때 Content-Type을 image/jpegimage/png으로 변경해서 보내면 될 거 같다.
그래서 burpsuite proxy intercept를 켜고 다시 webshell를 보낸 뒤 Content-Type을 변경한다.

inpercept를 풀고 웹사이트에서 My account로 간 뒤에 history에 가서 webshell이 잘 들어갔는지 확인한다.
확인해 보면 webshell이 잘 작동하여 값이 나온 것을 확인할 수 있다.
zVivwOnC9Bix7FKb7ZfEPznnCn8B7N4E

해당 값을 lab 배너 submit solution에 적고 ok를 누르면 문제가 풀린다.

profile
[README]newbi security hacker :p

0개의 댓글