Changed death mechanics

This commit is contained in:
sose 2018-10-11 06:50:26 +02:00
parent 42b858105a
commit b7bbe1ccc6
8 changed files with 32 additions and 55 deletions

View File

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

View File

@ -0,0 +1 @@

16
killme.sh Executable file
View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1 +0,0 @@
testuser