r/ExploitDev • u/Serious-Individual-4 • Nov 22 '23
Having trouble debugging IoT firmware (mipsel)
I'm reproducing a relative old vulnerabilities, a bof in DIR-815.
This device is a router, exposing a httpd service to network and use cgi (where bug exists) to process request. I've writen a working exp in qemu-mipsel (user mode).
However in qemu system mode, I'm trying to simulate real environment, running httpd and use cgibin to parse request. The httpd use fork+execve to invoke cgibin
But I encounterd some problems:
- I use static compiled gdbserver inside qemu
gdbserver [hostip]:8888 --attach $(pgrep httpd)
In host
gdb-multiarch /path/to/cgibin
(gdb) target remote [qemuip]:8888
inside gdb the memory info is all about httpd, not cgibin. I can't set breakpoints in cgibin with symbol name or address.
- I try to follow child execution
set follow-fork-mode child
set detach-on-fork false
catch exec
when I continue, I get error (which indicates I can't catch exec)
warning: Error inserting catchpoint 3: Your system does not support this type of catchpoint.
And I have no idea how to correctly debug my exploit like in real world, having no information about cgibin's execution :(
Any advice?
0
Nov 22 '23
[deleted]
2
u/asyty Nov 22 '23 edited Nov 22 '23
Setting the fork mode was my original reply until I noticed he was already doing that. It seems like patching the binary with 08000000 and then attaching and replacing the instruction with the original is the way to go.
1
u/Serious-Individual-4 Nov 23 '23
Thanks for advice, however patching doesn't work for me either :(
I patched related function's begginning and end but none of them would freeze the execution. Can't inspect the child process with `ps`
2
u/asyty Nov 23 '23
Just to be clear, 0x004094c8 is the address you patched to 08 00 00 00? Is that what disassembled to "jr zero"? That is Jump Register.
08000000 (big endian) should be jump zero bytes ahead. I figured it was the equivalent of "eb fe" on x86.
The encoding for traps and jumps is: ccccccii iiiiiiiiii iiiiiiii iiiiiiii (where c is the bits for the opcode, and i is the immediate operand).
There's a lot of conflicting information around though, the reference I was looking at said the operand for j is relative, but others are saying it's an absolute address. Maybe try this instead:
0x004094c8 >> 2 == 0x102532,
so j 0x004094c8 should encode to 08102532.
1
u/Serious-Individual-4 Nov 24 '23
Oh I got you. Sorry for the misunderstand. I'll try this technique
1
u/Serious-Individual-4 Nov 28 '23
Hi, I'm here to reply that "j" op does use absolute addressing and I successfully patched & debug it to make my exploit work! Thanks again!
1
u/Character_Drama5214 Dec 05 '23
can u please share how u patched the cgibin,
i have the same issue where i can only attach to lighttpd while the vuln was in cstecgi.cgi,which was the child process of lighttpd
and my question is that where i can get into the infinite loop,the main function in cgi or the vuln function in cgi
thx