I am very new to assembly and I am trying to call:
/bin/bash -c "echo hello; ls -la"
I store the “/bin/bash” command as a string and its address in RBX and RDI.
59 on RAX for the execve syscall that I perform at the end.
-c on RSI as the second argument with the echo line on the third.
Here’s what gdb sees on the registers before the syscall line.
RBX: 0x4000b3 ("/bin/bash")
RCX: 0x0
RDX: 0x4000c8 (""echo hello; ls -la"")
RSI: 0x4000c5 --> 0x6f6863652200632d ('-c')
RDI: 0x4000b3 ("/bin/bash")
RBP: 0x0
RSP: 0x7fffffffe0e0 --> 0x1
RIP: 0x4000a7 --> 0xe8050f0000003bb8
But when I start the executable nothing happens. I thought the registers are used for the argv[]
arguments.
I debugged the program and I honestly can’t tell what’s going wrong but then again I am really new so maybe I am not actually giving the arguments to the syscall?
5
Try splitting the command string into seperate arguments and storing their addresses in memory. Also make sure that the last argument in both the “argv[]” and “envp[]” arrays is a NULL pointer to terminate the array.
2