webhacking.kr 61번-SQL INJECTION(column alias)
<?
echo("<a href=index_lolll.phps>source</a>");
if(!$_GET[id]) $_GET[id]="guest";
echo("<html><head><title>Challenge 61</title></head><body>");
if(eregi("\(|\)|union|select|challenge|from|,|by|\.",$_GET[id])) exit("Access Denied");
if(strlen($_GET[id])>18) exit("Access Denied");
$q=@mysql_fetch_array(mysql_query("select $_GET[id] from c_61 order by id desc limit 1"));
echo("<b>$q[id]</b><br>");
if($q[id]=="admin") @clear();
echo("</body></html>");
?>
id가 없다면, id는 'guest'가 된다!
id에 \(, \), union, select, challenge, from, , ,by, \. 은 필터링된다! Access Denined
id의 길이가 18자보다 크면 Access Denied
select id from c_61 order by id desc limit 1
내림차순으로 정렬, limit 1(출력의 갯수를 1개로 제한)
q[id]을 출력!
q[id]가 admin이어야 clear!
select 'admin' as id
를 하면 id 컬럼 안에 admin이 들어간다.
근데 '이 안먹으므로 admin을 16진수로 우회하여 넣어준다!