I'm currently trying to reproduce a multi-stage shellcode, as described in the slides. I'm executing a simple read and piping more shellcode into it. When I run the ELF directly, it performs as expected and executes the second stage.
However, when I try to run it against babyshell_level8 (which is supposed to sort the bytes), I get a really bizarre result. Basically, if I set rdi to 0, it overwrites my rsi with "" (empty string), no matter what else I do around it. I've tried multiple ways of setting rdi to 0 (shift left/right, xor, mov 1 then shift or do math), but every time that register becomes 0, rsi becomes "".
I assume this has something to do with the sorting. However, when the teaching exercise prints the code it's about to execute, it looks right. It doesn't look like the sorting mangled it at all. It shows lea rsi, mov rdi, mov rax, mov rdx, syscall, as expected and in the right order.
I'm not sure what I'm missing here. Either the teaching binary isn't showing the actual bytes after they were sorted, or somehow rdi is affecting rsi.