execve x86 - 分段错误

时间:2016-11-03 17:51:13

标签: c assembly x86 shellcode execve

我不断得到分段错误,任何人都可以帮我解决这个问题,我是ASM的新手

Answers

我正在尝试复制以下内容

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

提前致谢

1 个答案:

答案 0 :(得分:2)

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

同样mov al, 0xb仅设置(32位)eax寄存器的低8位。 之前您还将堆栈中的地址加载到eax mov eax, esp中,并且由于堆栈增长,eax中存储的值将更接近0xFFFFFFFF 0 }}。如果您稍后mov al, 0xb,则只需将上一个Feax替换为完全 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
相关问题