Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.6k views
in Technique[技术] by (71.8m points)

assembly - execve shellcode linux segmentation fault

Im trying to run this shellcode but it throws me: "Segmentation fault" error The shellcode is the following:

shellcode.asm:

global _start
_start:

jmp short ca
doit:
pop ebx
xor eax, eax
cdq
mov byte [ebx+7], al
mov long [ebx+8], ebx
mov long [ebx+12], eax
lea ecx, [ebx+8]
mov byte al, 0x0b

int 0x80
ca:
call doit
db '/bin/sh'

i compile it with : 'nasm -f elf shellcode.asm' and link it with: ' ld -m elf_i386 -s -o shellcode shellcode.o

I think the error is when I use mov [ebx+x], al/eax/ebx because when I erase it from the code y get no error

Thank you

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Your problem is that the .text section is not writable by default. The easiest thing to do is put your code into a new custom section that is marked as writable. Add this line at the top of your asm file:

section .shellcode  progbits alloc exec write align=16

You could also pass the -N switch to the linker.

Alternatively, you could rewrite the shellcode so that it uses the stack to create the arguments.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...