# 多态代码

**多态代码**是在执行过程中改变其运行时特征码的软件：每次运行，代码都会变异为自身的不同版本，而实现与原版相同的目的。在恶意软件中，这一特性可击败基于特征码的防御手段，如依赖稳定字节模式识别已知威胁的杀毒与反恶意软件工具。[MITRE ATT&CK](https://www.edgepedia.org/zh/mitre-att-and-ck) 将该技术编目为 T1027.014“多态代码”，属“隐蔽”战术下“混淆文件或信息”的子技术，适用于 Linux、Windows 和 macOS。<sup>[1](https://attack.mitre.org/techniques/T1027/014/)</sup>

| 关键事实 | 详情 |
|---|---|
| 定义 | 每次执行时变异为自身的不同版本，同时实现相同目标，从而规避基于特征码的检测<sup>[1](https://attack.mitre.org/techniques/T1027/014/)</sup> |
| 首次出现 | 首批多态病毒出现于1990年：变色龙家族（1260、V2P1、V2P2 和 V2P6），作者为马克·沃什伯恩（Mark Washburn）<sup>[2](https://encyclopedia.kaspersky.com/knowledge/year-1990/)</sup> |
| 首个变异引擎 | 变异引擎（MtE）由病毒作者“黑暗复仇者”（Dark Avenger）于1991年发布，是首个多态生成器<sup>[3](https://people.ece.ubc.ca/irenek/techpaps/virus/virusf.html)</sup> |
| 对抗措施里程碑 | 尤金·卡巴斯基（Eugene Kaspersky）于1992年开发的处理器模拟器可破译多态代码，此后成为杀毒程序不可或缺的属性<sup>[2](https://encyclopedia.kaspersky.com/knowledge/year-1990/)</sup> |
| 现代 ATT&CK 条目 | T1027.014，创建于2024年9月27日，检测策略 DET0324 涵盖哈希、熵和内存段变化<sup>[1](https://attack.mitre.org/techniques/T1027/014/)</sup><sup> • </sup><sup>[4](https://attack.mitre.org/detectionstrategies/DET0324/)</sup> |

## 工作原理

多态程序将一个不变的有效载荷与一个可变的外壳配对。在经典病毒设计中，病毒体被加密，解密例程置于病毒开头。每次感染时，代码以不同密钥进行可变加密，解密器本身也以不同形式重写。简单加密技术、可变密钥加密与解密代码交替的组合，使得通过扫描字符串——早期扫描器使用的固定字节序列——进行检测几乎不可能。<sup>[3](https://people.ece.ubc.ca/irenek/techpaps/virus/virusf.html)</sup>

变异由**多态引擎**产生，该组件在恶意软件每次自我复制时生成新的解密器和加密例程。当病毒使用此类引擎将自身写入文件时，引擎的加密器会修改病毒代码，使每个副本携带从大量方案中选择的不同加解密方案。<sup>[6](https://www.researchgate.net/publication/329327300_A_study_of_polymorphic_virus_detection)</sup>其结果，正如微软《安全情报报告》所描述，是功能相同但在文件大小、内容或其他方面彼此不同的恶意软件文件。<sup>[7](https://download.microsoft.com/download/8/1/B/81B3A25C-95A1-4BCD-88A4-2D3D0406CDEF/Microsoft_Security_Intelligence_Report_volume_9_Battling_Botnets_English.pdf)</sup>

该方法存在已知弱点。由于加密的病毒体不变，代码必须在运行时解密到内存中，安全研究人员可在此检测并标记它。<sup>[8](https://onlinelibrary.wiley.com/doi/10.1155/2023/8227751)</sup>早期混淆方案还受困于代际间病毒大小不变、以扫描器可针对的方式附加或前置到宿主文件，以及相似代码段使病毒暴露于熵分析等问题。<sup>[8](https://onlinelibrary.wiley.com/doi/10.1155/2023/8227751)</sup>

## 历史

首批多态病毒于1990年出现，即变色龙家族，包括1260、V2P1、V2P2 和 V2P6。作者马克·沃什伯恩以一本关于维也纳病毒的书为基础，并加入了自编码瀑布病毒的特性。与瀑布不同，[变色龙](https://www.edgepedia.org/zh/chameleon)不仅加密，而且每次感染都改变其代码，这一特性使当时的杀毒程序形同虚设，因为它们依赖搜索已知病毒代码片段。杀毒开发者以识别多态病毒的特殊算法作为回应。<sup>[2](https://encyclopedia.kaspersky.com/knowledge/year-1990/)</sup>1260病毒通常被认为是首个已知的多态病毒，为采用各种加解密技术的更复杂设计铺平了道路。<sup>[9](https://repository.royalholloway.ac.uk/items/bde3a9fe-51c0-a19a-e04d-b324c0926a4a/1/RHUL-MA-2008-02.pdf)</sup>

下一个里程碑是变异引擎（MtE），由“黑暗复仇者”于1991年发布并在欧洲公告板上传播。作为任何病毒都可整合的通用生成器，它使该技术工业化。<sup>[3](https://people.ece.ubc.ca/irenek/techpaps/virus/virusf.html)</sup><sup> • </sup><sup>[10](https://www.neperos.com/article/r7ctwj2e92513258)</sup>后来的生成器，如 Phalcon/Skism 批量代码生成器（PS-MPC）和病毒创建实验室（VCL），批量生产了多态病毒，至今仍在使用。<sup>[8](https://onlinelibrary.wiley.com/doi/10.1155/2023/8227751)</sup>

## 多态、寡态与变态代码

多态介于两种相关技术之间。**寡态**恶意软件——以1990年首次发现的鲸鱼 DOS 病毒为代表——在有限的解密器集合中轮换；W95/Memorial 病毒恰好有96种不同的解密器可供选择。一旦该循环耗尽，恶意软件可能的代际变异也随之耗尽。将混淆扩展到解密例程本身，产生实际上无限多的解密例程，催生了第一代多态病毒，如1260。<sup>[8](https://onlinelibrary.wiley.com/doi/10.1155/2023/8227751)</sup>

**变态**恶意软件则更进一步。多态引擎只是重新加密静态有效载荷，而变态引擎生成的变体中，语法和结构——在最复杂的层面上甚至行为——可以任意变化，但恶意功能保持不变。在变态病毒中，整个病毒体以混淆状态存在，不存在恒定病毒体，也不再需要加密，因为解密器与病毒体不再可分离。首批变态病毒是1998年的 W95/Regswap，随后是2000年的 W32/Ghost，其10个子模块仅通过子程序重排就可产生超过360万种可能变体。<sup>[11](https://www.sciencedirect.com/science/article/pii/S0167404826002683)</sup><sup> • </sup><sup>[8](https://onlinelibrary.wiley.com/doi/10.1155/2023/8227751)</sup>在实践中，恶意软件作者将变态与多态技术结合使用，使每个实例的形态代代不同。<sup>[12](https://www.sciencedirect.com/science/article/abs/pii/S0167404820304326)</sup>

## 检测

仅靠特征码扫描无法跟上自我重写的代码，因此防御针对的是不变的部分：行为、结构以及变异行为本身。

**模拟**是首个决定性的对抗措施。1992年，[尤金·卡巴斯基](https://www.edgepedia.org/zh/eugene-kaspersky)开发了一款处理器模拟器，让多态代码在模拟处理器内部自行解密，从而破译它；该技术此后成为杀毒程序不可或缺的属性。<sup>[2](https://encyclopedia.kaspersky.com/knowledge/year-1990/)</sup>模拟至今仍广泛用于通用脱壳器、行为杀毒和多态恶意软件检测。<sup>[13](https://www.virusbulletin.com/conference/vb2006/abstracts/full-potential-dynamic-binary-translation-av-emulation-engine/)</sup>Microsoft Defender Antivirus 的模拟引擎动态脱壳恶意软件并检查其在运行时的行为，同时扫描模拟期间的行为和模拟结束时的内存内容，可击败加壳器并暴露多态恶意软件的行为。<sup>[14](https://learn.microsoft.com/en-us/defender-endpoint/adv-tech-of-mdav)</sup>

**行为与机器学习检测**具有抗变体能力，因为单一恶意行为可代表数千个独立特征码变体。<sup>[15](https://download.microsoft.com/download/e/b/0/eb0f50cc-989c-4b66-b7f6-68cd3dc90de3/microsoft_security_intelligence_report_volume_21_english.pdf)</sup>当 Microsoft Defender ATP 的执行前引擎未能阻止某些 Dexphot 感染时，基于行为的机器学习模型提供了剩余防护，行为阻止与遏制最终终止了该活动。<sup>[5](https://www.microsoft.com/en-us/security/blog/2019/11/26/insights-from-one-year-of-tracking-a-polymorphic-threat/)</sup>MITRE 的检测策略 DET0324 将这一理念付诸实践，其分析可识别在执行期间或执行之间表现出二进制哈希、熵或内存段变化的自我修改可执行文件，标记功能相同但哈希不同的文件异常爆发式执行，并追踪借助脚本引擎或 JIT 编译器在多次运行间发生变异的可执行文件。<sup>[4](https://attack.mitre.org/detectionstrategies/DET0324/)</sup>

检测方法的研究综述发现，大多数依赖操作码、控制流图和 API 调用图，关键挑战包括代码混淆、缺乏动态分析能力以及应用难度。<sup>[16](https://researchonline.gcu.ac.uk/en/publications/effective-methods-to-detect-metamorphic-malware-a-systematic-revi/)</sup>在虚拟机内运行机器学习的方法——虚拟机可执行加壳恶意文件并对其进行动态分析——以及将图像处理与深度学习结合的混合方法，已被专门应用于多态恶意软件。<sup>[17](https://strathprints.strath.ac.uk/75235/)</sup>

## 有记录的案例

**Dexphot** 展示了现代活动中的多态性。它于2018年10月首次被观察到，是一款在黑客论坛和暗网网站上出售的多态木马，最终在被感染的 Windows 设备上安装加密货币挖矿程序。<sup>[5](https://www.microsoft.com/en-us/security/blog/2019/11/26/insights-from-one-year-of-tracking-a-polymorphic-threat/)</sup><sup> • </sup><sup>[18](https://digital.nhs.uk/cyber-alerts/2019/cc-3299)</sup>微软的多态爆发监控系统检测到报告激增，数千台设备上部署的文件每20至30分钟就发生变化；活动结束时约有8万台设备被感染。

**BendyBear** 是一款与中国有关联的 shellcode 加载器，是 MITRE 为 T1027.014 列出的过程示例：它在代码执行期间改变运行时特征码以规避基于特征码的防御。<sup>[1](https://attack.mitre.org/techniques/T1027/014/)</sup>

## References

1. [Obfuscated Files or Information: Polymorphic Code (T1027.014), MITRE ATT&CK](https://attack.mitre.org/techniques/T1027/014/)
2. [1990, Kaspersky IT Encyclopedia](https://encyclopedia.kaspersky.com/knowledge/year-1990/)
3. [With the increasing sophistication of anti-virus tools, a virus writer should give the virus some means for detection avoidance, UBC technical paper collection](https://people.ece.ubc.ca/irenek/techpaps/virus/virusf.html)
4. [Detection Strategy for Polymorphic Code Mutation and Execution (DET0324), MITRE ATT&CK](https://attack.mitre.org/detectionstrategies/DET0324/)
5. [Insights from one year of tracking a polymorphic threat, Microsoft Security Blog (2019)](https://www.microsoft.com/en-us/security/blog/2019/11/26/insights-from-one-year-of-tracking-a-polymorphic-threat/)
6. [A study of polymorphic virus detection, ResearchGate](https://www.researchgate.net/publication/329327300_A_study_of_polymorphic_virus_detection)
7. [Microsoft Security Intelligence Report, Volume 9: Battling Botnets](https://download.microsoft.com/download/8/1/B/81B3A25C-95A1-4BCD-88A4-2D3D0406CDEF/Microsoft_Security_Intelligence_Report_volume_9_Battling_Botnets_English.pdf)
8. [Metamorphic Malware and Obfuscation: A Survey of Techniques, Variants, and Generation Kits, Security and Communication Networks (2023)](https://onlinelibrary.wiley.com/doi/10.1155/2023/8227751)
9. [Metamorphic Virus: Analysis and Detection, Royal Holloway technical report RHUL-MA-2008-02](https://repository.royalholloway.ac.uk/items/bde3a9fe-51c0-a19a-e04d-b324c0926a4a/1/RHUL-MA-2008-02.pdf)
10. [The Engine that Kills! A Mutating Menace!, Neperos](https://www.neperos.com/article/r7ctwj2e92513258)
11. [Beyond Patterns: A Bayesian Intent Lattice for Metamorphic Malware Detection, Computers & Security](https://www.sciencedirect.com/science/article/pii/S0167404826002683)
12. [Auditing static machine learning anti-malware tools against metamorphic attacks, Computers & Security](https://www.sciencedirect.com/science/article/abs/pii/S0167404820304326)
13. [Full potential of dynamic binary translation for AV emulation engine, Virus Bulletin 2006](https://www.virusbulletin.com/conference/vb2006/abstracts/full-potential-dynamic-binary-translation-av-emulation-engine/)
14. [Advanced technologies at the core of Microsoft Defender Antivirus, Microsoft Learn](https://learn.microsoft.com/en-us/defender-endpoint/adv-tech-of-mdav)
15. [Microsoft Security Intelligence Report, Volume 21](https://download.microsoft.com/download/e/b/0/eb0f50cc-989c-4b66-b7f6-68cd3dc90de3/microsoft_security_intelligence_report_volume_21_english.pdf)
16. [Effective methods to detect metamorphic malware: a systematic review, International Journal of Electronic Security and Digital Forensics 10(2), 2018](https://researchonline.gcu.ac.uk/en/publications/effective-methods-to-detect-metamorphic-malware-a-systematic-revi/)
17. [A review of polymorphic malware detection techniques, University of Strathclyde](https://strathprints.strath.ac.uk/75235/)
18. [Dexphot Trojan, NHS England Digital cyber alert CC-3299](https://digital.nhs.uk/cyber-alerts/2019/cc-3299)

---
*Initially written Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 网络与安全 › Malware and endpoint threats › Malware by platform and type

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/polymorphic-code

English original: https://www.edgepedia.org/polymorphic-code
