1

I am attempting to write a piece of assembly code which will perform operations on some shell code I have initialized in .data

My initialization is as as follows:

section .data
        shellcode: db "\x31\xc9\xf7\xe1\x51\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\xb0\x0b\xcd\x80", 0

When I attempt to load the array holding the shell code into a register, it is automatically escaped, breaking my program:

enter image description here

enter image description here

I assembled and linked as follows:

nasm -f elf32 -g encryptor_assembly.asm -o encryptor_assembly.o
gcc -m32 -g encryptor_assembly.o -o encryptor_assembly

Is there a way to avoid this from happening? Thanks for your help.

  • You presumably need `-zexecstack` for gcc to link the `.data` section into executable memory. Also, obviously you're just getting a *pointer* to the memory into EAX, and that doesn't change the memory contents. – Peter Cordes Mar 19 '19 at 19:18

1 Answers1

2

Nasm only interpretes C-style escape sequences inside character strings delimited with backticks. To fix your code, replace the double quotes with backticks like this:

shellcode: db `\x31\xc9\xf7\xe1\x51\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\xb0\x0b\xcd\x80`, 0

Refer to the manual for details.

fuz
  • 88,405
  • 25
  • 200
  • 352