initial commit

This commit is contained in:
Pin
2022-12-20 22:15:44 -05:00
commit 9a0c74b701
7 changed files with 104 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
.env
keys/

11
client/Dockerfile Normal file
View File

@@ -0,0 +1,11 @@
FROM alpine:3.16
RUN apk --no-cache add openrc openssh bash && \
ssh-keygen -A && \
mkdir -p /run/openrc && \
touch /run/openrc/softlevel
COPY scripts /opt/scripts
RUN chmod 700 /opt/scripts
ENTRYPOINT ["/opt/scripts/setup.sh"]

25
client/scripts/setup.sh Executable file
View File

@@ -0,0 +1,25 @@
#!/bin/bash
TEAM_NUM=${TEAM_NUM:=10}
for (( i=1; i<=TEAM_NUM; i++ )); do
echo "Creating Team ${i}"
adduser -D "team${i}"
chmod 750 "/home/team${i}"
PASSWORD="TEAM${i}_PASSWORD"
if [[ -z "${!PASSWORD}" ]]; then
PASSWORD=$(head -c10 </dev/urandom | base64)
else
PASSWORD=${!PASSWORD}
fi
echo -e "Password: ${PASSWORD}\n"
echo -e "${PASSWORD}\n${PASSWORD}" | passwd "team${i}"
unset PASSWORD
done
if [[ -n "${SSHD_CHALLENGE_DIR}" ]]; then
sed -i "s|^AuthorizedKeysFile.*|AuthorizedKeysFile ${SSHD_CHALLENGE_DIR}|" /etc/ssh/sshd_config
fi
/usr/sbin/sshd -D

7
controller/Dockerfile Normal file
View File

@@ -0,0 +1,7 @@
FROM alpine:3.16
RUN apk --no-cache add openssh-client bash
COPY scripts /opt/scripts
ENTRYPOINT ["sh", "-c", "/opt/scripts/init.sh"]

10
controller/scripts/gen_keys.sh Executable file
View File

@@ -0,0 +1,10 @@
#!/bin/bash
TEAM_NUM=${TEAM_NUM:=10}
for (( i=1; i<=TEAM_NUM; i++ )); do
if [[ ! -e "${HOME}/.ssh/team-${i}" ]]; then
ssh-keygen -q -t ed25519 -N '' -f "${HOME}/.ssh/team-${i}" -C "team${i}"
fi
done

27
controller/scripts/init.sh Executable file
View File

@@ -0,0 +1,27 @@
#!/bin/bash
SCORING_POD=${SCORING_POD:=client}
TEAM_NUM=${TEAM_NUM:=10}
echo "Generating scoring details"
/opt/scripts/gen_keys.sh
echo "Scoring Details"
cat /root/.ssh/*.pub
while true; do
echo "Testing Scoring"
for (( i=1; i<=${TEAM_NUM}; i++ )); do
echo "Testing Team ${i}"
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no "team${i}@${SCORING_POD}" -i "/root/.ssh/team-${i}" \
'echo "flag" >.flag'
done
sleep 30
done

21
docker-compose.yml Normal file
View File

@@ -0,0 +1,21 @@
---
version: "3.9"
services:
client:
image: local/c2games-client:latest
build:
context: ./client
environment:
TEAM_NUM: 5
SSHD_CHALLENGE_DIR: .ssh/auth_keys
controller:
image: local/c2games-controller:latest
build:
context: ./controller
environment:
TEAM_NUM: 5
volumes:
- "${PWD}/keys:/root/.ssh"
...