While learning ROP and the uses of gadgets, I've stumbled upon a case where I have a solid one-gadget that executes execl("sh", "-c", "/bin/sh")
but does _exit(0x7f)
right afterwards.
When testing this gadget I'v found that the shell indeed opens, and closes after a split second when _exit
is called.
Gadget found in libc.so.6:
LEA EAX,[ESI + 0xfffa8b28]=>DAT_0016bb28 ; "-c"
SUB ESP,0xc
PUSH 0x0
PUSH dword ptr [ESP + param_2]
PUSH EAX=>DAT_0016bb28 ; "-c"
LEA EAX,[ESI + 0xfffa8b30]=>DAT_0016bb30 ; "sh"
PUSH EAX=>DAT_0016bb30 ; "sh"
LEA EAX,[ESI + 0xfffa8b2b]=>DAT_0016bb2b ; "/bin/sh"
PUSH EAX=>DAT_0016bb2b ; "/bin/sh"
CALL execl
ADD ESP,0x14
PUSH 0x7f
CALL _Exit
When used in gdb:
process 239607 is executing new program: /bin/dash
sh: 0: -c requires an argument
[Inferior 1 (process 239607) exited with code 02]
(gdb) r
Starting program: /bin/dash
$
When used in a normal execution without a debugger it just stops.
My question is, is this a doomed gadget, or is there a possible way to still use it?