Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 程序集运行任何代码之前发生的分段错误_Linux_Assembly_Shellcode - Fatal编程技术网

Linux 程序集运行任何代码之前发生的分段错误

Linux 程序集运行任何代码之前发生的分段错误,linux,assembly,shellcode,Linux,Assembly,Shellcode,我正在尝试编写一个shell代码程序,它将调用execve并生成一个shell。我在一个32位虚拟机中工作,该虚拟机是为我提供的。代码如下: section .text global _start _start: ;clear out registers xor eax, eax xor ebx, ebx xor ecx, ecx xor edx, edx ;exacve("/bin/sh",Null,NULL) ;ascii for /bin/sh; ;2f 62 9 6e 2f 73 6

我正在尝试编写一个shell代码程序,它将调用execve并生成一个shell。我在一个32位虚拟机中工作,该虚拟机是为我提供的。代码如下:

section .text

global _start

_start:
;clear out registers
xor eax, eax
xor ebx, ebx
xor ecx, ecx
xor edx, edx
;exacve("/bin/sh",Null,NULL)
;ascii for /bin/sh;
;2f 62 9 6e 2f 73 68 3b
push 0x3b68732f
push 0x6e69622f
mov ebx, esp
mov al, 11
int 0x80
;exit(int status)
movv al, 1
xor ebx, ebx
int 0x80
我使用
nasm-f elf-gshell.asm编译,并使用
ld-oshell.o
当我试着运行它时,我得到了一个分段错误。我尝试使用gdb来查看我在哪里犯了错误,但是,即使a将断点设置为_start+0,它也会出错。它说在代码的最后一条指令之后的地址有一个SEGFULT。 i、 e.如果最后一行的地址为0x804807c,则在任何代码有机会运行之前,分段故障发生在0x804807e


有谁能给我指出正确的方向,让我知道如何解决这个问题吗?

您代码中的一个错误是,字符串的ascii代码中没有
0x3b

;exacve("/bin/sh",Null,NULL)
;ascii for /bin/sh;
;2f 62 9 6e 2f 73 68 3b
push 0x3b68732f
push 0x6e69622f
以下代码将解决此问题(假设您使用的是小型endian机器):


请注意,调试器可能无法正确设置断点。那是真的。。。因此,它可能正在执行,调试器检测到问题,但无法完全找出问题所在。谢谢。出于某种原因,我认为最后一个是分号。@a1j9o94即使它是分号,您仍然需要一些东西来指示字符串的结尾,对吗?:)否则节目肯定不知道。通常情况下,一个字符串应该以空字符(
0x00
)结尾。我最终发现这就是为什么我会出现seg错误。我必须先在堆栈上推一个空寄存器。
;exacve("/bin/sh",Null,NULL)
;ascii for /bin/sh;
;2f 62 99 6e 2f 73 68 00
push 0x0068732f
push 0x6e69622f