diff --git a/go b/go new file mode 100755 index 0000000..75478d0 --- /dev/null +++ b/go @@ -0,0 +1,56 @@ +#! /bin/sh -e + +TYPE=p2 + +case ${1:-$TYPE} in + mcp) + packages='mcp net-re' + ;; + router) + packages='router' + ;; + p2) + packages='p2 sequence' + ;; + p2cli) + packages='p2client' + ;; +esac + +PATH=$HOME/src/buildroot/output/host/usr/bin:$PATH +for arch in arm i386; do + command -v ${arch}-linux-cc && ARCH=${arch}-linux export ARCH +done + +if [ -z "$ARCH" ]; then + echo "I can't find a cross-compiler." + exit 1 +fi + +make -C $HOME/src/puzzles +make -C $HOME/src/ctf + +for p in $packages; do + for pd in ctf puzzles; do + pp=$HOME/src/$pd/bin/$p.pkg + [ -f $pp ] && op="$op $pp" + done +done + +mksquashfs \ + $op \ + $HOME/ctf.squashfs -noappend + +echo $ARCH + +if [ $ARCH = i386-linux ]; then + lsmod | grep -q kvm-intel || sudo modprobe kvm-intel + sudo kvm \ + -serial stdio \ + -kernel $HOME/src/buildroot/output/images/bzImage \ + -initrd $HOME/src/buildroot/output/images/rootfs.squashfs \ + -append "console=ttyS0 packages=/dev/sda ipv6 debug" \ + -hda $HOME/ctf.squashfs \ + -net nic,model=e1000 \ + -net tap,vlan=0,script=$HOME/src/ctf/qemu-ifup,downscript=/bin/true +fi diff --git a/packages/00admin/00admin.mk b/packages/00admin/00admin.mk deleted file mode 100644 index e47065a..0000000 --- a/packages/00admin/00admin.mk +++ /dev/null @@ -1,19 +0,0 @@ -00ADMIN_PKGDIR = $(TARGET)/00admin -00ADMIN_BUILDDIR = $(BUILD)/00admin - -ifndef PASSWORD -$(error PASSWORD not defined) -endif - -00admin-build: $(00ADMIN_BUILDDIR)/build -$(00ADMIN_BUILDDIR)/build: - $(MAKE) -C packages/00admin/src - -00admin-install: $(00ADMIN_BUILDDIR)/build - $(call COPYTREE, packages/00admin/service, $(00ADMIN_PKGDIR)/service) - echo "$(PASSWORD)" > $(00ADMIN_PKGDIR)/password - mkdir -p $(00ADMIN_PKGDIR)/sbin - cp packages/00admin/bin/* $(00ADMIN_PKGDIR)/bin - cp packages/00admin/src/tea $(00ADMIN_PKGDIR)/bin - -PACKAGES += 00admin diff --git a/packages/00admin/bin/fire-ip b/packages/00admin/bin/fire-ip deleted file mode 100755 index 5312539..0000000 --- a/packages/00admin/bin/fire-ip +++ /dev/null @@ -1,34 +0,0 @@ -#! /bin/sh -e - -action=$1; shift - -read n < ip.txt - -if grep -q '/' ip.txt; then - IP=$n -elif grep -q ipv4 /proc/cmdline; then - # IPv4 - IP="10.0.0.$n/16" -else - # IPv6 - l=$(busybox dc 16 o $n p) - IP="fd84:b410:3441::$l/64" -fi - - - -[ "$action" ] && ip addr $action $IP dev eth0 - -if [ "$action" = "add" ]; then - fail=fail - for i in $(seq 5); do - if ip addr | grep -v tentative | grep -Fq $IP; then - fail= - break - fi - sleep 1 - done - [ "$fail" ] && return 1 -fi - -[ "$action" = del ] || echo $IP diff --git a/packages/00admin/src/Makefile b/packages/00admin/src/Makefile deleted file mode 100644 index 67107b5..0000000 --- a/packages/00admin/src/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -all: tea -clean: - rm -f tea diff --git a/packages/00common/NOT A PACKAGE b/packages/00common/NOT A PACKAGE new file mode 100644 index 0000000..416ae7a --- /dev/null +++ b/packages/00common/NOT A PACKAGE @@ -0,0 +1,5 @@ +This directory is for things that multiple packages need. +For example, eris httpd is used by mcp, p2, and inferno. + + +This directory does not create its own package, though. diff --git a/packages/00common/ctfbase.mk b/packages/00common/ctfbase.mk new file mode 100644 index 0000000..6c1afd1 --- /dev/null +++ b/packages/00common/ctfbase.mk @@ -0,0 +1,27 @@ +ifndef PASSWORD +$(error PASSWORD not defined) +endif + +TEA_BIN = packages/00common/src/tea +POINTSCLI_BIN = packages/00common/src/pointscli +PUZZLES_BIN = packages/00common/src/puzzles.cgi + +.PHONY: ctfbase +ctfbase: $(TEA_BIN) $(POINTSCLI_BIN) $(PUZZLES_BIN) +$(TEA_BIN) $(POINTSCLI_BIN) $(PUZZLES_BIN): + $(MAKE) -C $(@D) + +packages-clean: ctfbase-clean +ctfbase-clean: + $(MAKE) -C packages/00common/src clean + +define CTFBASE_INSTALL + $(call COPYTREE, packages/00common/service, $1/service) + + mkdir -p $(1)/bin + cp $(TEA_BIN) $(1)/bin + cp $(POINTSCLI_BIN) $(1)/bin + cp $(PUZZLES_BIN) $(1)/bin + + echo "$(PASSWORD)" > $(1)/password +endef diff --git a/packages/mcp/service/pointsd/bkup.png b/packages/00common/service/pointsd/bkup.png similarity index 100% rename from packages/mcp/service/pointsd/bkup.png rename to packages/00common/service/pointsd/bkup.png diff --git a/packages/00admin/service/sshd/log/run b/packages/00common/service/pointsd/log/run similarity index 100% rename from packages/00admin/service/sshd/log/run rename to packages/00common/service/pointsd/log/run diff --git a/packages/00common/service/pointsd/mkpage b/packages/00common/service/pointsd/mkpage new file mode 100755 index 0000000..b23331e --- /dev/null +++ b/packages/00common/service/pointsd/mkpage @@ -0,0 +1,21 @@ +#! /bin/sh + +# Use first installed binary +for bin in /opt/*/bin/$1; do + if [ -x $bin ]; then + exec $bin + fi +done + +cat < + + + $1 + + +

