#include #include #include #include #include void cat(const char* filename) { // Jednoduchá funkce na vypsání vlajky. (Tady není zranitelnost) int fd = open(filename, O_RDONLY); char buf[1024]; int buflen; while((buflen = read(fd, buf, 1024)) > 0) { write(1, buf, buflen); } } void print_flag1() { cat("secrets/flag1"); } void print_flag2() { cat("secrets/flag2"); } char skutecne_heslo[40]; int main() { // Příprava programu, vypínání bufferování stdoutu a stdinu, načítání tajného hesla. (Tady není zranitelnost) setbuf(stdout, NULL); setbuf(stdin, NULL); int fd = open("secrets/heslo", O_RDONLY); read(fd, skutecne_heslo, 40); bool ok = false; char heslo[40]; printf("Zadejte heslo: "); gets(heslo); if (strcmp(heslo, skutecne_heslo) == 0) ok = true; if (ok) print_flag1(); else printf("\nŠpatné heslo.\n"); }