DB-Owner
Configuring
Prerequisite
Normal domain user accessConfiguring
Login to
WEB01as theAdministratoruser with passwordWelcome01!.Open "Microsoft SQL Server Management Studio"

3. Login with the sa user using the password sa or Password1! (Depending if you changed it for another vulnerability)

4. Click “New Query” button and use the SQL query below to make Amsterdam\Richard database owner of the production database.

5. Change the Owner of the database to the SA account. Right click on "Production", click "Properties" and open the "Files" tab. Click on the "..." and fill in "sa" and click on "OK"

6. Execute the following query to make sure Amsterdam\Richard is Database owner and the real Owner of the database is sa:


7. Set the database as trustworthy and check if it is:


The 1 after Production shows us that the database is ThrustWorthy.
Attacking
How it works
If the database is set as trustworthy and we have db_owner privileges, we could elevate our privileges and execute queries as sa.
Tools
Executing attack
Login to
WS01as Richard with the passwordSample123.Download and start heidiSQL.
Click on "New" on the left bottom and configure the following settings:
Network Type:
Microsoft SQL Server (TCP/IP)Library:
SQLOLEDBHostname / IP:
WEB01.amsterdam.bank.localSelect: "Use Windows Authentication"
Port:
1433

4. Click "OK" on the security Issue warning.
Prerequisites
5. Click on the "Query" tab and enter the following Query to check if we are db_owner:

Our current user AMSTERDAM\richard is db_owner.
6. Check who is the owner of the database.

sa is the owner of the production database.
6. Check if the database is set to trustworthy

The Production database is trustworty.
Executing the attack
7. Create a stored procedure which will add AMSTERDAM\Richard as sysadmin.

8. Execute the stored procedure:

9. Check if we are sysadmin:

The 1 means that we are sysadmin! Check the executing commands page under SQL Server Attacks to read how to execute cmd commands:
Cleanup
Login to WEB01 as Administrator, start the "Microsoft SQL Server Management Studio" and login as Administrator.
Execute the following query:
Defending
Recommendations
Detection
References
Last updated