© 2018 Caendra Inc. - Hera For Ptpv5 - Linux Exploitation (Remote Exploitation & Post-Exploitation)
© 2018 Caendra Inc. - Hera For Ptpv5 - Linux Exploitation (Remote Exploitation & Post-Exploitation)
1. Netblock: 172.16.80.1/24
2. Domain: robotstogo.localdomain
© 2018 Caendra Inc. | Hera for PTPv5 | Linux Exploitation (Remote Exploitation 2
& Post-Exploitation)
• Metasploit
• Nmap
• Bash Shell
• Netcat
On which port was the backdoor discovered, what user is the backdoor running
under, and what method was used to obtain root-level access as that user?
Of the users discovered via SMB enumeration, obtain access to 172.16.80.27 via SSH
using one of them. Once access has been obtained with that user account, elevate
privileges to root. Write your findings below.
© 2018 Caendra Inc. | Hera for PTPv5 | Linux Exploitation (Remote Exploitation 3
& Post-Exploitation)
Of the available SMB shares discovered during the enumeration of 172.16.80.27, one
of them can be exploited to obtain access to the server. Exploit this finding to obtain
access to 172.16.80.27 and describe your method below:
© 2018 Caendra Inc. | Hera for PTPv5 | Linux Exploitation (Remote Exploitation 4
& Post-Exploitation)
© 2018 Caendra Inc. | Hera for PTPv5 | Linux Exploitation (Remote Exploitation 5
& Post-Exploitation)
Below, you can find solutions for each task for the Remote Exploitation and Post-
Exploitation tasks. Remember though that you can follow your own strategy (which may
be different from the one explained in the following lab). Additionally, the labs contain
additional vulnerabilities not covered below which can also be exploited but may not
necessarily be required to complete the tasks below. Exploit as many of the vulnerabilities
you find!
Using Nmap during our enumeration phase and while conducting a SYN scan for all 65535
ports, we should have discovered a port listening on 60666 on 172.16.80.27:
Using netcat (nc), when connecting to the 60666 port, we notice that the system is opening
up another port (60667). While leaving that connection open, in another terminal, we netcat
the newly opened 60667 port and find we are connected to a bind shell, and can execute
commands as a user “Jordan”:
© 2018 Caendra Inc. | Hera for PTPv5 | Linux Exploitation (Remote Exploitation 6
& Post-Exploitation)
We can then upgrade our shell using a python shell upgrade one-liner:
Now after conducting some simple enumeration, we find that “Jordan” has the ability to sudo
as root the nano editor for a certain file (readme.txt) in /home/*/*/readme.txt:
$ sudo -l
Seeing as the sudo command is requiring that a file called “readme.txt” be created in a
subdirectory of jordans home directory, we can create the subdirectory, but instead of
creating a “readme.txt” file, we’ll create a symbolic link from “readme.txt” to the
/etc/shadow file:
Listing the directory shows we’ve created a symbolic link to the /etc/shadow file, as the
“Readme.txt” file:
© 2018 Caendra Inc. | Hera for PTPv5 | Linux Exploitation (Remote Exploitation 7
& Post-Exploitation)
Once this is done, we can sudo the nano program to read the readme.txt file, which should
display the /etc/shadow file, but we notice that a proper terminal hasn’t been exported to
the users’ TERM environment variable:
We first need to add an environment variable for “TERM” to use xterm with the following
command:
$ export TERM=xterm
Once we’ve defined the TERM environment variable, we can then read the readme.txt file
(which is a symbolic link to the privileged /etc/shadow file):
In addition to the above explanation, the above Nano Wildcard Directory Symlink
vulnerability can be exploited in multiple ways to gain root to the system. Use your
imagination and see what other ways you can exploit it for a root shell!
© 2018 Caendra Inc. | Hera for PTPv5 | Linux Exploitation (Remote Exploitation 8
& Post-Exploitation)
During enumeration phases, and using enum4linux against 172.16.80.27, we should have
obtained a user list:
# enum4linux -a 172.16.80.27
Of the users discovered, we find that we can execute a dictionary attack using the first 500
entries of the rockyou.txt wordlist and are able to crack the password for the “james” user.
Create a password list of 500 entries from the rockyou.txt wordlist file, and save it to another
file:
© 2018 Caendra Inc. | Hera for PTPv5 | Linux Exploitation (Remote Exploitation 9
& Post-Exploitation)
Execute a hydra attack against the SSH port on 172.16.80.27 for the james user (or all of the
users discovered), when complete, you should be able to crack the password for james on
the 172.16.80.27 machine:
Using the password, we SSH to 172.16.80.27 as james, and after conducting some local
enumeration, find that james can sudo the “/usr/sbin/tcpdump” command. James’ sudo
entry is provided to us once we issue the “sudo -l” command, and enter his password, which
we previously obtained via the SSH dictionary attack:
Some basic research on using “tcpdump” to elevate our privileges when it is defined as a
sudo entry for a user reveals that we can take the following steps to obtain root: (tcpdump
allows for execution of arbitrary commands with a specially constructed command-line)
1. Write a file to /tmp, in this case, we’ll call the file “elevate,” with the following
contents:
#!/bin/bash
echo “james ALL=(root) NOPASSWD: ALL” >> /etc/sudoers
We can use the cat command to redirect our contents to the /tmp/elevate file like so:
© 2018 Caendra Inc. | Hera for PTPv5 | Linux Exploitation (Remote Exploitation 10
& Post-Exploitation)
2. We then set the executable bit for our /tmp/elevate file:
$ chmod +x /tmp/elevate
The above tcpdump command, as sudo (root), along with our “elevate” file, will write a new
entry to the /etc/sudoers file for james, whose shell can then be immediately upgraded to
root with a “sudo bash” command:
$ sudo bash
# id
uid=0(root) gid=0(root) groups=0(root)
# smbmap -H 172.16.80.27
© 2018 Caendra Inc. | Hera for PTPv5 | Linux Exploitation (Remote Exploitation 11
& Post-Exploitation)
We also find that anonymous access is allowed to the share using Nmap with the “smb-enum-
shares” script:
Having this information, we use smbclient to connect to the share while providing no
password and blank user (anonymous access), and list the shares contents:
# smbclient -N \\\\172.16.80.27\\web -U “”
smb: \> ls
info.pl A 283 Sat Jan 20 01:46:57 2018
© 2018 Caendra Inc. | Hera for PTPv5 | Linux Exploitation (Remote Exploitation 12
& Post-Exploitation)
Upload the perl-reverse-shell.pl file to the “web” share using smbclient:
# nc -nlvp 1234
© 2018 Caendra Inc. | Hera for PTPv5 | Linux Exploitation (Remote Exploitation 13
& Post-Exploitation)
During enumeration of the systems for vulnerabilities and having conducted a port scan for
all ports, we find that “172.16.80.22” contains an RMI Registry service listening on a non-
standard port of 1999. Research on RMI Registry of the particular version found finds that it
is vulnerable to arbitrary loading of java classes.
We can then once again, use the python tty spawn one-liner to get a proper shell on the
system and check our current kernel version with the “uname -a” command:
© 2018 Caendra Inc. | Hera for PTPv5 | Linux Exploitation (Remote Exploitation 14
& Post-Exploitation)
$ python -c ‘import pty; pty.spawn(“/bin/bash”)’
Our kernel version shows that the system is running an older kernel version of “2.6.24-16.”
We check exploit-db for vulnerabilities related to that kernel version 2.6, and find that it is
potentially vulnerable to a “udev” exploit, among others:
https://www.exploit-db.com/exploits/21848/
There is a Metasploit module available for this particular kernel exploit, so let’s load that
exploit and set it up for our current meterpreter session:
First, we send our current session into the background with “Ctrl-Z,” then type “background”:
We then search for the udev exploit, and load the available exploit module:
© 2018 Caendra Inc. | Hera for PTPv5 | Linux Exploitation (Remote Exploitation 15
& Post-Exploitation)
# msf > use exploit/linux/local/udev_netlink
We then set our SESSION value to the current meterpreter session and set your LHOST:
During post-exploitation of the machine “172.16.80.22” once we had gotten access as the
user “todd” via the udev kernel exploit, we should have determined the version of Samba on
the system with the following command to check for an exploitable Samba version:
© 2018 Caendra Inc. | Hera for PTPv5 | Linux Exploitation (Remote Exploitation 16
& Post-Exploitation)
$ smbd --version
Version 3.0.20-Debian
After conducting additional enumeration as user “todd” of the Samba configuration in file
“/etc/samba/smb.conf,” we find that it is configured with an option that allows reading of
the root file system via a Symlink Directory Traversal Vulnerability, specifically, the “wide
links = yes” option.
Knowing this information, we can use the Metasploit Module “samba_symlink_traversal” and
try and see if we can read the /root/ filesystem once we run the module:
© 2018 Caendra Inc. | Hera for PTPv5 | Linux Exploitation (Remote Exploitation 17
& Post-Exploitation)
We can now use smbclient to mount the “tmp” directory, and change into the “rootfs”
directory:
# smbclient -N \\\\172.16.80.22\\tmp -U “”
# smb: \> cd rootfs
# smb: \rootfs\> ls
From here, it is trivial to read the root file system, and download files that we may want to
conduct addition post-exploitation information gathering on:
© 2018 Caendra Inc. | Hera for PTPv5 | Linux Exploitation (Remote Exploitation 18
& Post-Exploitation)
During information gathering we determine that the system at IP address 172.16.80.22 is
running a web server on TCP port 80:
The scan quickly uncovers the existence of a “calendar.cgi” program in the “cgi-bin”
directory:
© 2018 Caendra Inc. | Hera for PTPv5 | Linux Exploitation (Remote Exploitation 19
& Post-Exploitation)
Knowing that CGI programs, in particular, are of primary concern in regards to shellshock
vulnerabilities, we use Metasploit’s “apache_mod_cgi_bash_env” module to check for
exploitability, making sure to configure the correct options, including the TARGETURI value:
The server returns the output of the “id” command, which confirms that the exploit (with its
default CMD value of “id”) was successful:
We exploit this, to obtain a reverse shell as the “www-data” user by modifying the “CMD”
value in the Metasploit module to execute a netcat reverse shell back to our attacker system
where we have a netcat listener running.
Now we make sure we have a netcat listener running on our attacker machine:
# nc -nlvp 1234
We then run the shellshock exploit module and should receive a reverse shell back to our
attacker system, and we can see we are the “www-data” user at this point by running the “id”
command to confirm:
© 2018 Caendra Inc. | Hera for PTPv5 | Linux Exploitation (Remote Exploitation 20
& Post-Exploitation)
We upgrade our shell with python, as we have done previously with other tasks:
We can then conduct some post-exploitation enumeration and find a way to obtain root
privileges. We do so, and find that “nmap” is configured as a SUID root executable, and
furthermore, we determine that it allows the “--interactive” mode which as we know, can
give us a root shell if nmap is SUID root:
We run nmap with “--interactive” mode switch to escape to a shell, and escalate our
privileges to that of Effective User ID (EUID) “root”:
© 2018 Caendra Inc. | Hera for PTPv5 | Linux Exploitation (Remote Exploitation 21
& Post-Exploitation)
Once again, we are root!
© 2018 Caendra Inc. | Hera for PTPv5 | Linux Exploitation (Remote Exploitation 22
& Post-Exploitation)