免考final linux提权与渗透入门——Exploit-Exercise Nebula学习与实践 (8)

18-1

根据输出内容,我们知道登录成功了。应该可以执行shell命令。

我们追加一个shell,然后再执行flag18程序。

18-2

看到这个结果,是因为文件描述符用尽了。

我们看源码中的这一部分

} else if(strncmp(line, "closelog", 8) == 0) { if(globals.debugfile) fclose(globals.debugfile); globals.debugfile = NULL; }

也就是说添加closelog可以释放一个文件描述符。我们再次修改/tmp/login

18-3

然后执行

cat login | /home/flag18/flag18 --init-file -d debug

但是出现了下面的问题。

18-4

我们可以这么操作

18-5

既然找不到Starting命令,我们就攻击环境变量,将Starting指向恶意脚本

再次运行程序,查看/tmp/output文件,我们可以知道/bin/getflag已经被执行了

18-6

level19——突破进程

终于来到最后一关了,这一关要求我们攻破下面的程序。

程序的源代码如下:

#include <stdlib.h> #include <unistd.h> #include <string.h> #include <sys/types.h> #include <stdio.h> #include <fcntl.h> #include <sys/stat.h> int main(int argc, char **argv, char **envp) { pid_t pid; char buf[256]; struct stat statbuf; /* Get the parent\'s /proc entry, so we can verify its user id */ snprintf(buf, sizeof(buf)-1, "/proc/%d", getppid()); /* stat() it */ if(stat(buf, &statbuf) == -1) { printf("Unable to check parent process\n"); exit(EXIT_FAILURE); } /* check the owner id */ if(statbuf.st_uid == 0) { /* If root started us, it is ok to start the shell */ execve("/bin/sh", argv, envp); err(1, "Unable to execve"); } printf("You are unauthorized to run this program\n"); }

这段程序的逻辑是这样的:

先通过getppid()函数得到父进程pid号

根据pid号找到/proc下当前pid号的目录

如果属于root,就执行shell

我们需要利用“孤儿进程”的特点来突破这段程序

孤儿进程的父进程init的uid绝对是0

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zwpfgy.html