here we go with a new walktrougth of Hack The Box - Stocker Machine!
initial footprint
As usual, we started in a black-box mode, and we need to figure out what type of the server we have in front of us. Let’s start our loved tool nmap.
We starting collecting information about services, operating system, etc. As we add more knowledge about or target, we will add in our note.
service enumeration
Looking at the exposed services of the machine, two services capture our attention: port 80 and 9091: SSH port is a well-know and deep tested services so it’s very uncommon to discover vurlnerability in such kind of service.
We leave port 22 as last chance as usually it not provide much attack surface:
encrypted traffic
auth required
very common and test service
80/tcp open http nginx 1.18.0 (Ubuntu)
We can see from nmap service enumeration that a webservice is present at port TCP80 with the “Coming Soon” title. Let’s open our browser to see what is running on that port.
as we can read… the website is under development. Analizyng webpage source, no dynamic content is provided by webserver. Let’s continue the enumeration to see if we can find some hidden dev website/uri/pages.
pages/directory enumeration
vhosts enumeration
dir/pages enumeration
First step facing to a webserver is looking for webapplication mapping. Looking to the source code of the index page we cannot see any specific dynamic content, forms, etc. Let try to find other resources, backup files, dev files, etc.
We are gonna use gobuster with some well-know wordlists.
Unfortunatly dir/pages discovery didn’t provide more information on the system: just few static resources. Let’s continue in different way.
vhost enumeration
We didn’t find anything on stocker.htb website and we can suppose that dev website should be in different host/vhost where the nginx is gonna redirect our requests. Let’s use gobuster to enumerate vhosts
vhost enumeration give us a gift: new uri to be scanned dev.stocker.htb - let’s add it to our HOSTS files and continue the enumeration.
web application analisys
We found additional vhost where a web appication is still listen. Using a browser we can see if any known website/application is listening.
Looking at the cookies and using browser tools like wappalyzer we can try to identify the stack used by the application. We could be sure that is used nodejs.
Looking at the disclosed component we can “assume” or better we can try to make some hypothesis on the used application stack in terms of front-end, back-end and database. All the components belongs to what is common defined as MEAN architecture (Mongo, Express.js, Angular and Node.js).
So, let’s try some injection on the login form. Our goal is interact with the internal db to exfiltrate some data or in the best case to login to the webapp! We can start with a simple tool nosl-login-bypass.
The tool identify a possibility to bypass the authentication form using NoSQL Injection on username & password form field using a JSON payload. We can use multple way to exploit this vulnerability, but due the simplicity of the test we have to do, let’s use the developers tools on our browser.
Basically we have to inject json payload on the login function editing the request. Pay attention to set the correct “content type” and payload.
After the injection we are redirected to the main-page of the application!!!!
web application survey
After successully login we have ti start again enumerating additional things to undestand application functionality, input/output, control points, etc.
Application appear to be an ecommerce portal to insert items in a basket and place some orders. The functionalities of the application are:
add some items in the chart
view the cart of items in the basket
place on order/submitn a purchase
view the pdf receipt of the order
Probably the pdf generation function could be a possibile attack-vector: we can insert information from the stock to the pdf-file, we can recall the file from browser, etc.
PDF Generation Inject
After initial test we found that the field “title” is HTML inject-able… let’s tray to grab some useful infomation..
and the result…
Now, we are able to perfoem some LFI - we can try to enumerate and find more information about target appl
nginx.conf
Now we found a password and we got already a username (from passwd file)… let’s try some password reuse technics.
That’s means we can launch all the script with the path /usr/local/scripts/* using /usr/bin/node with root permissions!!
About
Luigi Vezzoso
Security professional with more than 15 year of experience in multiple aspects of cyber security - In my the spare time I like to train dogs.