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

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

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

    mov bl, byte [rsi + rax + 1]
    mov byte [rdi], bl
    inc rdi
    inc rax
    loop loop_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,



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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.