在缓冲区溢出的情况下利用 C 中的 strcpy(),

Exploiting strcpy() in C with Buffer overflow,

我是计算机安全领域的新手,我遇到了这个 table

char *
isdn_net_newslave(char *parm)
{
    char *p = strchr(parm, ',');
    isdn_net_dev *n;
    char newname[10];
    if (p) {
        /* Slave-Name MUST not be empty */
        if (!strlen(p + 1))
            return NULL;
        strcpy(newname, p + 1);
        *p = 0;
        /* Master must already exist */
        if (!(n = isdn_net_findif(parm)))
            return NULL;
        /* Master must be a real interface, not a slave */
        if (n->local->master)
            return NULL;
        /* Master must not be started yet */
        if (isdn_net_device_started(n))
            return NULL;
        return (isdn_net_new(newname, n->dev));
    }
    return NULL;
}

我想通过利用 strcpy()strchr() 获得根 shell。

虽然它里面有 strcpy()strchr(),但我在用 C 来利用它时遇到了一些麻烦,因为这是我第一次利用缓冲区溢出。


我的问题:

我不太了解ASLR。它如何干扰 C 脚本的缓冲区溢出?我不想禁用它,我正在寻找实际的利用。

如何操作变量newname

以及如何精确定位这段代码?实际上这段代码从原始代码的第 2639 行开始。


请帮帮我!谢谢!

原码:

https://kernel.googlesource.com/pub/scm/linux/kernel/git/ralf/linux/+/linux-3.18.19/drivers/isdn/i4l/isdn_net.c

任何溢出(缓冲区、堆栈、堆...)都需要 shell 代码 才能导致利用。

ASLR 和 DEP 通过随机偏移 cf https://security.stackexchange.com/questions/18556/how-do-aslr-and-dep-work

随机化特定模块(如堆栈、堆、libc)在内存中的位置

在 linux 上您可以看到 ASLR 如何与 cat /proc/self/maps ( With ASLR turned on, are all sections of an image get loaded at the same offsets relative to the image base address every time? )

一起工作

如果不这样做并且模块在内存中处于静态位置(就像过去那样),那么将有一个静态地址,其中包含特定功能,这些地址可以用作入口点对于 shell 代码执行,因为任何溢出攻击的目标都是将 shell 代码放在内存中,并通过指向内存中特定位置的指针执行此 shell 代码

我不会在这里告诉你更多关于灰色技术的信息,但也许可以看看 return-oriented programming什么是仍然有效的溢出技术的变体

( Exploiting a string-based overflow on x86-64 with NX (DEP) and ASLR enabled )