【发布时间】:2014-08-04 17:48:37
【问题描述】:
我正在关注一个基本的 shell 生成漏洞利用示例。以下正是我的书告诉我要写的内容,但我仍然遇到段错误。
在 gdb 中运行它时,我在“mov byte [esi + 7], al”处得到一个段错误。这一行是必要的,这样我就可以在字符串“/bin/sh”的末尾放置一个空字节。 当我将它翻转到“mov byte al,[esi + 7]”时,这并没有导致段错误。我假设我对存储字符串的内存位置没有写权限。看来我只有读取权限。
我正在使用运行 32 位 centos 的虚拟机,该虚拟机由 64 位 centos 机器托管。
我已经采取的预防措施:
- 使用 sysctl -w kernel.randomize_va_space=0 在我的虚拟机中禁用 ASLR
- 使用 sysctl -w kernel.exec-shield=0 在我的 vm 中禁用 dep
-
通过 BIOS 设置禁用了我的主机中的 XD 标志
Section .text global _start _start: jmp short GotoCall shellcode: pop esi ; stores address of string in esi xor eax, eax ; fill eax with null bytes mov byte [esi + 7], al ; replace 'J' with null byte - SEGFAULT! lea ebx, [esi] ; stores address of string in ebx mov long [esi + 8], ebx ; stores address of string in AAAA mov long [esi + 12], eax ; stores null bytes in KKKK mov byte al, 0x0b ; stores 11 (execve code) in al mov ebx, esi ; stores address of string in ebx lea ecx, [esi + 8] ; stores pointer to string in ecx lea edx, [esi + 12] ; stores pointer to null in edx int 0x80 ; system call GotoCall: call shellcode ; pushes address of string on stack db '/bin/shJAAAAKKKK' ; creates space for string
我已经确认 ESI 包含指向 gdb 中字符串的正确地址。
/x $esi = 0x8048081
(gdb) x/s 0x8048081
0x8048081 <GotoCall+5>: "/bin/shJAAAAKKKK"
我也尝试用 0x1 而不是 al 写入 [esi] 而不是 [esi + 7]。看来我只是无法写入 db 指令分配的内存。为什么我不能向 [esi + 7] 写入空字节?
【问题讨论】:
-
您是否尝试过在运行时使用
mprotect对.text部分进行写入启用? -
相关:x86_64 Assembly - Segfault when trying to edit a byte within an array in x64 assembly 解释了你应该为非 shellcode 做什么,即
.data或.bss。
标签: linux assembly x86 exploit shellcode