the cat
S.14

MicroCorruption: Jakarta

You finally *Gitgit* to Jakarta..

4 Nov 2020 · write-up · buffer underflow

There's a manual:

The main function just calls login.

login function is quite long:

r15 = 0x2402
for *r15 != 0{
    r15++
}

r11 = r15
r11 -= 0x2402 ; this gives the length of the username input.

cmp.b(0x21, r11) ; this compares if the input is less than 0x21(33) characters.
        ; checks the carry flag. jnc implies the input length less than 0x21.

An interesting discovery on calculating the length of input passed to getsn on the password input.

If the username input is maximum length, a buffer underflow occurs! :D

Time to get down and dirty!

You run a test input with the maximum username input and follow the progression:

This will cause an underflow as you observed earlier;

Sweet! You can now have long password input. However, there is still a barrier that you need to bypass: the cmp.b #0x21, r15. The total length of username + password is checked to ensure it is not more than 0x21.

Looking at cmp.b instruction from the user guide: this operation compares the last byte of the source operand from the destination operand.

You just need to ensure that the last byte of r15(the total length of user + pass) is less than 0x21. The minimum value for this would be 0x100(256) chars. Since the username length is already 0x20, the password length needs to be 0x100 - 0x20 = 0xe0(224) characters.

Authentication fails as expected(this was a test run). You notice though, that the return address is now overwritten by the copied content.

Can almost see the victory now...

You need to modify the 5th and 6th byte of the password input to the call to unlock_door address at 0x461c. You try a 32 char username input and this password input:

You cracked it! :D

Santa Cruz is your oyster now.