From 9d59aabe4b1686f09e6a03acc7ba4ee6fd1c69b9 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Tue, 21 Feb 2023 13:22:08 +0100 Subject: [PATCH] Introducing new IP for students and a new tool to display them --- challenge.yml | 3 +++ pkg/challenge/my_ips.sh | 44 +++++++++++++++++++++++++++++++++++++++++ token-validator/ip.go | 4 ++-- 3 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 pkg/challenge/my_ips.sh diff --git a/challenge.yml b/challenge.yml index 5c665a7..1fe3009 100644 --- a/challenge.yml +++ b/challenge.yml @@ -106,6 +106,9 @@ files: - path: bin/progression source: pkg/challenge/progression.sh mode: "0755" + - path: bin/my_ips + source: pkg/challenge/my_ips.sh + mode: "0755" - path: bin/wg-adlin contents: | #!/bin/sh diff --git a/pkg/challenge/my_ips.sh b/pkg/challenge/my_ips.sh new file mode 100644 index 0000000..34cbc8c --- /dev/null +++ b/pkg/challenge/my_ips.sh @@ -0,0 +1,44 @@ +#!/bin/sh + +# /proc/cmdline parser (from Gentoo Wiki) +cmdline() { + local value + value=" $(cat /proc/cmdline) " + value="${value##* $1=}" + value="${value%% *}" + [ "$value" != "" ] && echo "$value" +} + +IPS=$(curl -s -f "http://172.23.0.1/api/students/$(cmdline adlin.login)/ips") + +if [ $? -ne 0 ] +then + echo -e "Utilisez l'IP \e[01m$(cmdline adlin.ip)\e[0m pour vous connecter au réseau." +else + echo "Voici la liste des IP qui vous ont été attribuées :" + for KEY in vlan0 wg0 vlan7 + do + [ $(echo "${IPS}" | jq -r ".${KEY}") != "null" ] && { + echo -en " - \e[01m" + case $KEY in + vlan0) echo -n "Services Router";; + wg0) echo -n "VPN";; + vlan7) echo -n "Internet Router";; + *) echo -n "Autre IP";; + esac + echo -en " :\e[0m " + echo "${IPS}" | jq -r ".${KEY}" + } + done + + [ $# -gt 0 ] && [ "$1" == "-a" ] && { + INFOS=$(curl -s -f "http://172.23.0.1/api/students/$(cmdline adlin.login)/") + + echo + echo -e "La MAC bénéficiant d'une protection est \e[01m$(echo "${IPS}" | jq -r .mac)\e[0m" + } +fi + +echo +echo -e "\e[41;33;01m /!\\ \e[0m Attention à bien préciser la plage indiquée dans la topologie !" +echo diff --git a/token-validator/ip.go b/token-validator/ip.go index 206f526..56e460f 100644 --- a/token-validator/ip.go +++ b/token-validator/ip.go @@ -70,8 +70,8 @@ func GetStudentTunnelIPs(student *adlin.Student) (ips []string) { func getStudentIPs(student *adlin.Student) (r map[string]string) { r = make(map[string]string) - r["vlan0"] = IPSuffix(student, net.IPNet{IP: net.ParseIP("172.23.0.0"), Mask: net.CIDRMask(17, 32)}).String() - r["wg0"] = IPSuffix(student, net.IPNet{IP: net.ParseIP("172.17.0.0"), Mask: net.CIDRMask(16, 32)}).String() + r["vlan0"] = IPSuffix(student, net.IPNet{IP: net.ParseIP("172.23.12.0"), Mask: net.CIDRMask(17, 32)}).String() + r["wg0"] = IPSuffix(student, net.IPNet{IP: net.ParseIP("172.17.12.0"), Mask: net.CIDRMask(16, 32)}).String() r["vlan7"] = IPSuffix(student, net.IPNet{IP: net.ParseIP("172.23.142.0"), Mask: net.CIDRMask(23, 32)}).String() for d, ip := range GetStudentTunnelIPs(student) {