$1

+

No $1 binary installed!

+ + +EOD diff --git a/packages/00common/service/pointsd/pointsd b/packages/00common/service/pointsd/pointsd new file mode 100755 index 0000000..7673c76 --- /dev/null +++ b/packages/00common/service/pointsd/pointsd @@ -0,0 +1,43 @@ +#! /bin/sh -e + +fn=$2/$3 + +WWW=${CTF_BASE:-/var/www} +BASE=${CTF_BASE:-/var/lib/ctf} +OPT=${CTF_BASE:-/opt} + +POINTS=$BASE/points.log +BACKUP=$WWW/backup.png +SCOREBOARD=$WWW/scoreboard.html +PUZZLES=$WWW/puzzles.html + +# Only do this if this score hasn't yet been recorded +if [ -n "$(sort -k2 $POINTS $fn | uniq -f1 -d)" ]; then + exit +fi + +# Append point. pointsd is called serially from inotify, +# so we don't need to lock it. +cat $fn >> $POINTS +rm $fn + +# Generate new backup if we can find a password file +for pwfile in $OPT/*/password; do + if [ -f $pwfile ]; then + ( + cat bkup.png + tar cvf - $BASE | gzip -c | $OPT/*/bin/tea 3< $pwfile + ) > $BACKUP.new + mv $BACKUP.new $BACKUP + break + fi +done + +# Render scoreboard +./mkpage scoreboard < $POINTS > $SCOREBOARD.new +mv $SCOREBOARD.new $SCOREBOARD + +# Render puzzles list +./mkpage puzzles.cgi > $PUZZLES.new +mv $PUZZLES.new $PUZZLES + diff --git a/packages/00common/service/pointsd/run b/packages/00common/service/pointsd/run new file mode 100755 index 0000000..6294c72 --- /dev/null +++ b/packages/00common/service/pointsd/run @@ -0,0 +1,49 @@ +#! /bin/sh -e + +exec 2>&1 + +: ${CTF_BASE:=/var/lib/ctf} + +install -d $CTF_BASE + +# Create CTF and nobody users +touch /etc/group /etc/passwd +addgroup -g 65534 nogroup || true +adduser -DH -G nogroup -u 65534 nobody || true +adduser -DHS ctf || true + +# Set up base directories +NEWDIR=$CTF_BASE/points.new +TMPDIR=$CTF_BASE/points.tmp + +install -d /var/www +install -d /var/lib/ctf +install -o ctf -m 0755 -d $NEWDIR +install -o ctf -m 0755 -d $TMPDIR + +# Create some files +touch /var/lib/ctf/points.log + +# Generate preliminary scoreboard +if [ ! -f /var/www/scoreboard.html ]; then + ./mkpage scoreboard < /dev/null > /var/www/scoreboard.html +fi + +# Generate preliminary puzzles list +if [ ! -f /var/www/puzzles.html ]; then + ./mkpage puzzles.cgi > /var/www/puzzles.html +fi + +# Run pointsd every time a new points file is dropped +if [ -x /sbin/inotifyd ]; then + exec /sbin/inotifyd ./pointsd $NEWDIR:y +fi + +# Simulate inotifyd by polling +cd $NEWDIR +while true; do + find . -type f | while read fn; do + ./pointsd m $NEWDIR ${fn#./} + done + sleep 7 +done diff --git a/packages/mcp/service/pointsd/log/run b/packages/00common/service/sshd/log/run similarity index 100% rename from packages/mcp/service/pointsd/log/run rename to packages/00common/service/sshd/log/run diff --git a/packages/00admin/service/sshd/rsa.key b/packages/00common/service/sshd/rsa.key similarity index 100% rename from packages/00admin/service/sshd/rsa.key rename to packages/00common/service/sshd/rsa.key diff --git a/packages/00admin/service/sshd/run b/packages/00common/service/sshd/run similarity index 74% rename from packages/00admin/service/sshd/run rename to packages/00common/service/sshd/run index b2e99dd..de54c2f 100755 --- a/packages/00admin/service/sshd/run +++ b/packages/00common/service/sshd/run @@ -2,7 +2,10 @@ exec 2>&1 -read password < /opt/00admin/password +password='grape guts' +for fn in /opt/*/password; do + read password < $fn && break +done printf 'root:%s' "$password" | chpasswd --md5 diff --git a/packages/mcp/src/Makefile b/packages/00common/src/Makefile similarity index 65% rename from packages/mcp/src/Makefile rename to packages/00common/src/Makefile index 134ec7c..4da5d94 100644 --- a/packages/mcp/src/Makefile +++ b/packages/00common/src/Makefile @@ -1,12 +1,12 @@ CFLAGS = -Wall -Werror -TARGETS = claim.cgi puzzler.cgi puzzles.cgi -TARGETS += pointscli +TARGETS = claim.cgi puzzler.cgi puzzles.cgi pointscli +TARGETS += tea bubblebabble all: build build: $(TARGETS) -pointscli: pointscli.o common.o +pointscli: common.o puzzles.cgi: puzzles.cgi.o common.o claim.cgi: claim.cgi.o common.o @@ -14,4 +14,3 @@ puzzler.cgi: puzzler.cgi.o common.o clean: rm -f $(TARGETS) *.o - diff --git a/packages/00common/src/bubblebabble.c b/packages/00common/src/bubblebabble.c new file mode 100644 index 0000000..7477fcd --- /dev/null +++ b/packages/00common/src/bubblebabble.c @@ -0,0 +1,54 @@ +#include +#include + +/** 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"; + +int +main(int argc, char *argv[]) +{ + int seed = 1; + + putchar('x'); + while (1) { + int c; + + c = getchar(); + if (EOF == c) { + putchar(vowels[seed % 6]); + putchar('x'); + putchar(vowels[seed / 6]); + break; + } + + putchar(vowels[(((c >> 6) & 3) + seed) % 6]); + putchar(consonants[(c >> 2) & 15]); + putchar(vowels[((c & 3) + (seed / 6)) % 6]); + + seed = (seed * 5) + (c * 7); + c = getchar(); + seed = (seed + c) % 36; + + if (EOF == c) { + break; + } + putchar(consonants[(c >> 4) & 15]); + putchar('-'); + putchar(consonants[c & 15]); + } + + putchar('x'); + putchar('\n'); + + return 0; +} diff --git a/packages/mcp/src/claim.cgi.c b/packages/00common/src/claim.cgi.c similarity index 100% rename from packages/mcp/src/claim.cgi.c rename to packages/00common/src/claim.cgi.c diff --git a/packages/mcp/src/common.c b/packages/00common/src/common.c similarity index 100% rename from packages/mcp/src/common.c rename to packages/00common/src/common.c diff --git a/packages/mcp/src/common.h b/packages/00common/src/common.h similarity index 100% rename from packages/mcp/src/common.h rename to packages/00common/src/common.h diff --git a/packages/mcp/src/pointscli.c b/packages/00common/src/pointscli.c similarity index 100% rename from packages/mcp/src/pointscli.c rename to packages/00common/src/pointscli.c diff --git a/packages/mcp/src/puzzler.cgi.c b/packages/00common/src/puzzler.cgi.c similarity index 100% rename from packages/mcp/src/puzzler.cgi.c rename to packages/00common/src/puzzler.cgi.c diff --git a/packages/mcp/src/puzzles.cgi.c b/packages/00common/src/puzzles.cgi.c similarity index 98% rename from packages/mcp/src/puzzles.cgi.c rename to packages/00common/src/puzzles.cgi.c index 4cc776f..d81de51 100644 --- a/packages/mcp/src/puzzles.cgi.c +++ b/packages/00common/src/puzzles.cgi.c @@ -59,7 +59,7 @@ main(int argc, char *argv[]) } { - FILE *f = fopen(state_path("puzzles.db"), "r"); + FILE *f = fopen(state_path("points.log"), "r"); char cat[CAT_MAX]; char points_str[11]; long points; diff --git a/packages/00admin/src/tea.c b/packages/00common/src/tea.c similarity index 100% rename from packages/00admin/src/tea.c rename to packages/00common/src/tea.c diff --git a/packages/cowbull/service/cowbull/finish b/packages/cowbull/service/cowbull/finish index 24417e3..9721530 100755 --- a/packages/cowbull/service/cowbull/finish +++ b/packages/cowbull/service/cowbull/finish @@ -1,3 +1,3 @@ #! /bin/sh -/opt/00admin/bin/fire-ip del +dbip -d diff --git a/packages/cowbull/service/cowbull/run b/packages/cowbull/service/cowbull/run index 27e24df..730e5ba 100755 --- a/packages/cowbull/service/cowbull/run +++ b/packages/cowbull/service/cowbull/run @@ -2,6 +2,6 @@ exec 2>&1 -IP=$(/opt/00admin/bin/fire-ip add) +IP=$(dbip -a) exec setuidgid nobody /opt/cowbull/bin/cowd < /opt/cowbull/tokens.txt diff --git a/packages/fizzbuzz/service/fizzbuzz/finish b/packages/fizzbuzz/service/fizzbuzz/finish index 24417e3..9721530 100755 --- a/packages/fizzbuzz/service/fizzbuzz/finish +++ b/packages/fizzbuzz/service/fizzbuzz/finish @@ -1,3 +1,3 @@ #! /bin/sh -/opt/00admin/bin/fire-ip del +dbip -d diff --git a/packages/fizzbuzz/service/fizzbuzz/run b/packages/fizzbuzz/service/fizzbuzz/run index 9d3e25f..3347b07 100755 --- a/packages/fizzbuzz/service/fizzbuzz/run +++ b/packages/fizzbuzz/service/fizzbuzz/run @@ -2,6 +2,6 @@ exec 2>&1 -IP=$(/opt/00admin/bin/fire-ip add) +IP=$(dbip -a) exec tcpsvd -u nobody ${IP%/*} 1013 ./go diff --git a/packages/ircd/service/ircd/finish b/packages/ircd/service/ircd/finish index 24417e3..9721530 100755 --- a/packages/ircd/service/ircd/finish +++ b/packages/ircd/service/ircd/finish @@ -1,3 +1,3 @@ #! /bin/sh -/opt/00admin/bin/fire-ip del +dbip -d diff --git a/packages/ircd/service/ircd/run b/packages/ircd/service/ircd/run index f7ec982..60b3963 100755 --- a/packages/ircd/service/ircd/run +++ b/packages/ircd/service/ircd/run @@ -2,7 +2,7 @@ exec 2>&1 -IP=$(/opt/00admin/bin/fire-ip add) +IP=$(dbip -a) adduser -S -H -u 65534 nobody adduser -S -H irc diff --git a/packages/mcp/fnord.patch b/packages/mcp/fnord.patch deleted file mode 100644 index 73a0436..0000000 --- a/packages/mcp/fnord.patch +++ /dev/null @@ -1,90 +0,0 @@ -diff -Naur fnord-1.10-orig//httpd.c fnord-1.10/httpd.c ---- fnord-1.10-orig//httpd.c 2005-08-03 05:32:50.000000000 -0600 -+++ fnord-1.10/httpd.c 2011-03-14 17:05:57.000000000 -0600 -@@ -163,9 +163,8 @@ - - #define MAXHEADERLEN 8192 - --char* remote_ip; -+char* remote_addr; - #ifdef CGI --char* remote_port; - char* remote_ident; - #endif - -@@ -186,7 +185,7 @@ - time_t t=time(0); - struct tm* x=localtime(&t); - int l=-(timezone/60); -- buffer_puts(buffer_2,remote_ip?remote_ip:"0.0.0.0"); -+ buffer_puts(buffer_2,remote_addr?remote_addr:"0.0.0.0"); - buffer_puts(buffer_2," - - ["); - - buffer_put2digits(buffer_2,x->tm_mday); -@@ -219,7 +218,7 @@ - buffer_putrange(buffer_2,len); - - #else -- buffer_puts(buffer_2,remote_ip?remote_ip:"0.0.0.0"); -+ buffer_puts(buffer_2,remote_addr?remote_addr:"0.0.0.0"); - buffer_putspace(buffer_2); - buffer_putulong(buffer_2,retcode); - buffer_putspace(buffer_2); -@@ -271,7 +270,6 @@ - "REQUEST_URI=", - "SCRIPT_NAME=", - "REMOTE_ADDR=", -- "REMOTE_PORT=", - "REMOTE_IDENT=", - "HTTP_USER_AGENT=", - "HTTP_COOKIE=", -@@ -337,17 +335,10 @@ - *tmp=0; ++tmp; - - i=7; -- if (remote_ip) { -+ if (remote_addr) { - cgi_env[++i]=tmp; - tmp+=str_copy(tmp,"REMOTE_ADDR="); -- tmp+=str_copy(tmp,remote_ip); -- *tmp=0; ++tmp; -- } -- -- if (remote_port) { -- cgi_env[++i]=tmp; -- tmp+=str_copy(tmp,"REMOTE_PORT="); -- tmp+=str_copy(tmp,remote_port); -+ tmp+=str_copy(tmp,remote_addr); - *tmp=0; ++tmp; - } - -@@ -663,8 +654,9 @@ - static char* mimetype="text/plain"; - - static struct mimeentry { const char* name, *type; } mimetab[] = { -- { "html", "text/html" }, -- { "htm", "text/html" }, -+ { "html", "text/html; charset=utf-8" }, -+ { "htm", "text/html; charset=utf-8" }, -+ { "txt", "text/plain; charset=utf-8" }, - { "css", "text/css" }, - { "dvi", "application/x-dvi" }, - { "ps", "application/postscript" }, -@@ -1060,16 +1052,7 @@ - static void get_ucspi_env(void) { - char* ucspi=getenv("PROTO"); - if (ucspi) { -- char* buf=alloca(str_len(ucspi)+20); -- unsigned int tmp=str_copy(buf,ucspi); -- buf[tmp+str_copy(buf+tmp,"REMOTEIP")]=0; -- remote_ip=getenv(buf); --#ifdef CGI -- buf[tmp+str_copy(buf+tmp,"REMOTEPORT")]=0; -- remote_port=getenv(buf); -- buf[tmp+str_copy(buf+tmp,"REMOTEINFO")]=0; -- remote_ident=getenv(buf); --#endif -+ remote_addr=getenv("REMOTEADDR"); - } - } - diff --git a/packages/mcp/mcp.mk b/packages/mcp/mcp.mk index 066db23..27f7f37 100644 --- a/packages/mcp/mcp.mk +++ b/packages/mcp/mcp.mk @@ -1,36 +1,21 @@ MCP_PKGDIR = $(TARGET)/mcp -MCP_BUILDDIR = $(BUILD)/mcp -mcp-source: $(MCP_BUILDDIR)/source -$(MCP_BUILDDIR)/source: - mkdir -p $(@D) - touch $@ - -mcp-build: $(MCP_BUILDDIR)/build -$(MCP_BUILDDIR)/build: $(MCP_BUILDDIR)/source - $(MAKE) -C packages/mcp/src build - -mcp-install: $(MCP_BUILDDIR)/build eris +mcp-install: eris ctfbase mkdir -p $(MCP_PKGDIR) + $(call CTFBASE_INSTALL, $(MCP_PKGDIR)) + $(call COPYTREE, packages/mcp/bin, $(MCP_PKGDIR)/bin) - cp packages/mcp/src/pointscli $(MCP_PKGDIR)/bin/ - cp packages/mcp/src/puzzles.cgi $(MCP_PKGDIR)/bin/ - cp packages/mcp/src/tea $(MCP_PKGDIR)/bin/ cp $(ERIS_BIN) $(MCP_PKGDIR)/bin/ $(call COPYTREE, packages/mcp/service, $(MCP_PKGDIR)/service) $(call COPYTREE, packages/mcp/www, $(MCP_PKGDIR)/www) - cp packages/mcp/src/puzzler.cgi $(MCP_PKGDIR)/www/ - cp packages/mcp/src/claim.cgi $(MCP_PKGDIR)/www/ + cp packages/00common/src/puzzler.cgi $(MCP_PKGDIR)/www/ + cp packages/00common/src/claim.cgi $(MCP_PKGDIR)/www/ mcp-test: mcp-build packages/mcp/test.sh -mcp-clean: - rm -rf $(MCP_PKGDIR) $(MCP_BUILDDIR) - $(MAKE) -C packages/mcp/src clean - PACKAGES += mcp \ No newline at end of file diff --git a/packages/mcp/service/httpd/finish b/packages/mcp/service/httpd/finish index 24417e3..9721530 100755 --- a/packages/mcp/service/httpd/finish +++ b/packages/mcp/service/httpd/finish @@ -1,3 +1,3 @@ #! /bin/sh -/opt/00admin/bin/fire-ip del +dbip -d diff --git a/packages/mcp/service/httpd/run b/packages/mcp/service/httpd/run index 6c10d7f..7ecd50e 100755 --- a/packages/mcp/service/httpd/run +++ b/packages/mcp/service/httpd/run @@ -2,7 +2,7 @@ exec 2>&1 -IP=$(/opt/00admin/bin/fire-ip add) +IP=$(dbip -a) hostname mcp diff --git a/packages/mcp/service/pointsd/pointsd b/packages/mcp/service/pointsd/pointsd deleted file mode 100755 index 9d64efa..0000000 --- a/packages/mcp/service/pointsd/pointsd +++ /dev/null @@ -1,31 +0,0 @@ -#! /bin/sh -e - -fn=$2/$3 - -WWW=${CTF_BASE:-/var/www} -BASE=${CTF_BASE:-/var/lib/ctf} -OPT=${CTF_BASE:-/opt} - -POINTS=$BASE/points.log -BACKUP=$WWW/backup.png -SCOREBOARD=$WWW/scoreboard.html - -# Only do this if this score hasn't yet been recorded -if [ -z "$(sort -k2 $POINTS $fn | uniq -f1 -d)" ]; then - cat $fn >> $POINTS - rm $fn -fi - -if [ $POINTS -nt $SCOREBOARD ]; then - # Generate new backup - ( - cat bkup.png; - tar cvf - $BASE | gzip -c | $OPT/00admin/bin/tea 3< $OPT/00admin/password - ) > $BACKUP.new - mv $BACKUP.new $BACKUP - - # Render scoreboard - /opt/mcp/bin/scoreboard < $POINTS > $SCOREBOARD.new - mv $SCOREBOARD.new $SCOREBOARD -fi - diff --git a/packages/mcp/service/pointsd/run b/packages/mcp/service/pointsd/run deleted file mode 100755 index f393539..0000000 --- a/packages/mcp/service/pointsd/run +++ /dev/null @@ -1,44 +0,0 @@ -#! /bin/sh -e - -exec 2>&1 - -install -d /var/lib/ctf - -# Create CTF and nobody users -touch /etc/group /etc/passwd -addgroup -g 65534 nogroup || true -adduser -D -S -h /var/lib/ctf -H ctf || true -adduser -D -g nogroup -u 65534 -h /tmp -H nobody || true - -# Set up base directories -NEWDIR=/var/lib/ctf/points.new -install -d /var/www -install -d /var/lib/ctf -install -o ctf -m 0755 -d $NEWDIR -install -o ctf -m 0755 -d /var/lib/ctf/points.tmp - -# Create some files -CLAIM=/var/lib/ctf/claim.db -touch $CLAIM -chown ctf $CLAIM -touch /var/lib/ctf/points.log - -# Generate preliminary scoreboard -if ! [ -f /var/www/scoreboard.html ]; then - /opt/mcp/bin/scoreboard < /dev/null > /var/www/scoreboard.html -fi - - -if [ -x /sbin/inotifyd ]; then - exec /sbin/inotifyd ./pointsd $NEWDIR:y -fi - -# Simulate inotifyd -cd $NEWDIR -while true; do - for fn in *; do - [ -f "$fn" ] || continue - ./pointsd m $NEWDIR $fn - done - sleep 7 -done diff --git a/packages/mcp/service/puzzled/puzzled b/packages/mcp/service/puzzled/puzzled deleted file mode 100755 index 5316667..0000000 --- a/packages/mcp/service/puzzled/puzzled +++ /dev/null @@ -1,5 +0,0 @@ -#! /bin/sh - -PUZZLES=/var/www/puzzles.html - -/opt/mcp/bin/puzzles.cgi > $PUZZLES.new && mv $PUZZLES.new $PUZZLES diff --git a/packages/mcp/service/puzzled/run b/packages/mcp/service/puzzled/run deleted file mode 100755 index 08f8d43..0000000 --- a/packages/mcp/service/puzzled/run +++ /dev/null @@ -1,15 +0,0 @@ -#! /bin/sh -e - -exec 2>&1 - -install -d /var/www - -# Install truncates files -DB=/var/lib/ctf/puzzles.db -touch $DB -chown ctf $DB - -# Make an initial listing -./puzzled - -exec inotifyd ./puzzled ${DB}:w diff --git a/packages/mcp/src/arc4.h b/packages/mcp/src/arc4.h deleted file mode 100644 index 64dc565..0000000 --- a/packages/mcp/src/arc4.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef __ARC4_H__ -#define __ARC4_H__ - -#include -#include -#include - -#define ARC4_KEYLEN 256 - -struct arc4_ctx { - uint8_t S[256]; - uint8_t i; - uint8_t j; -}; - -/* Stream operations */ -ssize_t -arc4_encrypt_stream(FILE *out, FILE *in, - const uint8_t *key, size_t keylen); -ssize_t -arc4_decrypt_stream(FILE *out, FILE *in, - const uint8_t *key, size_t keylen); - - -/* Auto-seeding Psuedo Random Number Generator */ -void arc4_rand_seed(const uint8_t *seed, size_t seedlen); -uint8_t arc4_rand8(); -uint32_t arc4_rand32(); - -/* Low-level operations */ -void arc4_init(struct arc4_ctx *ctx, const uint8_t *key, size_t keylen); -uint8_t arc4_out(struct arc4_ctx *ctx); -void arc4_crypt(struct arc4_ctx *ctx, - uint8_t *obuf, const uint8_t *ibuf, size_t buflen); -void arc4_crypt_buffer(const uint8_t *key, size_t keylen, - uint8_t *buf, size_t buflen); -void arc4_nonce(uint8_t *nonce, size_t noncelen, void *seed, size_t seedlen); - - -#endif diff --git a/packages/multicaster/service/multicaster/finish b/packages/multicaster/service/multicaster/finish index 24417e3..9721530 100755 --- a/packages/multicaster/service/multicaster/finish +++ b/packages/multicaster/service/multicaster/finish @@ -1,3 +1,3 @@ #! /bin/sh -/opt/00admin/bin/fire-ip del +dbip -d diff --git a/packages/multicaster/service/multicaster/run b/packages/multicaster/service/multicaster/run index 173af0d..9356c83 100755 --- a/packages/multicaster/service/multicaster/run +++ b/packages/multicaster/service/multicaster/run @@ -2,6 +2,6 @@ exec 2>&1 -IP=$(/opt/00admin/bin/fire-ip add) +IP=$(dbip -a) exec setuidgid ctf /opt/multicaster/bin/multicaster ff15::62c 1580 &1 -IP=$(/opt/00admin/bin/fire-ip) +IP=$(dbip -p ../octopus/ip.txt) sv s octopus >/dev/null || exit 1 exec tcpsvd ${IP%/*} 8888 ./octopus-redirect diff --git a/packages/octopus/service/octopus/finish b/packages/octopus/service/octopus/finish index 24417e3..9721530 100755 --- a/packages/octopus/service/octopus/finish +++ b/packages/octopus/service/octopus/finish @@ -1,3 +1,3 @@ #! /bin/sh -/opt/00admin/bin/fire-ip del +dbip -d diff --git a/packages/octopus/service/octopus/run b/packages/octopus/service/octopus/run index 78a5bdd..b8e1df0 100755 --- a/packages/octopus/service/octopus/run +++ b/packages/octopus/service/octopus/run @@ -2,7 +2,7 @@ exec 2>&1 -IP=$(/opt/00admin/bin/fire-ip add) +IP=$(dbip -a) grep -q ipv4 /proc/cmdline && IP=::ffff:$IP diff --git a/packages/p2/bin/p2console b/packages/p2/bin/p2console index a1f736b..8a2d6e5 100755 --- a/packages/p2/bin/p2console +++ b/packages/p2/bin/p2console @@ -1,15 +1,7 @@ #! /bin/sh -: ${BASE:=/var/lib/ctf/p2} - -mkdir -p $BASE - -if ! [ -f $BASE/salt ]; then - dd if=/dev/urandom count=1 | md5sum - > $BASE/salt -fi -clear -printf '\017' -read salt < $BASE/salt +: ${CTF_BASE:=/var/lib/ctf} +BASE=$CTF_BASE/teams esc () { printf '%s' "$*" | sed 's/[^-0-9A-Za-z ]/_/g; s/ /+/g' @@ -28,14 +20,12 @@ newteam () { fi hash=$(printf '%s %s' "$salt" "$name" | md5sum | cut -b 1-8) - if [ -d $BASE/$hash ]; then + if [ -f $BASE/names/$hash ]; then echo "That name is already in use. Try another one." return fi - mkdir $BASE/$hash - - printf '%s' "$name" > $BASE/$hash/.name + printf '%s' "$name" > $BASE/names/$hash cat < $fn + elif pointscli $hash $cat $points p2console; then echo "You get $points more points in the $cat category." - # run puzzles.cgi - # update scoreboard + else + echo "Error recording points. Tell the officials!" fi done diff --git a/packages/p2/p2.mk b/packages/p2/p2.mk new file mode 100644 index 0000000..09a581b --- /dev/null +++ b/packages/p2/p2.mk @@ -0,0 +1,25 @@ +P2_PKGDIR = $(TARGET)/p2 + +p2-build: packages/p2/src/modem +packages/p2/src/modem: + $(MAKE) -C packages/p2/src + +p2-install: packages/p2/src/modem eris ctfbase + mkdir -p $(P2_PKGDIR) + + $(call CTFBASE_INSTALL, $(P2_PKGDIR)) + + $(call COPYTREE, packages/p2/bin, $(P2_PKGDIR)/bin) + + cp $(ERIS_BIN) $(P2_PKGDIR)/bin/ + cp packages/p2/src/modem $(P2_PKGDIR)/bin/ + + $(call COPYTREE, packages/p2/service, $(P2_PKGDIR)/service) + + $(call COPYTREE, packages/mcp/www, $(P2_PKGDIR)/www) + +p2-clean: + $(MAKE) -C packages/p2/src + +PACKAGES += p2 + diff --git a/packages/p2/service/httpd/finish b/packages/p2/service/httpd/finish deleted file mode 100755 index 24417e3..0000000 --- a/packages/p2/service/httpd/finish +++ /dev/null @@ -1,3 +0,0 @@ -#! /bin/sh - -/opt/00admin/bin/fire-ip del diff --git a/packages/mcp/service/puzzled/log/run b/packages/p2/service/httpd/log/run similarity index 100% rename from packages/mcp/service/puzzled/log/run rename to packages/p2/service/httpd/log/run diff --git a/packages/p2/service/httpd/run b/packages/p2/service/httpd/run index d0db2cf..5042f67 100755 --- a/packages/p2/service/httpd/run +++ b/packages/p2/service/httpd/run @@ -2,12 +2,7 @@ exec 2>&1 -IP=$(/opt/00admin/bin/fire-ip add) - -addgroup -g 65534 nogroup || true -adduser -D -g nogroup -u 65534 -h /tmp -H nobody || true - -hostname p2 +IP=$(dbip -p ../p2console/ip.txt) # Link in puzzles and web pages install -d /var/www diff --git a/packages/p2/service/p2console/finish b/packages/p2/service/p2console/finish new file mode 100755 index 0000000..9721530 --- /dev/null +++ b/packages/p2/service/p2console/finish @@ -0,0 +1,3 @@ +#! /bin/sh + +dbip -d diff --git a/packages/p2/service/httpd/ip.txt b/packages/p2/service/p2console/ip.txt similarity index 100% rename from packages/p2/service/httpd/ip.txt rename to packages/p2/service/p2console/ip.txt diff --git a/packages/p2/service/pointsd/log/run b/packages/p2/service/p2console/log/run similarity index 100% rename from packages/p2/service/pointsd/log/run rename to packages/p2/service/p2console/log/run diff --git a/packages/p2/service/p2console/p2console b/packages/p2/service/p2console/p2console new file mode 100755 index 0000000..310396a --- /dev/null +++ b/packages/p2/service/p2console/p2console @@ -0,0 +1,5 @@ +#! /bin/sh + +while true; do + /opt/p2/bin/p2console +done | /opt/p2/bin/modem diff --git a/packages/p2/service/p2console/run b/packages/p2/service/p2console/run new file mode 100755 index 0000000..aa7b0fd --- /dev/null +++ b/packages/p2/service/p2console/run @@ -0,0 +1,15 @@ +#! /bin/sh -e + +exec 2>&1 + +hostname p2 + +IP=$(dbip -a) +install -d /var/lib/ctf/teams +install -o ctf -m 0755 -d /var/lib/ctf/teams/names + +if ! [ -f /var/lib/ctf/teams/salt ]; then + dd if=/dev/urandom count=1 | md5sum - > /var/lib/ctf/teams/salt +fi + +exec setuidgid ctf tcpsvd 0 5555 ./p2console diff --git a/packages/p2/service/pointsd/pointsd b/packages/p2/service/pointsd/pointsd deleted file mode 100755 index 1b0c987..0000000 --- a/packages/p2/service/pointsd/pointsd +++ /dev/null @@ -1,31 +0,0 @@ -#! /bin/sh -e - -fn=$2/$3 - -WWW=${CTF_BASE:-/var/www} -BASE=${CTF_BASE:-/var/lib/ctf} -OPT=${CTF_BASE:-/opt} - -POINTS=$BASE/points.log -BACKUP=$WWW/backup.png -SCOREBOARD=$WWW/scoreboard.html - -# Only do this if this score hasn't yet been recorded -if [ -z "$(sort -k2 $POINTS $fn | uniq -f1 -d)" ]; then - cat $fn >> $POINTS - rm $fn -fi - -if [ $POINTS -nt $SCOREBOARD ]; then - # Generate new backup - ( - cat bkup.png; - tar cvf - $BASE | gzip -c | $OPT/00admin/bin/tea 3< $OPT/00admin/password - ) > $BACKUP.new - mv $BACKUP.new $BACKUP - - # Render scoreboard - /opt/p2/bin/scoreboard < $POINTS > $SCOREBOARD.new - mv $SCOREBOARD.new $SCOREBOARD -fi - diff --git a/packages/p2/service/pointsd/run b/packages/p2/service/pointsd/run deleted file mode 100755 index f393539..0000000 --- a/packages/p2/service/pointsd/run +++ /dev/null @@ -1,44 +0,0 @@ -#! /bin/sh -e - -exec 2>&1 - -install -d /var/lib/ctf - -# Create CTF and nobody users -touch /etc/group /etc/passwd -addgroup -g 65534 nogroup || true -adduser -D -S -h /var/lib/ctf -H ctf || true -adduser -D -g nogroup -u 65534 -h /tmp -H nobody || true - -# Set up base directories -NEWDIR=/var/lib/ctf/points.new -install -d /var/www -install -d /var/lib/ctf -install -o ctf -m 0755 -d $NEWDIR -install -o ctf -m 0755 -d /var/lib/ctf/points.tmp - -# Create some files -CLAIM=/var/lib/ctf/claim.db -touch $CLAIM -chown ctf $CLAIM -touch /var/lib/ctf/points.log - -# Generate preliminary scoreboard -if ! [ -f /var/www/scoreboard.html ]; then - /opt/mcp/bin/scoreboard < /dev/null > /var/www/scoreboard.html -fi - - -if [ -x /sbin/inotifyd ]; then - exec /sbin/inotifyd ./pointsd $NEWDIR:y -fi - -# Simulate inotifyd -cd $NEWDIR -while true; do - for fn in *; do - [ -f "$fn" ] || continue - ./pointsd m $NEWDIR $fn - done - sleep 7 -done diff --git a/packages/p2/src/Makefile b/packages/p2/src/Makefile index 5330d0a..3f5b8ba 100644 --- a/packages/p2/src/Makefile +++ b/packages/p2/src/Makefile @@ -1,4 +1,4 @@ -all: modem tea +all: modem clean: - rm -f modem tea + rm -f modem diff --git a/packages/p2/www/ctf.css b/packages/p2/www/ctf.css index 08e8ec1..cf6a559 100644 --- a/packages/p2/www/ctf.css +++ b/packages/p2/www/ctf.css @@ -2,7 +2,7 @@ /**** Color Scheme ****/ html { - background: #112 url(smoke.jpg) no-repeat; + background: #112 url(p2inv.jpg) no-repeat; background-size: contain; } diff --git a/packages/p2/www/index.html b/packages/p2/www/index.html index 9785442..5606c6f 100644 --- a/packages/p2/www/index.html +++ b/packages/p2/www/index.html @@ -15,9 +15,6 @@
  • Puzzles
  • -
  • - News -
  • About scoring
  • diff --git a/packages/p2client/service/p2client/p2connect b/packages/p2client/service/p2client/p2connect index f4d823a..5b3bb4d 100755 --- a/packages/p2client/service/p2client/p2connect +++ b/packages/p2client/service/p2client/p2connect @@ -1,11 +1,13 @@ #! /bin/sh -# Try hard to look like a serial connection - +# Try hard to look like a serial terminal reset +# Maybe this is some startup code +sleep 0.4 + # Print some bullshit to confuse people -printf 'RS232/0:1200-N81 ' +printf 'S0:1200N81 ' # Simulate a green-phosphor CRT printf '\033]P0111122\033]P788ff00\033]Pfff8800' diff --git a/packages/playfair/service/playfair/finish b/packages/playfair/service/playfair/finish index 24417e3..9721530 100755 --- a/packages/playfair/service/playfair/finish +++ b/packages/playfair/service/playfair/finish @@ -1,3 +1,3 @@ #! /bin/sh -/opt/00admin/bin/fire-ip del +dbip -d diff --git a/packages/playfair/service/playfair/run b/packages/playfair/service/playfair/run index eaa58da..e7a9470 100755 --- a/packages/playfair/service/playfair/run +++ b/packages/playfair/service/playfair/run @@ -2,7 +2,7 @@ exec 2>&1 -IP=$(/opt/00admin/bin/fire-ip add) +IP=$(dbip -a) ip addr add $IP dev eth0 || true exec tcpsvd -u nobody ${IP%/*} 1013 /opt/playfair/bin/playfair diff --git a/packages/printf/service/printf/finish b/packages/printf/service/printf/finish index 24417e3..9721530 100755 --- a/packages/printf/service/printf/finish +++ b/packages/printf/service/printf/finish @@ -1,3 +1,3 @@ #! /bin/sh -/opt/00admin/bin/fire-ip del +dbip -d diff --git a/packages/printf/service/printf/run b/packages/printf/service/printf/run index b37c812..92a725d 100755 --- a/packages/printf/service/printf/run +++ b/packages/printf/service/printf/run @@ -2,7 +2,7 @@ exec 2>&1 -IP=$(/opt/00admin/bin/fire-ip add) +IP=$(dbip -a) # So I say to him, "Alex, what's a good high port number for a CTF category?" # And he says, "6" diff --git a/packages/revwords/service/revwords/finish b/packages/revwords/service/revwords/finish index 24417e3..9721530 100755 --- a/packages/revwords/service/revwords/finish +++ b/packages/revwords/service/revwords/finish @@ -1,3 +1,3 @@ #! /bin/sh -/opt/00admin/bin/fire-ip del +dbip -d diff --git a/packages/revwords/service/revwords/run b/packages/revwords/service/revwords/run index a328c26..ada9905 100755 --- a/packages/revwords/service/revwords/run +++ b/packages/revwords/service/revwords/run @@ -2,7 +2,7 @@ exec 2>&1 -IP=$(/opt/00admin/bin/fire-ip add) +IP=$(dbip -a) exec tcpsvd -u nobody ${IP%/*} 1013 ./go diff --git a/packages/rlyeh/service/rlyeh/finish b/packages/rlyeh/service/rlyeh/finish index 24417e3..9721530 100755 --- a/packages/rlyeh/service/rlyeh/finish +++ b/packages/rlyeh/service/rlyeh/finish @@ -1,3 +1,3 @@ #! /bin/sh -/opt/00admin/bin/fire-ip del +dbip -d diff --git a/packages/rlyeh/service/rlyeh/run b/packages/rlyeh/service/rlyeh/run index 91fc8eb..6060676 100755 --- a/packages/rlyeh/service/rlyeh/run +++ b/packages/rlyeh/service/rlyeh/run @@ -2,7 +2,7 @@ exec 2>&1 -IP=$(/opt/00admin/bin/fire-ip add) +IP=$(dbip -a) dir=/var/lib/ctf/rlyeh install -o nobody -d $dir diff --git a/qemu-ifup b/qemu-ifup new file mode 100755 index 0000000..6708fed --- /dev/null +++ b/qemu-ifup @@ -0,0 +1,5 @@ +#! /bin/sh + +ip addr add fd84:b410:3441::ffff/64 dev $1 +ip addr add 10.0.0.254/24 dev $1 +