Basically if you’re admin you own everything.
So how would you access an SQL-Server if you don’t have SQL-Permissions but you’re administrator on the system the SQL-server is running on?
Basically you can abuse the fact, that the sql-server has to have at least one account with the necessary permissions. Often this is the local system user.
- So just become system using psexec (or anything else): psexec -s cmd.exe
- Search for your local SQL-Instance: osql -L
- Connect to your SQL-Server using your current (system) credentials: osql -S <InstanceName> -E
- If the connection is successful, just enable the sa account and set a new password for it. After that you can use the SQL-Management Studio to administer all permissions:
/* Enable SQL-User authentication and set sa password */ ALTER LOGIN sa ENABLE; GO /* Reset the password, requires CONTROL SERVER permission */ ALTER LOGIN sa WITH PASSWORD = '<newPassword>'; GO /* just set sa password (alternative way)*/ sp_password NULL, '<newPassword>', 'sa'; GO /* To add an windows user to the admins role do this */ CREATE LOGIN [DOMAIN\USER] FROM WINDOWS; GO EXEC sp_addsrvrolemember 'DOMAIN\USER', 'sysadmin'; GO
If the above is throwing an access denied error for you try a different user for example the mssql service user use process hacker to run a cmd prompt in the context of that user and try again. If also that fails, check if there is any application accessing the database that could have an account with too much permissions e. g. Server Admin instead of db_owner and try that one.
- If that all does not help, you have one last way of getting into the database, but that causes a downtime.
- Stop your SQL-Server Services (Server, Browser, Agent, …) and open an elevated cmd.
- Navigate to the folder containing the executable of the service and start it with the parameter “-m” for single user mode without authentication. After the server is back up do Step 4 and after that stop the server and restart the services you stopped earlier.
WARNING: BY DOING STEP 7 EVERYBODY COULD GAIN FULL ACCESS TO YOUR SERVER, DEPENDING ON YOUR INFRASTRUCTURE YOU MAY WANT TO BLOCK REMOTE CONNECTIONS ON THE WINDOWS FIREWALL WHILE PERFORMING THIS STEP
7 thoughts on “Hacking an SQL-Server”
Very good blog you have here but I was curious about if you knew of any message boards that cover the same topics discussed here? I’d really like to be a part of group where I can get suggestions from other knowledgeable people that share the same interest. If you have any suggestions, please let me know. Kudos!
There are hacking related message boards, but I’m not gonna share links in reply to such questions.
Many of these boards do not differentiate between legal and illegal (and the definition also changes by country you’re in), therefore just search for IT Security and you should find plenty of them.
If you really want to go into it, Twitter is a very good start.
It’s a shame you don’t have a donate button! I’d certainly donate to this outstanding blog! I guess for now i’ll settle for bookmarking and adding your RSS feed to my Google account. I look forward to brand new updates and will talk about this site with my Facebook group. Talk soon!
Nice post. I was checking constantly this blog and I am impressed!
Very helpful information specially the last part 🙂 I care for such info much.
I was looking for this certain info for a long time. Thank you
and good luck.
Pretty nice post. I simply stumbled upon your blog and wanted
to mention that I have truly loved browsing your weblog posts.
After all I will be subscribing in your rss feed and I am hoping you write again very soon!
These are truly wonderful ideas in about blogging.
You have touched some good factors here. Any way keep up wrinting.