Hola, estaba haciendo una shellcode de prueba. Simplemente debe de imprimir el carácter 'w'.
He usado el gdb para comprobar todas la instrucciones y el programa acaba correctamente pero no se por que no imprime el carácter.
#include <stdio.h>
#include <sys/mman.h>
#include <string.h>
#include <stdlib.h>
  
int (*sc)();
/****************************************************************
	0000000000000000 <main>:                                         /
	   0:	48 31 c9             	xor    %rcx,%rcx                  /
	   3:	48 31 c0             	xor    %rax,%rax                  /
	   6:	eb 11                	jmp    19 <n>                     /
	                                                                  /
	0000000000000008 <et>:                                            / 
	   8:	59                   	pop    %rcx                       /
	   9:	b0 04                	mov    $0x4,%al                   / 
	   b:	b3 01                	mov    $0x1,%bl                   /
	   d:	b2 01                	mov    $0x1,%dl                   /
	   f:	cd 80                	int    $0x80                      /
	  11:	48 31 c0             	xor    %rax,%rax                  /
	  14:	48 ff c0             	inc    %rax                       /
	  17:	cd 80                	int    $0x80                      / 
	                                                                  /
	0000000000000019 <n>:                                             /
	  19:	e8 ea ff ff ff       	callq  8 <et>                     /
	                                                                  /
	000000000000001e <abc>:                                           /
	...                                                           /
******************************************************************/
char shellcode[] = "\x48\x31\xc9\x48\x31\xc0\xeb\x11\x59\xb0\x04\xb3\x01\xb2\x01\xcd\x80\x48\x31\xc0\x48\xff\xc0\xcd\x80\xe8\xea\xff\xff\xffw";
  
int main(int argc, char **argv) {
  
    char *ptr = mmap(0, sizeof(shellcode),
            PROT_EXEC | PROT_WRITE | PROT_READ, MAP_ANON
            | MAP_PRIVATE, -1, 0);
  
    if (ptr == MAP_FAILED) {
        perror("mmap");
        exit(-1);
    }
  
    memcpy(ptr, shellcode, sizeof(shellcode));
    sc = ptr;
  
    (void)((void(*)())ptr)();
  
    return 0;
}
EI: juntando mensajes.
He corregido algunos posibles errores. Pero sigue sin funcionar.
Tengo que decir que que el código ensamblador(en nasm) funciona pero la shellcode insertada en c no funciona.
Lo que he hecho es añadir los xor por si quedaba basura en los registros y cambiar la llamada a exit() por un ret para que después de la función continúe.
#include <stdio.h>
#include <sys/mman.h>
#include <string.h>
#include <stdlib.h>
  
int (*sc)();
/****************************************************************
	0000000000000000 <main>:                                      /
	   0:	48 31 c9             	xor    %rcx,%rcx              /
	   3:	48 31 c0             	xor    %rax,%rax              /
	   6:	eb 13                	jmp    1b <n>                 /
                                                                  /
	0000000000000008 <et>:                                        /
	   8:	59                   	pop    %rcx                   /
	   9:	48 31 c0             	xor    %rax,%rax              /
	   c:	48 31 db             	xor    %rbx,%rbx              /
	   f:	48 31 d2             	xor    %rdx,%rdx              /
	  12:	b0 04                	mov    $0x4,%al               /
	  14:	b3 01                	mov    $0x1,%bl               /
	  16:	b2 01                	mov    $0x1,%dl               /
	  18:	cd 80                	int    $0x80                  / 
	  1a:	c3                   	retq                          /
	                                                              /
	000000000000001b <n>:                                         /
	  1b:	e8 e8 ff ff ff       	callq  8 <et>                 /
	                                                              /
	0000000000000020 <abc>:                                       /
	  20:	77                   	.byte 0x77                    /
		...                                                       /
******************************************************************/
char shellcode[] = "\x48\x31\xc9\x48\x31\xc0\xeb\x13\x59\x48\x31\xc0\x48\x31\xdb\x48\x31\xd2\xb0\x04\xb3\x01\xb2\x01\xcd\x80\xc3\xe8\xe8\xff\xff\xffw";
//char shellcode[] = "\x48\x31\xc9\x48\x31\xc0\xeb\x11\x59\xb0\x04\xb3\x01\xb2\x01\xcd\x80\x48\x31\xc0\x48\xff\xc0\xcd\x80\xe8\xea\xff\xff\xffw";
  
int main(int argc, char **argv) {
  
    char *ptr = mmap(0, sizeof(shellcode),
            PROT_EXEC | PROT_WRITE | PROT_READ, MAP_ANON
            | MAP_PRIVATE, -1, 0);
  
    if (ptr == MAP_FAILED) {
        perror("mmap");
        exit(-1);
    }
  
    memcpy(ptr, shellcode, sizeof(shellcode));
    sc = ptr;
  
    (void)((void(*)())ptr)();
    printf("\n");
  
    return 0;
}
El código de nasm es el siguiente:
;EXAMPLE VARIABLES IN LINUX
global main
main:                           ; main
xor rcx, rcx            ; eficient way turning register to 0
xor rax, rax            ; exclusive or
           
jmp n            
et:	
pop rcx
xor rax, rax
xor rbx, rbx
xor rdx, rdx
mov al, 4                      ; Number of system call (write)
mov bl, 1                      ; argument(1=stdout)
mov dl, 1                      ; number of characters
int 0x80
ret
n:
call et
abc:	db 'w'            ; declaring one variable(size 8 bytes)
EI: juntando mensajes.
Bueno, resulta que también pregunté en stackoverflow y al final me contesto a mi mismo.
Podeis ver la respuesta en este hilo: http://stackoverflow.com/questions/13323379/shell-code-print-character64bits
			
			
			
				Bueno, resulta que también pregunté en stackoverflow y al final me contesto a mi mismo.
Podeis ver la respuesta en este hilo: http://stackoverflow.com/questions/13323379/shell-code-print-character64bits