【问题标题】:Bus Error in OS X x86_64 in Execve callExecve 调用中 OS X x86_64 中的总线错误
【发布时间】:2016-05-06 23:52:24
【问题描述】:

我正在尝试在 64 位 Asm 中模仿 Security Tubes execve 教程 (http://hackoftheday.securitytube.net/2013/04/demystifying-execve-shellcode-stack.html)。我不确定总线错误来自哪里。我逐步浏览了 GDB 中的应用程序,但直到我超出框架后才出现错误。如果有人知道发生了什么,我很想听听你的意见。

.section __DATA,__data
.section __TEXT,__text
.globl _start
_start:
    xor %rax, %rax
    push %rax
    movabsq $0x68732f6e69622f2f, %rdi
    push %rax
    mov %rsp, %rsi
    push %rdi
    mov %rsp, %rdx
    mov $0x2000059, %rax
    syscall

【问题讨论】:

  • 一方面,push 在 64 位模式下是 64 位,具有 32 位符号扩展立即数。所以你实际上最终在堆栈上得到了2f 2f 62 69 00 00 00 00 6e 2f 73 68 00 00 00 00。相反,您可以尝试movabsq $0x68732f6e69622f2f, %rax; push %rax
  • 谢谢@Jester。虽然仍然出现总线错误。将更新我的代码以反映您的指示。
  • 您加载了rdi,但推送了rax

标签: macos assembly x86-64 execve


【解决方案1】:

以下应该更好,但我没有要测试的 osx:

.globl _start
_start:
    xor %edx, %edx                    ; NULL for env
    movabsq $0x0068732f6e69622f, %rax ; /bin/sh<0>
    push %rax
    mov %rsp, %rdi                    ; filename
    push %rdx                         ; NULL for argv terminator
    push %rdi                         ; argv[0] = filename
    mov %rsp, %rsi                    ; argv
    mov $0x200003b, %eax              ; I think 59 is decimal
    syscall

【讨论】:

  • 我正在玩弄代码以缩小我做错的部分。我注意到你 push %rdx(第 7 行)。推动的目的是什么?我注意到如果我将其注释掉,总线错误就会回来。
  • @JLegendre :因为sys_execve 要求 argv[] 和/或 envp[] 为空字符指针数组。如果没有 NULL 指针终止,内核不知道数组的末尾在哪里。数组的长度不作为参数传递,因此 NuLL 终止符是一种在处理时识别数组结尾的方法。它本质上类似于为什么一个字符数组以 NUL(0) 字符结尾 - 这样就可以找到字符串的结尾而无需提前告知实际长度
  • @MichaelPetch 很棒的解释!谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-09-21
  • 2014-10-21
  • 1970-01-01
  • 2011-10-02
  • 2015-03-23
  • 2016-10-21
  • 1970-01-01
相关资源
最近更新 更多