From b7bbe1ccc6157e1eb3135db220b18ab2aaf67025 Mon Sep 17 00:00:00 2001 From: sose Date: Thu, 11 Oct 2018 06:50:26 +0200 Subject: [PATCH] Changed death mechanics --- deluser.sh | 7 ++++--- gamestatus | 1 + killme.sh | 16 ++++++++++++++++ listen.py | 48 ---------------------------------------------- login.sh | 8 +++++++- newuser.sh | 4 +++- suicidebash.bashrc | 2 +- users.txt | 1 - 8 files changed, 32 insertions(+), 55 deletions(-) create mode 100755 killme.sh delete mode 100755 listen.py diff --git a/deluser.sh b/deluser.sh index 5773af4..9147351 100755 --- a/deluser.sh +++ b/deluser.sh @@ -1,7 +1,7 @@ #!/bin/sh SLBRUSER=$1 test -z "$SLBRUSER" && echo "no user provided" && exit -if !(grep -qx "$SLBRUSER" users.txt) +if !(grep -qE "^$SLBRUSER$" users.txt) then echo "user not found in users.txt, will not delete" exit @@ -9,7 +9,7 @@ fi if ps -o stat= -p $PPID | grep -qv S+ #check if this is being called from listen.py then - echo "YOU ARE ABOUT TO PERMANENTLY DELETE USER $SLBRUSER AND ALL OF THEIR DATA. RE-ENTER THE USERS NAME TO CONTINUE" + echo "YOU ARE ABOUT TO PERMANENTLY DELETE USER $SLBRUSER AND ALL OF THEIR DATA. RE-ENTER THE USER'S NAME TO CONTINUE" read -r ENTEREDUSER [ "$ENTEREDUSER" != "$SLBRUSER" ] && echo "users did not match, exiting..." && exit fi @@ -17,4 +17,5 @@ lxc stop "$SLBRUSER" lxc delete "$SLBRUSER" sudo rm -rf "$SLBRUSER" sudo userdel "$SLBRUSER" -sed -ie "s/$SLBRUSER .*$//g" +sed -i "s/^$SLBRUSER$//g" users.txt +sed -i '/^$/d' users.txt diff --git a/gamestatus b/gamestatus index e69de29..8b13789 100644 --- a/gamestatus +++ b/gamestatus @@ -0,0 +1 @@ + diff --git a/killme.sh b/killme.sh new file mode 100755 index 0000000..f4aadc2 --- /dev/null +++ b/killme.sh @@ -0,0 +1,16 @@ +#!/bin/sh +#This should only be run by users who have been eliminated +SLBRUSER=$(whoami) +test -z "$SLBRUSER" && echo "no user provided" && exit +if !(grep -qE "^$SLBRUSER$" /home/slbr/users.txt) +then + echo "user not found in users.txt, will not delete" + exit +fi + +rm -rf "/home/sblr/$SLBRUSER" +userdel "$SLBRUSER" +sed -i "s/^$SLBRUSER$//g" /home/slbr/users.txt +sed -i '/^$/d' /home/slbr/users.txt +lxc stop "$SLBRUSER" +lxc delete "$SLBRUSER" diff --git a/listen.py b/listen.py deleted file mode 100755 index 4f115a7..0000000 --- a/listen.py +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/python3 -import socket -import threading -import os # oh no - -serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) -serversocket.bind(("test.tilde.team", 9090)) -serversocket.listen(5) - - -def clientthread(conn): - while True: - data = conn.recv(1024) - if not data: - break - - message = data.decode("utf-8").replace("\n", "") - print("writing to log") - log = open("gamelog.txt", "a") - print(message, file=log) - log.close() - - print("sending message") - os.system("./sendmsg.sh \"$(tail -n1 gamelog.txt)\"") # oh noooooo - print("sent message: " + message) - - userisdead = False - deaduser = message.split(" ")[0] - - print("Looking for user in userfile") - with open("users.txt") as userfile: - if deaduser in userfile.read(): - userisdead = True - else: - print("could not find user in userfile, will not delete") - - if userisdead: - print("eliminating " + deaduser) - os.system("./deluser.sh " + deaduser) - conn.close() - break - - -while True: - (clientsocket, address) = serversocket.accept() - print("Connected to " + address[0]) - threading.Thread(target=clientthread, args=(clientsocket,)).start() -serversocket.close() diff --git a/login.sh b/login.sh index 80a2968..647ef1f 100755 --- a/login.sh +++ b/login.sh @@ -1,5 +1,7 @@ #!/bin/sh . /etc/profile.d/apps-bin-path.sh +SLBRUSER="$(whoami)" +lxc list | grep -q "$(echo $SSH_CLIENT | cut -f 1 -d ' ')" && ~/killme.sh && exit #this is a bit hacky, maybe something better? echo "The game has not started yet! Grab a cup of tea, or just wait here." while test -z "$(cat /home/slbr/gamestatus)" || break do @@ -8,4 +10,8 @@ do done echo "READY.......BEGIN!" sleep 1 -lxc exec "$(whoami)" /usr/bin/tmuxinit.sh +echo "Setting up your container..." +lxc exec "$SLBRUSER" ssh-keygen -- -t rsa -N '' -f /root/.ssh/id_rsa +lxc file pull "$SLBRUSER/root/.ssh/id_rsa.pub" "/home/slbr/$SLBRUSER/pubkey.temp" +cat "/home/slbr/$SLBRUSER/pubkey.temp" >> "/home/slbr/$SLBRUSER/.ssh/authorized_keys" && rm "/home/slbr/$SLBRUSER/pubkey.temp" +lxc exec "$SLBRUSER" /usr/bin/tmuxinit.sh diff --git a/newuser.sh b/newuser.sh index 6bb1779..06880d9 100755 --- a/newuser.sh +++ b/newuser.sh @@ -12,16 +12,18 @@ mkdir "/home/slbr/$SLBRUSER" mkdir "/home/slbr/$SLBRUSER/.ssh" echo "Copying key..." echo "$PUBKEY" >> "/home/slbr/$SLBRUSER/.ssh/authorized_keys" -echo "$SLBRUSER" >> users.txt echo "Creating container..." echo "lxc exec $SLBRUSER bash" > "/home/slbr/$SLBRUSER/.profile" chmod -w "/home/slbr/$SLBRUSER/.profile" echo "Creating user..." sudo useradd "$SLBRUSER" -d "/home/slbr/$SLBRUSER" sudo usermod -a -G lxd "$SLBRUSER" +sudo cp ./killme.sh "/home/slbr/$SLBRUSER/killme.sh" +sudo chmod +x "/home/slbr/$SLBRUSER" sudo chown -R "$SLBRUSER:$SLBRUSER" "/home/slbr/$SLBRUSER" sudo chsh "$SLBRUSER" -s /home/slbr/login.sh echo "Generating user keypair..." sudo su "$SLBRUSER" -s /bin/sh -c "ssh-keygen -t rsa -N '' -f /home/slbr/$SLBRUSER/.ssh/id_rsa" echo "Initializing container..." sudo su "$SLBRUSER" -s /bin/sh -c "/home/slbr/lxcinit.sh" +echo "$SLBRUSER" >> users.txt diff --git a/suicidebash.bashrc b/suicidebash.bashrc index 2b99481..3c96ab5 100644 --- a/suicidebash.bashrc +++ b/suicidebash.bashrc @@ -54,7 +54,7 @@ if [ ! -e "$HOME/.sudo_as_admin_successful" ] && [ ! -e "$HOME/.hushlogin" ] ; t fi function command_not_found_handle { - echo "$(hostname) has been eliminated by '$1'" | nc -q2 test.tilde.team 9090 & + ssh testuser@10.123.168.1 echo "====YOU HAVE BEEN ELIMINATED====" sleep 2 } diff --git a/users.txt b/users.txt index 4db90f4..e69de29 100644 --- a/users.txt +++ b/users.txt @@ -1 +0,0 @@ -testuser