小编dda*_*aar的帖子

Setuid二进制文件通过覆盖%n来生成根外壳,不适用于漏洞利用,但在不需要漏洞利用时起作用

我有一个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)

c linux bash setuid ctf

4
推荐指数
1
解决办法
189
查看次数

标签 统计

bash ×1

c ×1

ctf ×1

linux ×1

setuid ×1