x64 helloworld shellcode 不打印任何东西
x64 helloworld shellcode not printing anything
我正在 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
我assemble代码和运行它:
$nasm -f elf64 -o print2.o print2.asm
$ld -o print2 print2.o
$./print2
虽然 print2 似乎正常退出但什么也没有发生...有人可以解释为什么吗?
抱歉,如果这个问题已经被问过。我试图寻找类似的但找不到任何东西。
作为第一步,请查看 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'
我正在 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
我assemble代码和运行它:
$nasm -f elf64 -o print2.o print2.asm
$ld -o print2 print2.o
$./print2
虽然 print2 似乎正常退出但什么也没有发生...有人可以解释为什么吗?
抱歉,如果这个问题已经被问过。我试图寻找类似的但找不到任何东西。
作为第一步,请查看 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'