The rest of the idek pwn kinda hurted my brain (orz vy and nightxade) so I thought this chall might be good practice anyway to touch up on some of the basics. This is the pseudocode from ghidra which i pieced together. Its like the pseudo C ghidra has and I added some comments.
|
|
interesting things to note:
- the character count check is absolutely useless for options 2 and 3. The logic gate
((iVar2 < 0) || (7 < iVar2))
does technically work as control flow so this is very confusing
I look at the disassembly of the edit_friend
function, i see:
|
|
in the assembly of the control flow here
|
|
there is a jump for the index in range jle 0x401547
for jumping if the index is less than or equal to 7 but there is actually no jump or ret made if the index is greater… meaning it still performs the stuff inside the else but with an index greater than 7. so i can write to a higher index. What this means though is that positionallly, 8x8 matrix is 64 bytes so after that, any index i choose will increase that offset by 8 bytes. Because write()
has an fd to stdout, it prints the element at that position thus making a “display” feature. If i know the canary’s alignment in the stack now i can continue with the exploit. I honestly just spammed random numbers in hopes of finding a suffix which ended with 00
since thats usually the standard convention for canaries but i guess like if you look at the disassembly for main:
|
|
i know that the canary is likely loaded in 0x00000000004016bc <+312>: mov rdx,QWORD PTR [rbp-0x8]
because right after this instruction there is a 0x00000000004016c0 <+316>: sub rdx,QWORD PTR fs:0x28
instruction and stack check fail call which happens after a comparing of values. It makes sure that the value is the same through subtracting the expected value and all. fgets()
entry is at [rbp-0x30]
meaning alignment wise its above the matrix. The beginning is 0x70
so the distance betwween them both is 40 but this indexing is relative to the beginning of the matrix. So its 40+64
which is 104
or basically “index 13”.
simple canary capture
basically tldr canary is a value in the stack which when overwritten makes the program just crash out. Its a security protection which is supposed to stop buffer overflow attacks this way. Alas, like many protections it gets absolutely screwed over if leaks exist.
|
|
|
|
the 00
suffix is there so yea canary. Now i can bof in peace
now ->
- i overflow and i bypass canary
- theres conventiently a get_flag function. i ret to there.
- i exit cuz i need the ret to pop the top of the stack and jmp (top of the stack is addr of get flag)
so then i can finish the final script where the last order of business was just to do a simple bof with canary alignment, and then exit to leverage ret.
|
|
yay
|
|
fladg