简体   繁体   English

砸栈

[英]Smashing the Stack

So I'm working on an assignment for a security class and the assignment is to use a stack overflow to call the function oopsDidISmashTheStack that is never used it the program. 因此,我正在为安全类分配任务,该任务是使用堆栈溢出来调用函数oopsDidISmashTheStack,而该函数从未在程序中使用过。

#include <stdio.h>
#include <stdlib.h>

int oopsDidISmashTheStack(void)
{
    printf("Yup, smashing the stack is fun!\n");
    exit(0);
}

int getUserInput (void)
{
    char buf[12];
    gets(buf);
    return(1);
}

int main(void)
{
    getUserInput ();
    printf("Overflow failed, normal return\n");
    return(1);
}

I understand the concept of that after the buf variable is the sfp and then the return address what I can't figure out is the input that would change the return value to the address 0x080484fc which is where the function is located. 我理解在buf变量之后是sfp的概念,然后我不知道的返回地址就是将返回值更改为函数所在地址0x080484fc的输入。 I thought that it would require 12 characters to fill the buffer and then I was under the impression that sfp and return where 4 bytes so I trying to fill sfp with another 4 random characters and then use \\xfc\\x84\\x04\\x08 to make the return address point to the function. 我以为需要12个字符来填充缓冲区,然后我觉得sfp并返回4个字节,所以我尝试用另外4个随机字符填充sfp,然后使用\\ xfc \\ x84 \\ x04 \\ x08进行填充返回地址指向该函数。

If anyone is familiar with how the stack memory works and could explain where I'm going wrong that would be great? 如果有人熟悉堆栈存储器的工作原理并且可以解释我要去哪里,那会很棒吗?

You're pretty much on the right track. 您几乎在正确的轨道上。 I suggest you look at the stack and see if the return address is where you think it is. 我建议您查看堆栈,看看寄信人地址是否在您认为的位置。 There might be something else in there. 里面可能还有其他东西。 Also double check the endien-ness, 还要仔细检查字节序,

I assume this is your input string? 我假设这是您的输入字符串?

"012345678901xxxx\\xfc\\x84\\x04\\x08" “ 012345678901xxxx \\ xfc \\ x84 \\ x04 \\ x08”

What is the output of your program, generally if you're close but don't get it quite right the program crashes :) 程序的输出是什么,通常,如果您关闭但不完全正确,则程序崩溃:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM