Wrote shellcode:
BITS 64
xor rax, rax
push rax
push dword "n/sh"
push dword "//bi"
mov rdi, rsp
push rax
mov rdx, rsp
push rdi
mov rsi, rsp
mov al, 59
syscall
When code execution reaches push instructions, strange things happen. The string /bin/sh
must be sequentially written to the stack, but after the first instruction (and after the second) the values are equalized by 8-byte boundaries, which prevents the formation of a string, and I specified the DWORD
gdb:
=> 0x7fffffffea44: push 0x68732f6e
0x7fffffffea49: push 0x69622f2f
0x7fffffffea4e: mov rdi,rsp
0x7fffffffea51: push rax
0x7fffffffea52: mov rdx,rsp
0x7fffffffea55: push rdi
0x7fffffffea56: mov rsi,rsp
0x7fffffffea59: mov al,0x3b
-----------------------------------------------------------------------------------------------------------------------------
0x00007fffffffea44 in ?? ()
gdb$ ni
Warning:
Cannot insert breakpoint 0.
Cannot access memory at address 0x68732f6e
-----------------------------------------------------------------------------------------------------------------------[regs]
RAX: 0x0000000000000000 RBX: 0x0000000000000000 RBP: 0xFFFFFFFFFFFFFFFF RSP: 0x00007FFFFFFFEA80 o d I t s Z a P c
RDI: 0x00007FFFFFFFEA40 RSI: 0x0000555555556021 RDX: 0x0000000000000079 RCX: 0x40FFFFFFFFFFFFFF RIP: 0x00007FFFFFFFEA49
R8 : 0x0000000000000000 R9 : 0x00007FFFF7FE14C0 R10: 0xFFFFFFFFFFFFF8F5 R11: 0x00007FFFF7E53B60 R12: 0x0000555555555060
R13: 0x0000000000000000 R14: 0x0000000000000000 R15: 0x0000000000000000
CS: 0033 DS: 0000 ES: 0000 FS: 0000 GS: 0000 SS: 002B
-----------------------------------------------------------------------------------------------------------------------[code]
=> 0x7fffffffea49: push 0x69622f2f
0x7fffffffea4e: mov rdi,rsp
0x7fffffffea51: push rax
0x7fffffffea52: mov rdx,rsp
0x7fffffffea55: push rdi
0x7fffffffea56: mov rsi,rsp
0x7fffffffea59: mov al,0x3b
0x7fffffffea5b: syscall
-----------------------------------------------------------------------------------------------------------------------------
0x00007fffffffea49 in ?? ()
gdb$ ni
Warning:
Cannot insert breakpoint 0.
Cannot access memory at address 0x69622f2f
-----------------------------------------------------------------------------------------------------------------------[regs]
RAX: 0x0000000000000000 RBX: 0x0000000000000000 RBP: 0xFFFFFFFFFFFFFFFF RSP: 0x00007FFFFFFFEA78 o d I t s Z a P c
RDI: 0x00007FFFFFFFEA40 RSI: 0x0000555555556021 RDX: 0x0000000000000079 RCX: 0x40FFFFFFFFFFFFFF RIP: 0x00007FFFFFFFEA4E
R8 : 0x0000000000000000 R9 : 0x00007FFFF7FE14C0 R10: 0xFFFFFFFFFFFFF8F5 R11: 0x00007FFFF7E53B60 R12: 0x0000555555555060
R13: 0x0000000000000000 R14: 0x0000000000000000 R15: 0x0000000000000000
CS: 0033 DS: 0000 ES: 0000 FS: 0000 GS: 0000 SS: 002B
-----------------------------------------------------------------------------------------------------------------------[code]
=> 0x7fffffffea4e: mov rdi,rsp
0x7fffffffea51: push rax
0x7fffffffea52: mov rdx,rsp
0x7fffffffea55: push rdi
0x7fffffffea56: mov rsi,rsp
0x7fffffffea59: mov al,0x3b
0x7fffffffea5b: syscall
0x7fffffffea5d: (bad)
-----------------------------------------------------------------------------------------------------------------------------
0x00007fffffffea4e in ?? ()
gdb$ x/s $rsp
0x7fffffffea78: "//bi"
gdb$ x/16xb $rsp
0x7fffffffea78: 0x2f 0x2f 0x62 0x69 0x00 0x00 0x00 0x00
0x7fffffffea80: 0x6e 0x2f 0x73 0x68 0x00 0x00 0x00 0x00
gdb$
how can i solve this problem?