Lord of SQL injection – cobolt
Level 02
Source Code
<?php include "../config.php"; login_chk(); dbconnect(); if(preg_match('/prob|_|\.|\(\)/i', $_GET[id])) exit("No Hack ~_~"); if(preg_match('/prob|_|\.|\(\)/i', $_GET[pw])) exit("No Hack ~_~"); $query = "select id from prob_cobolt where id='{$_GET[id]}' and pw=md5('{$_GET[pw]}')"; echo "<hr>query : <strong>{$query}</strong><hr><br>"; $result = @mysql_fetch_array(mysql_query($query)); if($result['id'] == 'admin') solve("cobolt"); elseif($result['id']) echo "<h2>Hello {$result['id']}<br>You are not admin :(</h2>"; highlight_file(__FILE__); ?>
Analyse
http://los.sandbox.cash/cobolt-~~.php?id=abc&pw=123
이라고 입력하게 되면
select id from prob_cobolt where id='abc' and pw=md5('123')
와 같이 MySQL 쿼리문이 입력된다.
하지만 gremlin 문제와는 달리 pw가 md5로 해쉬화 되고 있고 10번째 줄을 보면
&result['id']
에 반드시 admin이 들어가야 cobolt 문제가 풀린다.
Frist Hint is next page