| name | extracting-config-from-agent-tesla-rat |
| description | 从 Agent Tesla RAT 样本中提取嵌入的配置信息,包括 SMTP/FTP/Telegram 数据泄露凭据、键盘记录器设置和 C2 端点,使用 .NET 反编译和内存分析技术。 |
| domain | cybersecurity |
| subdomain | malware-analysis |
| tags | ["agent-tesla","rat","config-extraction","dotnet","malware-analysis","keylogger","credential-theft"] |
| version | 1.0 |
| author | mahipal |
| license | Apache-2.0 |
从 Agent Tesla RAT 中提取配置
概述
Agent Tesla 是一款基于 .NET 的远程访问木马(RAT)和键盘记录器,在 2024 年跻身十大恶意软件变种之列,影响全球 6.3% 的企业网络。它通过 SMTP 电子邮件、FTP 上传、Telegram Bot API 或 Discord Webhook 窃取凭据。恶意软件配置内嵌于 .NET 程序集中,通常使用字符串加密、资源加密或自定义加载器进行混淆,后者通过 .NET Reflection 在内存中解密并执行 Agent Tesla(无文件方式)。配置提取需要使用 dnSpy 或 ILSpy 反编译 .NET 程序集,识别配置字符串的解密例程,并提取 SMTP 服务器地址、凭据、FTP 端点、Telegram Bot Token 和目标应用程序。
前置条件
- dnSpy 或 ILSpy,用于 .NET 反编译
- Python 3.9+,带有
dnlib 或 pythonnet,用于自动化提取
- de4dot,用于 .NET 去混淆
- 理解 .NET IL 代码和 Reflection
- 沙箱环境,用于动态分析(ANY.RUN、CAPE)
操作步骤
步骤 1:去混淆并提取配置
"""从 .NET 程序集中提取 Agent Tesla RAT 配置。"""
import re
import sys
import json
import base64
import hashlib
from pathlib import Path
def extract_strings_from_dotnet(filepath):
"""从 .NET 二进制文件中提取可读字符串用于配置分析。"""
with open(filepath, 'rb') as f:
data = f.read()
strings = []
patterns = {
"smtp_server": re.compile(rb'smtp[\.\-][\w\.\-]+\.\w{2,}', re.I),
"email": re.compile(rb'[\w\.\-]+@[\w\.\-]+\.\w{2,}'),
"ftp_url": re.compile(rb'ftp://[\w\.\-:/]+', re.I),
"telegram_token": re.compile(rb'\d{8,10}:[A-Za-z0-9_-]{35}'),
"telegram_chat": re.compile(rb'(?:chat_id=|chatid[=:])[\-]?\d{5,15}', re.I),
"discord_webhook": re.compile(rb'https://discord\.com/api/webhooks/\d+/[\w-]+'),
"password": re.compile(rb'(?:pass(?:word)?|pwd)[=:]\s*[\w!@#$%^&*]{4,}', re.I),
"port": re.compile(rb'(?:port|smtp_port)[=:]\s*\d{2,5}', re.I),
}
results = {}
for name, pattern in patterns.items():
matches = pattern.findall(data)
matches:
results[name] = [m.decode(, errors=) m matches]
b64_pattern = re.()
b64_decoded = []
b64_pattern.finditer(data):
:
decoded = base64.b64decode(.group())
text = decoded.decode(, errors=)
text.isprintable() (text) > :
b64_decoded.append(text)
Exception:
b64_decoded:
results[] = b64_decoded[:]
results
():
key = .fromhex(key_hex)
decrypted_strings = []
blob_pattern = re.()
blob_pattern.finditer(data):
blob = .group()
decrypted = (b ^ key[i % (key)] i, b (blob))
:
text = decrypted.decode(, errors=)
text.isprintable() (text.strip()) > :
decrypted_strings.append(text.strip())
UnicodeDecodeError:
sha256_key = hashlib.sha256(key).digest()
decrypted_strings
():
methods = []
config.get():
methods.append({
: ,
: config[],
: config.get(, []),
})
config.get():
methods.append({
: ,
: config[],
})
config.get():
methods.append({
: ,
: config[],
: config.get(, []),
})
config.get():
methods.append({
: ,
: config[],
})
methods
__name__ == :
(sys.argv) < :
()
sys.exit()
config = extract_strings_from_dotnet(sys.argv[])
methods = analyze_exfiltration_config(config)
report = {: config, : methods}
(json.dumps(report, indent=))
验证标准
- 已识别数据泄露方式(SMTP/FTP/Telegram/Discord)
- 已从配置中提取服务器地址和凭据
- 已恢复目标应用程序列表
- 已记录键盘记录器和截屏功能设置
- 已识别持久化机制
- 已提取适合网络封锁的 IoC
参考资料