Re: [問題] shellcode會core dump
※ 引述《mecs (mecs)》之銘言:
: ※ 引述《imprazaguy (Wayne)》之銘言:
: 恕刪
: : 不過將 foo2 改成你的 shellcode 結果就 code dump 了
: : 如果你的shellcode沒錯的話,我猜測的原因是:
: : http://en.wikipedia.org/wiki/Executable_space_protection
: : 原PO你覺得呢?
: : --
: : ◆ From: 140.112.30.141
: : → cobrasgo:我剛剛也查到了,用readelf可以看到STACK的flag是RW 12/30 17:49
: : → cobrasgo:感謝回應 12/30 17:51
: 你需要 E (executable) flag. RW 是不夠的.
: 1. echo 0 > /proc/sys/kernel/exec-shield (for Redhat/Fedora)
: or
: 2. 編譯時加上 -Wl,-z,execstack
: 另外就是,printf 是一定會被執行的。因為你是覆寫
: 到 test() 的 return address,而不是 printf。
: 如果你要測試 test() 會不會回到 main(),應該是把
: printf() 放在 main() 裡面(在 test()之後)。
不好意思,現在又有一個奇怪的問題
==============================
#include <string.h>
#include <stdio.h>
/*
原來的shellcode只有下面這裡
\x31\xdb\x89\xd8\x40\xcd\x80
我把buffer的起始位置append到shellcode的後面
再加上一個nop來對齊,下面這行是結果
*/
char shellcode[] = "\x90\x31\xdb\x89\xd8\x40\xcd\x80\x14\xe8\xff\xbf";
void vul(){
char buffer[4];
strcpy(buffer, shellcode);
}
int main(int argc, char *argv[]){
vul();
printf("you cannot see me\n");
return 0;
}
================================
其中shellcode的末4個byte是在我的環境,shellcode的起始address
================================
(gdb) b vul
Breakpoint 1 at 0x804822e: file vulFunc.c, line 9.
(gdb) x/16aw buffer
No symbol "buffer" in current context.
(gdb) run
Starting program: /fuck/test/c/demo/vulFunc
Breakpoint 1, vul () at vulFunc.c:9
9 strcpy(buffer, shellcode);
(gdb) x/16aw buffer
0xbfffe814: 0x1 0xbfffe828 0x8048259 <main+22> 0x3
0xbfffe824: 0xbfffe840 0xbfffea58 0x80484a8 <__libc_start_main+552> 0x20615
0xbfffe834: 0x3 0xbfffea58 0x80484a8 <__libc_start_main+552> 0x1
0xbfffe844: 0xbfffea84 0xbfffea8c 0x0 0x0
=================================
上面的0xbfffe814就是我抓到的位置,這個值環境不同也要改成不同的值
compile時就多下一個-z execstack就可以執行shellcode
現在碰到的狀況是
我用gdb跑這個程式
會正常結束
但是直接run
就會core dump
請問一下是哪裡出了問題?
謝謝
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.130.51.128
→
01/04 10:40, , 1F
01/04 10:40, 1F
→
01/04 10:41, , 2F
01/04 10:41, 2F
→
01/04 10:41, , 3F
01/04 10:41, 3F
→
01/04 12:03, , 4F
01/04 12:03, 4F
→
01/04 12:04, , 5F
01/04 12:04, 5F
→
01/04 12:04, , 6F
01/04 12:04, 6F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 4 之 4 篇):
LinuxDev 近期熱門文章
PTT數位生活區 即時熱門文章