In this writeup I will show you how to escape from vm2 sandbox. Then we will get the RCE on the server, find the database and extract the credentials from it. And to increase privileges, we have to exploit the vulnerability in a user script in Bash.
Our goal is to obtain superuser rights on the Codify machine from the training site Hack The Box. The difficulty level of the car is easy.
warning
It is recommended to connect to machines with HTB only via VPN. Do not do this from computers that contain data that is important to you, as you will end up on a shared network with other participants.
Intelligence service
Port scanning
Add the machine's IP address to /:
И запускаем сканирование портов.
Справка: сканирование портов
Сканирование портов — стандартный первый шаг при любой атаке. Он позволяет атакующему узнать, какие службы на хосте принимают соединение. На основе этой информации выбирается следующий шаг к получению точки входа.
Наиболее известный инструмент для сканирования — это Nmap. Улучшить результаты его работы ты можешь при помощи следующего скрипта:
#!/bin/bash
ports=$(nmap -p- --min-rate=500 $1 | grep ^(0-9) | cut -d '/' -f 1 | tr 'n' ',' | sed s/,$//)
nmap -p$ports -A $1
It works in two stages. The first one performs a regular quick scan, the second one performs a more thorough scan using the available scripts (option -A).
The scanner found three open ports:
- port 22 - OpenSSH 8.9p1 service;
- port 80 - Apache web server 2.4.52;
- port 3000 - Node.js Express application.
Based on the list of open ports, it is clear that in order to gain access to the server, you need to find and exploit a vulnerability on the site (it is not accepted to brute force the SSH password on HTB).

The site allows you to test Node.js code in an isolated environment directly on the site.

Point of entry
The About us page has information about the code editor. It uses a JavaScript sandbox for execution vm2.

The link on the site does not lead to the latest version of the vm2 library, but to version 3.9.16, which is probably used on the server.