尝试缓冲区溢出时,意外值出现在堆栈上

问题描述 投票:0回答:1

我试图了解有关网络安全的更多信息,在这种情况下,有关缓冲区溢出。我有一个想要更改其流程的简单代码:

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

void win()
{
  printf("code flow successfully changed\n");
}

int main(int argc, char **argv)
{
  volatile int (*fp)();
  char buffer[64];

  fp = 0;

  gets(buffer);

  if(fp) {
      printf("calling function pointer, jumping to 0x%08x\n", fp);
      fp();
  }
}

通过使用某些工具,我确定在72个字符进入缓冲区后,函数指针(fp)会将其值更新。函数win()位于值0xe5894855上,因此在72个字符之后,我需要将该值提供给缓冲区,以使其跳转到所需的函数。

但是我面临这个问题:enter image description here

通过将Python3的print("A"*18*4 + "UH" + "\x89" + "\xe5")放入给定C代码的输入中,我应该在标有红色的部分中获得所需的值0xe5894855。但是,相反,我从某个地方开始突出显示格式错误的十六进制。 (89正在获得多余的C2,并且错误的e5值正在溢出到堆栈的下一部分)(堆栈的那些部分中的值最初为零,但是一旦尝试溢出,则更改为该值)。

为什么会这样?我是否将十六进制值错误地放入C程序?

gcc stack-overflow
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.