我有一个Setuid二进制文件,该文件具有一个printf格式字符串漏洞,应该与“%n”一起利用它来覆盖authenticated
全局变量的值。使用/ bin / bash时authenticated = 1
,使用root Setuid权限可以执行/ bin / bash ,但authenticated = 0
使用exploit时则不能。
我已经尝试过ls
并且可以正常工作,所以exec正在发生。我也尝试过authenticated = 1
在源代码中进行制作,因此它可以自动运行bash而不会被利用。这适用于生成根外壳。使用漏洞利用程序时,程序将按预期方式调用授予访问权限的功能,但在exec处结束,并且永远不会达到错误。但是,父进程死了,这意味着bash的执行程序一定已经发生。Bash必须正在执行,但是它在启动时崩溃/退出。
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <errno.h>
int authenticated = 0;
void read_flag() {
if (!authenticated) {
printf("Sorry, you are not *authenticated*!\n");
}
else {
printf("Access Granted.\n");
int cpid = fork();
if(cpid == 0){
printf("child!\n");
execlp("/bin/bash", "bash", NULL);
perror("error");
}
else{
wait(NULL);
} …
Run Code Online (Sandbox Code Playgroud)