我对C中的代码注入的想法有点困惑.如果有人能够解释它并展示它是如何完成的,我会很感激它.
因此,假设在C中你有一些大小为512的Char数组,它被写入长度为1024的套接字的内容,而char数组现在拥有某种代码,但只有写入的一半.
如何在缓冲区中执行恶意代码溢出,我想我对进程结构(堆栈,堆,数据,文本)感到困惑.
Dou*_* T. 10
一般技巧与程序的代码和变量如何在内存中布局有关.例如,当调用函数时,程序(编译器插入的代码)必须存储要返回的指令的地址.因此,如果这是在堆栈开始之前的32位字,则可以执行以下操作:
void foo()
{
int array[5];
int var = 0;
int var2 = 0;
// read in user input
printf("Enter index and value to write:");
scanf("%i", var);
scanf("%i", var2);
// malicious user might set var to -1 and var2 to an address to execute
// if say the 32-bit value before the stack variables is the instruction to
// return to
array[var] = var2
// return now goes to malicious code
}
Run Code Online (Sandbox Code Playgroud)
(所以你的工作就是构造代码,这样就不可能了.:))
实现函数调用的方式,分配的堆栈变量,传递的值以及返回的返回值的规则称为调用约定.我建议阅读附件,以便深入了解C调用约定.