0

我一直在这方面遇到分段错误,有人可以帮我解决这个问题吗,我对 ASM 有点陌生

global _start

section .text
_start:

push   dword 0x0068732F ; Push /sh
push   dword 0x6E69622F ; Push /bin
mov    eax, esp         ; Store Pointer To /bin/sh In EAX

push   dword 0x0000632D ; Push -c
mov    ebx, esp         ; Store Pointer To -c In EBX

push   dword 0x00000068 ; Push h
push   dword 0x7361622F ; Push /bas
push   dword 0x6E69622F ; Push /bin
mov    ecx, esp         ; Store Pointer To /bin/bash In ECX

push   dword 0x0        ; NULL 
push   ecx              ; Push /bin/bash Pointer
push   ebx              ; Push -c Pointer
push   eax              ; Push /bin/sh Pointer

mov    ebx, eax         ; Move /bin/sh Pointer To EAX
mov    ecx, esp         ; Store /bin/sh -c /bin/bash Pointer in ECX
xor    edx, edx         ; Store 0 In EDX

mov    al, 0xb          ; sys_execve
int    0x80             ; system call

我正在尝试复制以下内容

char* Args[] = { "/bin/sh", "-c", "/bin/bash" };
    execve("/bin/sh", Args, NULL)

提前致谢

4

1 回答 1

2

正如评论中所指出的,参数需要以 NULL 结尾。

mov al, 0xb只设置(32 位)eax寄存器的低 8 位。早些时候,您还将堆栈中的地址加载到 eaxmov eax, esp中,并且由于堆栈不断增长,因此存储在其中的值eax将更0xFFFFFFFF接近于0. 当你稍后mov al, 0xb你只替换最后一个F并且eax需要完全正确 0xb

因此,您需要将值移动到整个eax寄存器或确保其高 24 位预先归零 - 例如通过执行xor eax, eax.

global _start

section .text
_start:

push   dword 0x0068732F ; Push /sh
push   dword 0x6E69622F ; Push /bin
mov    eax, esp         ; Store Pointer To /bin/sh In EAX

push   dword 0x0000632D ; Push -c
mov    ebx, esp         ; Store Pointer To -c In EBX

push   dword 0x00000068 ; Push h
push   dword 0x7361622F ; Push /bas
push   dword 0x6E69622F ; Push /bin
mov    ecx, esp         ; Store Pointer To /bin/bash In ECX

push   0                ; <----- NULL args terminator
push   ecx              ; Push /bin/bash Pointer
push   ebx              ; Push -c Pointer
push   eax              ; Push /bin/sh Pointer

mov    ebx, eax         ; Move /bin/sh Pointer To EAX
mov    ecx, esp         ; Store /bin/sh -c /bin/bash Pointer in ECX
xor    edx, edx         ; Store 0 In EDX
;xor    eax, eax        ; <----- either xor eax, eax or mov into eax
mov    eax, 11          ; sys_execve
int    0x80             ; system call
于 2016-11-03T18:23:21.737 回答