根据输出内容,我们知道登录成功了。应该可以执行shell命令。
我们追加一个shell,然后再执行flag18程序。
看到这个结果,是因为文件描述符用尽了。
我们看源码中的这一部分
} else if(strncmp(line, "closelog", 8) == 0) { if(globals.debugfile) fclose(globals.debugfile); globals.debugfile = NULL; }也就是说添加closelog可以释放一个文件描述符。我们再次修改/tmp/login
然后执行
cat login | /home/flag18/flag18 --init-file -d debug但是出现了下面的问题。
我们可以这么操作
既然找不到Starting命令,我们就攻击环境变量,将Starting指向恶意脚本
再次运行程序,查看/tmp/output文件,我们可以知道/bin/getflag已经被执行了
终于来到最后一关了,这一关要求我们攻破下面的程序。
程序的源代码如下:
#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