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?
View all comments
Show parent comment
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.