From b563456fda0e04cb70ebb271314a515fb9ca826b Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Mon, 25 Oct 2010 17:17:10 -0600 Subject: [PATCH] Start to add in tanks --- .gitignore | 3 ++ Makefile | 16 ++++++++++ packages/logger/logger.mk | 2 +- packages/mcp/mcp.mk | 2 +- packages/mcp/service/tokend/run | 8 +++++ packages/mcp/src/Makefile | 3 +- packages/mcp/src/common.c | 53 +++++++++++++++++++++++++++++++ packages/mcp/src/common.h | 5 +++ packages/mcp/src/in.tokend.c | 56 --------------------------------- packages/mcp/src/mktoken.c | 28 +++++++++++++++++ packages/octopus/octopus.mk | 2 +- packages/packages.mk | 14 ++++----- packages/printf/printf.mk | 2 +- packages/pwnables/pwnables.mk | 2 +- packages/tanks/tanks.mk | 21 +++++++++++++ packages/tokens/tokens.mk | 2 +- 16 files changed, 149 insertions(+), 70 deletions(-) create mode 100644 packages/mcp/src/mktoken.c create mode 100644 packages/tanks/tanks.mk diff --git a/.gitignore b/.gitignore index 2583a78..6296f20 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,6 @@ *.o bin/ build/ +cache/ +target/ + diff --git a/Makefile b/Makefile index 7817eea..bef9f96 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,22 @@ +# Scratch directory for building extrenal sources BUILD = build + +# Root to install things before they're packaged +TARGET = target + +# Downloaded source files go here +CACHE = cache + +# The end result BIN = bin + all: packages +clean: packages-clean + rm -rf $(BUILD) $(TARGET) $(BIN) + +scrub: clean + rm -rf $(CACHE) + include packages/packages.mk diff --git a/packages/logger/logger.mk b/packages/logger/logger.mk index a3d5ac4..14f251c 100644 --- a/packages/logger/logger.mk +++ b/packages/logger/logger.mk @@ -1,4 +1,4 @@ -LOGGER_PKGDIR = $(BUILD)/logger +LOGGER_PKGDIR = $(TARGET)/logger logger-install: logger-build mkdir -p $(LOGGER_PKGDIR) diff --git a/packages/mcp/mcp.mk b/packages/mcp/mcp.mk index 5920a8c..96c2115 100644 --- a/packages/mcp/mcp.mk +++ b/packages/mcp/mcp.mk @@ -1,4 +1,4 @@ -MCP_PKGDIR = $(BUILD)/mcp +MCP_PKGDIR = $(TARGET)/mcp mcp-install: mcp-build mkdir -p $(MCP_PKGDIR) diff --git a/packages/mcp/service/tokend/run b/packages/mcp/service/tokend/run index fabef63..ba75674 100755 --- a/packages/mcp/service/tokend/run +++ b/packages/mcp/service/tokend/run @@ -2,6 +2,14 @@ exec 2>&1 +DB=/var/lib/ctf/tokens.db + +if [ ! -f $DB ]; do + # Append any package-provided tokens + cat /opt/*/tokens >$DB 2>/dev/null + chown ctf $DB +fi + for fn in /var/lib/ctf/tokens.db /var/lib/ctf/claim.db; do touch $fn chown ctf $fn diff --git a/packages/mcp/src/Makefile b/packages/mcp/src/Makefile index 43cd59b..abf9e7d 100644 --- a/packages/mcp/src/Makefile +++ b/packages/mcp/src/Makefile @@ -1,7 +1,7 @@ CFLAGS = -Wall -Werror TARGETS = in.tokend tokencli claim.cgi TARGETS += puzzler.cgi puzzles.cgi -TARGETS += pointscli +TARGETS += pointscli mktoken all: build @@ -10,6 +10,7 @@ build: $(TARGETS) in.tokend: in.tokend.o arc4.o common.o tokencli: tokencli.o arc4.o pointscli: pointscli.o common.o +mktoken: mktoken.o common.o puzzles.cgi: puzzles.cgi.o common.o claim.cgi: claim.cgi.o common.o diff --git a/packages/mcp/src/common.c b/packages/mcp/src/common.c index 15d1a67..38d9187 100644 --- a/packages/mcp/src/common.c +++ b/packages/mcp/src/common.c @@ -524,3 +524,56 @@ award_and_log_uniquely(char const *team, } close(fd); } + + +/** Compute bubble babble for input buffer. + * + * The generated output will be of length 6*((inlen/2)+1), including the + * trailing NULL. + * + * Test vectors: + * `' (empty string) `xexax' + * `1234567890' `xesef-disof-gytuf-katof-movif-baxux' + * `Pineapple' `xigak-nyryk-humil-bosek-sonax' + */ +static char const consonants[] = "bcdfghklmnprstvz"; +static char const vowels[] = "aeiouy"; + +void +bubblebabble(unsigned char *out, + unsigned char const *in, + const size_t inlen) +{ + size_t pos = 0; + int seed = 1; + size_t i = 0; + + out[pos++] = 'x'; + while (1) { + unsigned char c; + + if (i == inlen) { + out[pos++] = vowels[seed % 6]; + out[pos++] = 'x'; + out[pos++] = vowels[seed / 6]; + break; + } + + c = in[i++]; + out[pos++] = vowels[(((c >> 6) & 3) + seed) % 6]; + out[pos++] = consonants[(c >> 2) & 15]; + out[pos++] = vowels[((c & 3) + (seed / 6)) % 6]; + if (i == inlen) { + break; + } + seed = ((seed * 5) + (c * 7) + in[i]) % 36; + + c = in[i++]; + out[pos++] = consonants[(c >> 4) & 15]; + out[pos++] = '-'; + out[pos++] = consonants[c & 15]; + } + + out[pos++] = 'x'; + out[pos] = '\0'; +} diff --git a/packages/mcp/src/common.h b/packages/mcp/src/common.h index 26931d4..3697d4a 100644 --- a/packages/mcp/src/common.h +++ b/packages/mcp/src/common.h @@ -7,7 +7,9 @@ #define TEAM_MAX 40 #define CAT_MAX 40 #define TOKEN_MAX 80 +#define itokenlen 5 +#define bubblebabble_len(n) (6*(((n)/2)+1)) int cgi_init(char *global_argv[]); size_t cgi_item(char *str, size_t maxlen); @@ -31,5 +33,8 @@ void award_and_log_uniquely(char const *team, long points, char const *logfile, char const *line); +void bubblebabble(unsigned char *out, + unsigned char const *in, + const size_t inlen); #endif diff --git a/packages/mcp/src/in.tokend.c b/packages/mcp/src/in.tokend.c index 397490d..b94183a 100644 --- a/packages/mcp/src/in.tokend.c +++ b/packages/mcp/src/in.tokend.c @@ -13,62 +13,6 @@ #include "common.h" #include "arc4.h" -#define itokenlen 5 - -char const consonants[] = "bcdfghklmnprstvz"; -char const vowels[] = "aeiouy"; - -#define bubblebabble_len(n) (6*(((n)/2)+1)) - -/** Compute bubble babble for input buffer. - * - * The generated output will be of length 6*((inlen/2)+1), including the - * trailing NULL. - * - * Test vectors: - * `' (empty string) `xexax' - * `1234567890' `xesef-disof-gytuf-katof-movif-baxux' - * `Pineapple' `xigak-nyryk-humil-bosek-sonax' - */ -void -bubblebabble(unsigned char *out, - unsigned char const *in, - const size_t inlen) -{ - size_t pos = 0; - int seed = 1; - size_t i = 0; - - out[pos++] = 'x'; - while (1) { - unsigned char c; - - if (i == inlen) { - out[pos++] = vowels[seed % 6]; - out[pos++] = 'x'; - out[pos++] = vowels[seed / 6]; - break; - } - - c = in[i++]; - out[pos++] = vowels[(((c >> 6) & 3) + seed) % 6]; - out[pos++] = consonants[(c >> 2) & 15]; - out[pos++] = vowels[((c & 3) + (seed / 6)) % 6]; - if (i == inlen) { - break; - } - seed = ((seed * 5) + (c * 7) + in[i]) % 36; - - c = in[i++]; - out[pos++] = consonants[(c >> 4) & 15]; - out[pos++] = '-'; - out[pos++] = consonants[c & 15]; - } - - out[pos++] = 'x'; - out[pos] = '\0'; -} - int main(int argc, char *argv[]) { diff --git a/packages/mcp/src/mktoken.c b/packages/mcp/src/mktoken.c new file mode 100644 index 0000000..d8790e2 --- /dev/null +++ b/packages/mcp/src/mktoken.c @@ -0,0 +1,28 @@ +#include +#include +#include "common.h" + +int +main(int argc, char *argv[]) +{ + if (2 != argc) { + fprintf(stderr, "Usage: %s CATEGORY\n", argv[0]); + return EX_USAGE; + } + + /* Create the token. */ + { + unsigned char crap[itokenlen]; + unsigned char digest[bubblebabble_len(itokenlen)]; + + urandom((char *)crap, sizeof(crap)); + + /* Digest some random junk. */ + bubblebabble(digest, (unsigned char *)&crap, itokenlen); + + /* Append digest to category name. */ + printf("%s:%s\n", argv[1], digest); + } + + return 0; +} diff --git a/packages/octopus/octopus.mk b/packages/octopus/octopus.mk index 103a92c..5c2b38a 100644 --- a/packages/octopus/octopus.mk +++ b/packages/octopus/octopus.mk @@ -1,4 +1,4 @@ -OCTOPUS_PKGDIR = $(BUILD)/octopus +OCTOPUS_PKGDIR = $(TARGET)/octopus octopus-install: octopus-build mkdir -p $(OCTOPUS_PKGDIR)/bin/ diff --git a/packages/packages.mk b/packages/packages.mk index e9c7bb0..261e2b5 100644 --- a/packages/packages.mk +++ b/packages/packages.mk @@ -9,12 +9,12 @@ define STANDARD_PUZZLE t=$(strip $1) $t-install: $t-stdinstall $t-stdinstall: - mkdir -p $(BUILD)/$t - ./mkpuzzles packages/$t $(BUILD)/$t + mkdir -p $(TARGET)/$t + ./mkpuzzles packages/$t $(TARGET)/$t $t-clean: $t-stdclean $t-stdclean: - rm -rf $(BUILD)/$t $(BIN)/$t.pkg + rm -rf $(TARGET)/$t $(BIN)/$t.pkg PACKAGES += $t endef @@ -26,10 +26,10 @@ $(foreach p, $(PACKAGES), $(eval $p: $(BIN)/$p.pkg)) packages: $(patsubst %, $(BIN)/%.pkg, $(PACKAGES)) -install: $(addsuffix -install, $(PACKAGES)) +packages-install: $(addsuffix -install, $(PACKAGES)) -clean: $(addsuffix -clean, $(PACKAGES)) - rm -rf $(BUILD) $(BIN) +packages-clean: $(addsuffix -clean, $(PACKAGES)) + rm -rf $(TARGET) $(BIN) $(foreach p, $(PACKAGES), $(eval $p-clean: $p-pkgclean)) %-pkgclean: @@ -37,4 +37,4 @@ $(foreach p, $(PACKAGES), $(eval $p-clean: $p-pkgclean)) $(BIN)/%.pkg: %-install @ mkdir -p $(@D) - mksquashfs $(BUILD)/$* $@ -all-root -noappend -no-progress + mksquashfs $(TARGET)/$* $@ -all-root -noappend -no-progress diff --git a/packages/printf/printf.mk b/packages/printf/printf.mk index 14a9474..f77ba09 100644 --- a/packages/printf/printf.mk +++ b/packages/printf/printf.mk @@ -1,4 +1,4 @@ -PRINTF_PKGDIR = $(BUILD)/printf +PRINTF_PKGDIR = $(TARGET)/printf printf-install: printf-build mkdir -p $(PRINTF_PKGDIR) diff --git a/packages/pwnables/pwnables.mk b/packages/pwnables/pwnables.mk index c45477d..873192b 100644 --- a/packages/pwnables/pwnables.mk +++ b/packages/pwnables/pwnables.mk @@ -1,4 +1,4 @@ -PWNABLES_PKGDIR = $(BUILD)/pwnables +PWNABLES_PKGDIR = $(TARGET)/pwnables pwnables-install: pwnables-build mkdir -p $(PWNABLES_PKGDIR) diff --git a/packages/tanks/tanks.mk b/packages/tanks/tanks.mk new file mode 100644 index 0000000..37d410b --- /dev/null +++ b/packages/tanks/tanks.mk @@ -0,0 +1,21 @@ +TANKS_PKGDIR = $(TARGET)/tanks +TANKS_BUILDDIR = $(BUILD)/tanks +TANKS_TAR = $(CACHE)/tanks.tar.gz +TANKS_URL = "http://woozle.org/~neale/gitweb.cgi?p=ctanks;a=snapshot;h=master;sf=tgz" + +$(TANKS_TAR): + @ mkdir -p $(@D) + wget -O $@ $(TANKS_URL) + +tanks-source: $(TANKS_BUILDDIR)/ctanks +$(TANKS_BUILDDIR)/ctanks: $(TANKS_TAR) + mkdir -p $(TANKS_BUILDDIR) + zcat $(TANKS_TAR) | (cd $(TANKS_BUILDDIR) && tar xf -) + +tanks-build: tanks-source + $(MAKE) -C $(TANKS_BUILDDIR)/ctanks + +tanks-install: tanks-build + +tanks-clean: + rm -f $(TANKS_BUILDDIR) diff --git a/packages/tokens/tokens.mk b/packages/tokens/tokens.mk index ee2cecc..e3e1601 100644 --- a/packages/tokens/tokens.mk +++ b/packages/tokens/tokens.mk @@ -1,4 +1,4 @@ -TOKENS_PKGDIR = $(BUILD)/tokens +TOKENS_PKGDIR = $(TARGET)/tokens tokens-install: tokens-build mkdir -p $(TOKENS_PKGDIR)/bin/