Stocker is a medium difficulty Linux machine that features a website running on port 80 that advertises various house furniture. Through vHost enumeration the hostname dev.stocker.htb is identified and upon accessing it a login page is loaded that seems to be built with NodeJS . By sending JSON data and performing a NoSQL injection, the login page is bypassed and access to an e-shop is granted. Enumeration of this e-shop reveals that upon submitting a purchase order, a PDF is crafted that contains details about the items purchased. This functionality is vulnerable to HTML injection and can be abused to read system files through the usage of iframes. The index.js file is then read to acquire database credentials and owed to password re-use users can log into the system over SSH . Privileges can then be escalated by performing a path traversal attack on a command defined in the sudoers file, which contains a wildcard for executing JavaScript files.
# Nmap 7.92 scan initiated Wed Jan 1819:58:252023as: nmap -vvv -sC -sV -oN nmap/stocker 10.129.137.112 Increasing send delay for10.129.137.112from5to10 due to12outof39 dropped probes since last increase. Increasing send delay for10.129.137.112from10to20 due to11outof34 dropped probes since last increase. Nmap scan report for10.129.137.112 Host is up, received reset ttl 63 (0.14s latency). Scanned at2023-01-1819:58:28 IST for74s Not shown: 998 closed tcp ports (reset) PORT STATE SERVICE REASON VERSION 22/tcp open ssh syn-ack ttl 63 OpenSSH 8.2p1 Ubuntu 4ubuntu0.5 (Ubuntu Linux; protocol 2.0) | ssh-hostkey: |30723d:12:97:1d:86:bc:16:16:83:60:8f:4f:06:e6:d5:4e (RSA) | ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC/Jyuj3D7FuZQdudxWlH081Q6WkdTVz6G05mFSFpBpycfOrwuJpQ6oJV1I4J6UeXg+o5xHSm+ANLhYEI6T/JMnYSyEmVq/QVactDs9ixhi+j0R0rUrYYgteX7XuOT2g4ivyp1zKQP1uKYF2lGVnrcvX4a6ds4FS8mkM2o74qeZj6XfUiCYdPSVJmFjX/TgTzXYHt7kHj0vLtMG63sxXQDVLC5NwLs3VE61qD4KmhCfu+9viOBvA1ZID4Bmw8vgi0b5FfQASbtkylpRxdOEyUxGZ1dbcJzT+wGEhalvlQl9CirZLPMBn4YMC86okK/Kc0Wv+X/lC+4UehL//U3MkD9XF3yTmq+UVF/qJTrs9Y15lUOu3bJ9kpP9VDbA6NNGi1HdLyO4CbtifsWblmmoRWIr+U8B2wP/D9whWGwRJPBBwTJWZvxvZz3llRQhq/8Np0374iHWIEG+k9U9Am6rFKBgGlPUcf6Mg7w4AFLiFEQaQFRpEbf+xtS1YMLLqpg3qB0= |2567c:4d:1a:78:68:ce:12:00:df:49:10:37:f9:ad:17:4f (ECDSA) | ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBNgPXCNqX65/kNxcEEVPqpV7du+KsPJokAydK/wx1GqHpuUm3lLjMuLOnGFInSYGKlCK1MLtoCX6DjVwx6nWZ5w= |256 dd:97:80:50:a5:ba:cd:7d:55:e8:27:ed:28:fd:aa:3b (ED25519) |_ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIDyp1s8jG+rEbfeqAQbCqJw5+Y+T17PRzOcYd+W32hF 80/tcp open http syn-ack ttl 63 nginx 1.18.0 (Ubuntu) |_http-title: Did not follow redirect to http://stocker.htb | http-methods: |_ Supported Methods: OPTIONS Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
Read data files from: /usr/bin/../share/nmap Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . # Nmap done at Wed Jan 1819:59:422023-- 1 IP address (1 host up) scanned in 76.33 seconds
Web
Opening the site we see
Enumerating for directory i don’t find anything lets enumerate for domain and we find dev.stocker.htb
Opeing dev.stocker.htb we get
Looking at the login request we see it is an express app
So might be MEAN stack as we see express and angular (based on cookie) and header lets try some no-sql injection.
And Viola we get bypass authentication.
Stocks page
Placing an order we see we get a link to get the order invoice
and opening the link show us an pdf
We see Cup string to be present in the pdf
Trying LFI payload we are able to read local file.
{"basket":[{"_id":"638f116eeb060210cbd83a8d","title":"<iframe src='file:///var/www/dev/index.js' width='750px' height='750px'>","description":"It's a red cup.","image":"red-cup.jpg","price":32,"currentStock":4,"__v":0,"amount":1}]}
We get
In that lets try the mongoos credentail with the users we found.
Privileage Escalation
After getting shell as angoose
Running sudo -l we see we can run *.js script from /usr/local/scripts/*.js
Checking if we can write to /usr/local/scripts which we cannot, so lets do path traversal and go to a directory where we can write and run