x64 shellcode 在…上 exploit.courses linux容器和我在运行我编写的hello world x64外壳代码时遇到了问题。 我试图将“Hi there”缓冲区直接移动到寄存器,因此我不使用 .data 部分
x64 shellcode
.data
section .data ;msg db "Hi there" section .text global _start _start: ;zeroed out these registers xor rax, rax xor rbx, rbx xor rsi, rsi xor rdi, rdi xor rdx, rdx ;write (int fd, char *msg, unsigned int len); mov rax,1 ; syscall 1 is write in 64bit arch mov rdi,1 ; rdi is fd mov rbx, 0x6572656874206948 mov rdx, 9; rdx is size (9 for null byte) syscall ; instead of int 0x80 for 32 bit architecture ;exit (int ret) mov rax, 60 ; syscall 60 is exit in 64bit arch mov rdi, 0 ; rdi is error code syscall
我组装代码并运行它:
$nasm -f elf64 -o print2.o print2.asm $ld -o print2 print2.o $./print2
虽然print2似乎正常退出,但什么也没有发生。。。有人能解释一下为什么吗?
对不起,如果已经问过这个问题。我试着找一个类似的,但什么也找不到。
作为第一步,请查看 write documentation
write
ssize_t write(int fd, const void *buf, size_t count);
第二个参数必须是 const void *
const void *
但对于linux,调用约定是:
RDI, RSI, RDX, RCX, R8, R9, XMM0â7
那么您的实现是不正确的。
你应该这样做
global _start _start: jmp short msg routine: ... pop rsi ;address of the string from the stack ... msg: call routine db 'Hi here'