x64 helloworld shellcode没有打印任何东西

时间:2017-10-12 07:03:57

标签: assembly 64-bit shellcode

我在exploit.courses linux容器上学习x64 shellcode我运行一个我编写的hello world 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似乎正常退出但没有任何反应......有人可以解释原因吗?

很抱歉,如果已经提出这个问题。我试着找一个类似的,但找不到任何东西。

1 个答案:

答案 0 :(得分:1)

首先看一下write documentation

   ssize_t write(int fd, const void *buf, size_t count);

第二个参数必须是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' 
相关问题