无论缓冲区大小,都无法访问$ eip-gdb

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

我具有以下C文件vuln.c,并且我正在尝试进行缓冲区溢出攻击。我的目标是将$eip设置为函数read_secret的地址。

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

void read_secret() {
    FILE *fptr = fopen("/task2/secret.txt", "r");
    char secret[1024];
    fscanf(fptr, "%512s", secret);
    printf("Well done!\nThere you go, a wee reward: %s\n", secret);
    exit(0);
}

int fib(int n)
{
   if ( n == 0 )
      return 0;
   else if ( n == 1 )
      return 1;
   else
      return ( fib(n-1) + fib(n-2) );
} 

void vuln(char *name)
{
    int n = 20;
    char buf[1024];
    int f[n];
    int i;
    for (i=0; i<n; i++) {
      f[i] = fib(i);
    }
    strcpy(buf, name);
    printf("Welcome %s!\n", buf);
    for (i=0; i<20; i++) {
      printf("By the way, the %dth Fibonacci number might be %d\n", i, f[i]);
    } 
}


int main(int argc, char *argv[])
{
    if (argc < 2) {
        printf("Provide your name\n");
        return 0;
    }

    vuln(argv[1]);
    return 0;
}

[到目前为止,使用gdb,将输入的大小推到1026时,我会遇到分段错误。就是run $(python -c "print('A'*1026)")

但是,无论我增加多少1026,$eip始终为0x8049323。对于任何类似的问题,我都花了很长时间在网上辛苦寻找,但没有找到任何问题。

我知道有类似的问题,但代码相似,但是答案并没有解决我的问题。

编辑:仅供参考,是的,x41确实可以使用,它们只是一直没有达到$ eip。

enter image description here

另外,这些是输入输入内容前后的信息注册表。

之前enter image description here

之后enter image description here

并且buf变量的地址前后为0xffffd230。并且read_secret()的地址为0x80491c2。

c security gdb buffer-overflow
1个回答
1
投票

问题是程序内部出现了一个点,程序试图打印f [i]。这些被缓冲区覆盖为非法地址(即0x41414141)。

相反,我从'info reg'($ ebp)中选择了一个对我有用的地址,并多次插入该地址,直到我碰到$ eip。本质上,您想在此处选择一个法律地址。

© www.soinside.com 2019 - 2024. All rights reserved.