首页 > 解决方案 > 使用立即数时汇编代码中的分段错误

问题描述

所以我一直在学习一些基本的汇编代码,以制作 shellcode 为导向,这一切都很好而且很花哨,但是我正在阅读的这本书有点过时了。到目前为止,汇编代码部分工作顺利,但是我遇到了一些打开新外壳的代码的问题。

BITS 32

  jmp short two     ; Jump down to the bottom for the call trick
one:
; int execve(const char *filename, char *const argv [], char *const 
envp[])
  pop ebx           ; ebx has the addr of the string
  xor eax, eax      ; put 0 into eax
  mov [ebx+7], al   ; null terminate the /bin/sh string
  mov [ebx+8], ebx  ; put addr from ebx where the AAAA is
  mov [ebx+12], eax ; put 32-bit null terminator where the BBBB is
  lea ecx, [ebx+8]  ; load the address of [ebx+8] into ecx for argv ptr
  lea edx, [ebx+12] ; edx = ebx + 12, which is the envp ptr
  mov al, 11        ; syscall #11
  int 0x80          ; do it

two:
  call one          ; Use a call to get string address
  db '/bin/sh'     ; the XAAAABBBB bytes aren't needed

在运行了几次测试程序之后,我设法找出了我认为的问题所在。它第一次在程序中使用立即数[ebx+7](理论上其他两个mov命令也是如此)会导致分段错误。我只是不明白为什么。我正在尝试执行的系统调用(如果注释在上下文中不是那么好)是execve,它采用文件名、指向参数数组的指针和envp变量。这段代码正在尝试做的事情是否可能,如果没有,我怎样才能达到同样的效果?

如果您想知道,这本书是“黑客:剥削的艺术,第 2 版”,它是 2008 年制作的,就像我说的那样,过时了。

标签: assemblyx86

解决方案


推荐阅读