Start to add in tanks

This commit is contained in:
Neale Pickett 2010-10-25 17:17:10 -06:00
parent 9e8f0b39ed
commit b563456fda
16 changed files with 149 additions and 70 deletions

3
.gitignore vendored
View File

@ -4,3 +4,6 @@
*.o
bin/
build/
cache/
target/

View File

@ -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

View File

@ -1,4 +1,4 @@
LOGGER_PKGDIR = $(BUILD)/logger
LOGGER_PKGDIR = $(TARGET)/logger
logger-install: logger-build
mkdir -p $(LOGGER_PKGDIR)

View File

@ -1,4 +1,4 @@
MCP_PKGDIR = $(BUILD)/mcp
MCP_PKGDIR = $(TARGET)/mcp
mcp-install: mcp-build
mkdir -p $(MCP_PKGDIR)

View File

@ -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

View File

@ -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

View File

@ -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';
}

View File

@ -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

View File

@ -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[])
{

View File

@ -0,0 +1,28 @@
#include <stdio.h>
#include <sysexits.h>
#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;
}

View File

@ -1,4 +1,4 @@
OCTOPUS_PKGDIR = $(BUILD)/octopus
OCTOPUS_PKGDIR = $(TARGET)/octopus
octopus-install: octopus-build
mkdir -p $(OCTOPUS_PKGDIR)/bin/

View File

@ -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

View File

@ -1,4 +1,4 @@
PRINTF_PKGDIR = $(BUILD)/printf
PRINTF_PKGDIR = $(TARGET)/printf
printf-install: printf-build
mkdir -p $(PRINTF_PKGDIR)

View File

@ -1,4 +1,4 @@
PWNABLES_PKGDIR = $(BUILD)/pwnables
PWNABLES_PKGDIR = $(TARGET)/pwnables
pwnables-install: pwnables-build
mkdir -p $(PWNABLES_PKGDIR)

21
packages/tanks/tanks.mk Normal file
View File

@ -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)

View File

@ -1,4 +1,4 @@
TOKENS_PKGDIR = $(BUILD)/tokens
TOKENS_PKGDIR = $(TARGET)/tokens
tokens-install: tokens-build
mkdir -p $(TOKENS_PKGDIR)/bin/