0

I am trying to write a shell insertion decoder (my encoder works as expected). But when I try to move one byte to the address inside a register i face a Segmentation fault.

The error happens in this line:

mov    BYTE PTR [rdi],bl

Here is my assembly code:

global _start

section .text

_start:
    jmp call_decoder
    rri_shellcode: db 0x48,0x48,0x5b,0x48,0x90,0x5b

init_decoder:
    lea rsi, [rel rri_shellcode]
    mov rdi, rsi
    inc rdi
    xor rax, rax
    add rax, 1
    xor rbx, rbx

loop_decoder:
    mov bl, byte [rsi + rax + 1]
    mov byte [rdi], bl
    inc rdi
    inc rax
    loop loop_decoder

call_decoder:
    call init_decoder

What happens that i cant move the byte within bl into the address stored within rdi?

PS.: I know the loop wont work since I didn't set rcx yet.

Thanks in advance,

:wq!

alacerda
  • 125
  • 6

1 Answers1

4

rdi points to rri_shellcode+1. This is located in the .text segment which is not writable by default, thus causing the segmentation fault.

You can link it using the ld -N option if you really need .text section to become read/write.

alacerda
  • 125
  • 6
rhodeo
  • 524
  • 1
  • 6
  • 14