v13 = __readfsqword(0x28u); setbuf(_bss_start, 0LL); setbuf(stdin, 0LL); rgid = getegid(); setresgid(rgid, rgid, rgid); puts("Welcome to slack (not to be confused with the popular chat service Slack)!"); timer = time(0LL); tp = localtime(&timer); v3 = time(0LL); srand(v3); for ( i = 0; i <= 2; ++i ) { strftime(s, 0x1AuLL, "%Y-%m-%d %H:%M:%S", tp); v4 = rand(); printf("%s -- slack Bot: %s\n", s, (&messages)[v4 % 8]); printf("Your message (to increase character limit, pay $99 to upgrade to Professional): "); fgets(format, 14, stdin); tp = localtime(&timer); strftime(s, 0x1AuLL, "%Y-%m-%d %H:%M:%S", tp); printf("%s -- You: ", s); printf(format); // fsb putchar(10); } return v13 - __readfsqword(0x28u); }
I just found the 3rd fsb only in this CTF. haha.
Anyway, only the buffer is 14 bytes. Actually 1 byte is for NULL. (Because fgets() receives string.)
Be careful when inputting with the fgets() becuase it receives an enter(‘\n’). It means if you send 13 bytes, you’ll have to send without ‘\n’. And if you send under 13 bytes, you’ll have to send including ‘\n’.
Solve
1 2 3 4 5
Arch: amd64-64-little RELRO: Full RELRO Stack: Canary found NX: NX enabled PIE: PIE enabled
We can’t do overwriting because of FULL RELRO.
I need to get red’s offest(25) and yellow’s offset(55).
First, I access the red’s offset, and then write a ptr_idx + 3 address. Because ptr_idx is small, so I have limit to trigger fsb vulnerability. So, I have to unlock this limit. I access yellow’s offset, and write a 0x80. Because I want to make ptr_idx as a negative.
So, I can trigger fsb vulnerability infinitely!! This rule also applies when rop_payload write to the stack.