Goo*_*ies 2 c buffer global-variables buffer-overflow
我正在研究检测和防止BOF攻击,我想知道,我怎样才能溢出全局结构?
我的代码:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
struct{
char name[20];
char description[10];
} test;
int main(int argc, char **argv){
if(argc != 2)
exit(-1);
*(*(argv+1)+20) = '\x00'; //terminate string after 20 characters
strcpy(test.name, argv[1]); //no BOF here... stopped at 20
printf("%s\n", test.name);
char *desc;
desc = malloc(10);
if(!desc){
printf("Error allocating memory\n");
exit(-1);
}
scanf("%s", desc); //no bounds checking - this is where I BOF
strcpy(test.description, desc); //copy over 10 characters into 10 char buffer
printf("%s\n", test.description); //this prints out whatever I type in
//even thousands of characters, despite it having a buffer of 10 chars
}
Run Code Online (Sandbox Code Playgroud)
溢出全局缓冲区的方式与执行任何其他缓冲区类型的方式相同; 在其中存储的数据多于为其分配的字节数.也许问题是"这会造成什么损害?",答案是通常的:它取决于.
基本上,当你溢出一个特定的全局缓冲区时,你会写一些其他全局变量,接下来会发生什么,取决于是否再次引用另一个变量,以及它应该保留什么.它通常不具有函数返回地址等,因此可能更难以利用.