HW1

My personal ID : 108

  • Your machine should boot using UEFI (5%)
  • Set hostname to sa2024-${ID} (5%)
hostnamectl set-hostname sa2024-108
  • Create user (25%)
    • Should be a member of wheel group (or sudo on Ubuntu)
    • Should be able to execute sudo commands without entering password (15%)
    • Should use sh as the default shell (10%)
    • You should use this user instead of root for subsequent operations
sudo adduser judge
sudo usermod -aG sudo judge

sudo visudo
# add below line into the config file
# judge ALL=(ALL) NOPASSWD: ALL

sudo chsh    -s /bin/sh judge  # Method 1
sudo usermod -s /bin/sh judge  # Method 2

# testing
su - judge
whoami
echo $0
groups judge
  • Create group (10%)
    • Create a group nycusa (5%)
    • Add judge user to this group (5%)
sudo addgroup nycusa
sudo adduser judge nycusa
  • Set your machine to Taiwan Standard Time (10%)
timedatectl
  • Secure Shell (15%)
    • Enable sshd
    • Install public key to your /home/judge/.ssh for Online Judge
    • Verify the fingerprint of public key
sudo systemctl status ssh
# sudo systemctl enable ssh
# sudo systemctl start ssh

wget https://nasa.cs.nycu.edu.tw/sa/2024/nasakey.pub
cat nasakey.pub >> /home/judge/.ssh/authorized_keys

ssh-keygen -l -f ./nasakey.pub
# 256 SHA256:l2xVg+C+hMjMldX6htc4SUPE5taFsxKkevTgiGmpeHA judge@sa-2024 (ED25519)
sudo vim /etc/ssh/sshd_config
# passwordAuthentication no
sudo systemctl restart ssh
  • Edit motd to show “NYCU-SA-2024-${Student ID}” (5%)
sudo vim /etc/motd
# NYCU-SA-2024-108
  • Configure your package manager to use CSIT mirror (10%)
# https://it.cs.nycu.edu.tw/equipment-linux-mirror
# https://ubuntu.cs.nycu.edu.tw/ubuntu/

# optional
# sudo cp ubuntu.sources ubuntu.sources.backup

sudo vim /etc/apt/sources.list.d/ubuntu.sources
sudo apt update
sudo apt upgrade
  • Online Judge servers can ping your system (15%)
sudo apt install wireguard
vim /etc/wireguard/wg0.conf
wg-quick up   wg0
wg-quick down wg0

ping -c 3 10.113.108.254

scp command

scp wg0.conf judge@192.168.50.246:/home/judge/Downloads

HW2

code

  • Usage (20%)
    • Invalid options (10%)
      • Exit Code (5%)
      • Help Message (5%)
    • Invalid type (5%)
    • Task type validation (5%)
  • Arbitrary argument position (15%)
  • Shellcheck (10%)
  • Tasks
    • Join NYCU CSIT (15%)
    • Math Solver (20%)
      • Invalid problem check is included
    • Crack Password (20%)
      • Invalid problem check is included
  • Bonus: Easter egg collection (5%)

Example

MATH_SOLVER
root@sa2024-108:/home/judge# curl -s -X POST -H "Content-Type: application/json" -d '{"type": "MATH_SOLVER"}' "http://10.113.0.253/tasks"
{
    "id":"04f0cd75-7e2d-4b61-83c2-8bca5f320d3c",
    "type":"MATH_SOLVER",
    "problem":"3172 - 5396 = ?",
    "status":"PENDING"
}

root@sa2024-108:/home/judge# curl -s -X POST -H "Content-Type: application/json" -d '{"answer": "-2224"}' "http://10.113.0.253/tasks/04f0cd75-7e2d-4b61-83c2-8bca5f320d3c/submit"

root@sa2024-108:/home/judge# curl -s -X GET "http://10.113.0.253/tasks/04f0cd75-7e2d-4b61-83c2-8bca5f320d3c"
{
    "id":"04f0cd75-7e2d-4b61-83c2-8bca5f320d3c",
    "type":"MATH_SOLVER",
    "problem":"3172 - 5396 = ?",
    "status":"TIMEOUT"
}

Note: Problem : a (+/-) b = c

-10000 <= a <= 10000
-10000 <= b <= 10000
-20000 <= c <= 20000

Add and subtract only, you don’t need to consider other conditions. If you get a problem not obey the above definition, just send “Invalid problem” to the task server.

JOIN_NYCU_CSIT
root@sa2024-108:/home/judge# curl -s -X POST -H "Content-Type: application/json" -d '{"type": "JOIN_NYCU_CSIT"}' "http://10.113.0.253/tasks"
{
    “id”: “4a9c99f4-0241-4f3d-a003-7b2f6bb455db”,
    “type”: “JOIN_NYCU_CSIT”,
    “status”: “PENDING”,
    “problem”: “https://i.imgur.com/wP3ST2x.jpeg”
}

root@sa2024-108:/home/judge# curl -s -X POST -H "Content-Type: application/json" -d '{"answer": "I Love NYCU CSIT"}' "http://10.113.0.253/tasks/4a9c99f4-0241-4f3d-a003-7b2f6bb455db/submit"
CRACK_PASSWORD
root@sa2024-108:/home/judge# curl -s -X POST -H "Content-Type: application/json" -d '{"type": "CRACK_PASSWORD"}' "http://10.113.0.253/tasks"
{
    “id”: “9d2cde78-837c-4e72-bc9d-4f7204b5520e”,
    “type”: “CRACK_PASSWORD”,
    “status”: “PENDING”,
    “problem”: “ALPHANFN{QfLWrLExdqgSufIi}}

root@sa2024-108:/home/judge# curl -s -X POST -H "Content-Type: application/json" -d '{“answer”: “NYCUNASA{DsYJeYRkqdtFhsVv}”}' "http://10.113.0.253/tasks/9d2cde78-837c-4e72-bc9d-4f7204b5520e/submit"