I am new to asm and I am trying to execute a syscall to /bin/bash. However I am currently encountering the following problem:
My code works for any execve call whose 1st argument length is less than 8 bytes, i.e "/bin/sh" or "/bin/ls" :
.section .data
name: .string "/bin/sh"
.section .text
.globl _start
_start:
#third argument of execve, set to NULL
xor %rdx, %rdx
#push nullbyte to the stack
pushq %rdx
#push /bin/sh to the stack
pushq name
#copy stack to rdi, 1st arg of execve
mov %rsp, %rdi
#copy 59 to rax, defining syscall number for execve
movq $59, %rax
#3rd arg of execve set to NULL
movq $0, %rsi
syscall
What puzzles me is that I cannot get it to work with
name: .string "/bin/bash"
I tried to split the string in parts, to pushq "/bash" then "/bin" to the stack, nothing seems to allows me to have it working and I get an "Illegal instruction" error every time. What am I doing wrong?
Non working code:
.section .data
name: .string "/bin/bash"
.section .text
.globl _start
_start:
#third argument of execve, set to NULL
xor %rdx, %rdx
#push nullbyte to the stack
pushq %rdx
#push /bin/sh to the stack
pushq name
#copy stack to rdi, 1st arg of execve
mov %rsp, %rdi
#copy 59 to rax, defining syscall number for execve
movq $59, %rax
#3rd arg of execve set to NULL
movq $0, %rsi
syscall
Other non working code :
.section .data
.section .text
.globl _start
_start:
#third argument of execve, set to NULL
xor %rdx, %rdx
#push nullbyte to the stack
pushq %rdx
#push /bin/bash to the stack
pushq $0x68
pushq $0x7361622f
pushq $0x6e69622f
#copy stack to rdi, 1st arg of execve
mov %rsp, %rdi
#copy 59 to rax, defining syscall number for execve
movq $59, %rax
#3rd arg of execve set to NULL
movq $0, %rsi
syscall