From e4c252ef4e987685552ff0bd47895f3b0d27003b Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Tue, 15 Mar 2011 17:09:43 -0600 Subject: [PATCH] Rewrite octopus to not use tokend --- packages/mcp/tokend.keys/logger | 1 - packages/mcp/tokend.keys/octopus | 2 - packages/mcp/tokend.keys/printf | 1 - packages/mcp/tokend.keys/pwnables | 1 - packages/mcp/tokend.keys/rlyeh | 1 - packages/mcp/tokend.keys/tanks | 1 - packages/octopus/solution.sh | 2 +- packages/octopus/src/Makefile | 2 +- packages/octopus/src/octopus.c | 48 ++++++++++---------- packages/octopus/src/token.c | 1 - packages/octopus/src/token.h | 1 - packages/octopus/tokens/octopus/category | 1 - packages/octopus/tokens/octopus/category.key | 2 - packages/octopus/tokens/octopus/enc.key | 3 -- 14 files changed, 25 insertions(+), 42 deletions(-) delete mode 100644 packages/mcp/tokend.keys/logger delete mode 100644 packages/mcp/tokend.keys/octopus delete mode 100644 packages/mcp/tokend.keys/printf delete mode 100644 packages/mcp/tokend.keys/pwnables delete mode 100644 packages/mcp/tokend.keys/rlyeh delete mode 100644 packages/mcp/tokend.keys/tanks delete mode 120000 packages/octopus/src/token.c delete mode 120000 packages/octopus/src/token.h delete mode 100644 packages/octopus/tokens/octopus/category delete mode 100644 packages/octopus/tokens/octopus/category.key delete mode 100644 packages/octopus/tokens/octopus/enc.key diff --git a/packages/mcp/tokend.keys/logger b/packages/mcp/tokend.keys/logger deleted file mode 100644 index f11bbd8..0000000 --- a/packages/mcp/tokend.keys/logger +++ /dev/null @@ -1 +0,0 @@ -S*繼7kp \ No newline at end of file diff --git a/packages/mcp/tokend.keys/octopus b/packages/mcp/tokend.keys/octopus deleted file mode 100644 index 8a5f356..0000000 --- a/packages/mcp/tokend.keys/octopus +++ /dev/null @@ -1,2 +0,0 @@ - -'6Y= \ No newline at end of file diff --git a/packages/mcp/tokend.keys/printf b/packages/mcp/tokend.keys/printf deleted file mode 100644 index 6089383..0000000 --- a/packages/mcp/tokend.keys/printf +++ /dev/null @@ -1 +0,0 @@ -I[^,5O \ No newline at end of file diff --git a/packages/mcp/tokend.keys/pwnables b/packages/mcp/tokend.keys/pwnables deleted file mode 100644 index b9f44b7..0000000 --- a/packages/mcp/tokend.keys/pwnables +++ /dev/null @@ -1 +0,0 @@ -t322/0gji \ No newline at end of file diff --git a/packages/mcp/tokend.keys/rlyeh b/packages/mcp/tokend.keys/rlyeh deleted file mode 100644 index 8d72a26..0000000 --- a/packages/mcp/tokend.keys/rlyeh +++ /dev/null @@ -1 +0,0 @@ -qVA.SF֨,.} \ No newline at end of file diff --git a/packages/mcp/tokend.keys/tanks b/packages/mcp/tokend.keys/tanks deleted file mode 100644 index 15df993..0000000 --- a/packages/mcp/tokend.keys/tanks +++ /dev/null @@ -1 +0,0 @@ -U'0mqp \ No newline at end of file diff --git a/packages/octopus/solution.sh b/packages/octopus/solution.sh index a8424e1..753e33a 100755 --- a/packages/octopus/solution.sh +++ b/packages/octopus/solution.sh @@ -1,7 +1,7 @@ #! /bin/sh port=8888 -host=10.0.0.8 +host=${1:-10.0.0.8} blooper=$(tempfile) trap "rm $blooper" 0 diff --git a/packages/octopus/src/Makefile b/packages/octopus/src/Makefile index 67085c3..f449d68 100644 --- a/packages/octopus/src/Makefile +++ b/packages/octopus/src/Makefile @@ -3,7 +3,7 @@ build: octopus -octopus: octopus.o token.o +octopus: octopus.o clean: rm -f octopus *.o diff --git a/packages/octopus/src/octopus.c b/packages/octopus/src/octopus.c index 6db8c6d..5c0744f 100644 --- a/packages/octopus/src/octopus.c +++ b/packages/octopus/src/octopus.c @@ -11,7 +11,6 @@ #include #include #include -#include "token.h" #define OUTPUT_MAX 1024 #define INPUT_MAX 1024 @@ -20,6 +19,9 @@ #define max(a,b) (((a)>(b))?(a):(b)) #endif +char token[80]; +size_t tokenlen; + uint8_t const key[] = {0x99, 0x5f, 0xcb, 0xde, 0xf9, 0x6d, 0x02, 0xf3, 0x47, 0x60, 0x0a, 0xe0, @@ -47,7 +49,7 @@ char const octopus[] = ); const char *friends[8] = { - ("Welcome to Olive Octopus's house! Olive lives at 00021270.\n" + ("Welcome to Olive Octopus's house!\n" "Help Olive visit all 8 of her friends to receive a prize!\n" "Hurry though, things change quickly in the ocean!\n" "Next friend: %08o\n" @@ -208,17 +210,8 @@ int rebind(struct in_addr *addr) { static int offset = 0; - char token[200]; - size_t tokenlen; int i; - tokenlen = read_token("octopus", - key, sizeof(key), - token, sizeof(token)); - if (-1 == tokenlen) { - return -1; - } - for (i = 1; i < 8; i += 1) { int ret; int last_guy; @@ -317,8 +310,6 @@ loop() FD_SET(bound_ports[i].fd, &rfds); } - /* Wait forever. There's no need to switch ports if nobody's doing - anything. */ while (-1 == select(nfds+1, &rfds, NULL, NULL, &timeout)) { if (EINTR == errno) { continue; @@ -340,11 +331,12 @@ main(int argc, char *argv[]) { int ret; int i; - time_t last = time(NULL); + time_t last_bind = 0; + time_t last_token = 0; struct in_addr addr; /* The random seed isn't super important here. */ - srand(last); + srand(time(NULL)); if (argc > 1) { if (-1 == inet_aton(argv[1], &addr)) { @@ -365,20 +357,26 @@ main(int argc, char *argv[]) for (i = 1; i < PORTS; i += 1) { bound_ports[i].fd = -1; } - if (-1 == rebind(&addr)) { - perror("initial binding"); - return EX_IOERR; - } - while (loop()) { + do { time_t now = time(NULL); - if (last + 4 < now) { - last = now; + if (last_token + 60 < now) { + last_token = now; + while (NULL == fgets(token, sizeof(token), stdin)) { + if (-1 == fseek(stdin, 0, SEEK_SET)) { + /* Non-seekable stdin: we're done. */ + return 0; + } + } + for (tokenlen = 0; token[tokenlen] && (token[tokenlen] != '\n'); tokenlen += 1); + } + + if (last_bind + 4 < now) { + last_bind = now; if (-1 == rebind(&addr)) break; } - } + } while (loop()); - perror("main loop"); - return EX_IOERR; + return 0; } diff --git a/packages/octopus/src/token.c b/packages/octopus/src/token.c deleted file mode 120000 index f0a9dcd..0000000 --- a/packages/octopus/src/token.c +++ /dev/null @@ -1 +0,0 @@ -../../../include/token.c \ No newline at end of file diff --git a/packages/octopus/src/token.h b/packages/octopus/src/token.h deleted file mode 120000 index 21e62e4..0000000 --- a/packages/octopus/src/token.h +++ /dev/null @@ -1 +0,0 @@ -../../../include/token.h \ No newline at end of file diff --git a/packages/octopus/tokens/octopus/category b/packages/octopus/tokens/octopus/category deleted file mode 100644 index 1ed143c..0000000 --- a/packages/octopus/tokens/octopus/category +++ /dev/null @@ -1 +0,0 @@ -octopus diff --git a/packages/octopus/tokens/octopus/category.key b/packages/octopus/tokens/octopus/category.key deleted file mode 100644 index 8a5f356..0000000 --- a/packages/octopus/tokens/octopus/category.key +++ /dev/null @@ -1,2 +0,0 @@ - -'6Y= \ No newline at end of file diff --git a/packages/octopus/tokens/octopus/enc.key b/packages/octopus/tokens/octopus/enc.key deleted file mode 100644 index 2e889c0..0000000 --- a/packages/octopus/tokens/octopus/enc.key +++ /dev/null @@ -1,3 +0,0 @@ -_mG` - -%M \ No newline at end of file