Pwn Echo
Ret2Win but you hunt where to return in memory. (+UEFI)
Handout
We are given a folder with source files, dockerfile, UEFI PE images and their debug files. This gives us debug symbols and other goodies. Nice.
Bug Feature
It’s a UEFI shellcode loader that happily loads and executes your ‘\r’ terminated shellcode.
Since communication is over serial, it returns the printable repr of input byte over serial.
It also emits “backspace” on encountering “\x08” and “\x7f”.
Only if it were so easy
The qemu serial console is wrapped with socat with sigint,sane,pty. This means
if shellcode contains tty escape sequences like C-c (\x03) and C-z (\x1a), they’ll
be intepreted by socat instead and cause side effects.
I also found some other bytes that didn’t “echo” back, meaning they were unconditionally dropped.
Approach
Simple ret-2-win, but we hunt in memory the address of win function.
-
Load flag module once. This triggers uefi policy error, but it’s fine - we just need the moule in memory somewhere before and somwdy close to our VulnApp efi module
-
Load VulnApp application.
-
Inject Shellcode that does two things:
- Copy
gBS(Boot service, 2nd arg) andgImageHandle(first argument to UefiMain) - Hunt for
Flag.efiin memory. Constraints:x/wx $modbase=MZandx/gx $modbase+0x21e4=0x75422f326b64652f(Start of a string)
- Call
_ModuleEntryPointofFlag.efi - Get flag.
- Copy
Solve script
PY
|
|
Conclusion
For challenges like this, it’d be much better, if the payload is first receieved by some external http server, and then loaded into the app locally instead of over the wire.