CN112464224A - 一种基于Powershell脚本的去混淆方法 - Google Patents
一种基于Powershell脚本的去混淆方法 Download PDFInfo
- Publication number
- CN112464224A CN112464224A CN202011543327.5A CN202011543327A CN112464224A CN 112464224 A CN112464224 A CN 112464224A CN 202011543327 A CN202011543327 A CN 202011543327A CN 112464224 A CN112464224 A CN 112464224A
- Authority
- CN
- China
- Prior art keywords
- powershell
- confusion
- code
- document
- decoded
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
- 238000000034 method Methods 0.000 title claims abstract description 37
- 238000013515 script Methods 0.000 title claims abstract description 25
- 230000007246 mechanism Effects 0.000 claims abstract description 8
- 238000007781 pre-processing Methods 0.000 claims abstract description 4
- 230000008569 process Effects 0.000 claims description 12
- 230000003068 static effect Effects 0.000 claims description 5
- 238000012545 processing Methods 0.000 claims description 4
- 238000012544 monitoring process Methods 0.000 claims description 3
- 239000000284 extract Substances 0.000 abstract description 3
- 230000006870 function Effects 0.000 description 7
- 238000001514 detection method Methods 0.000 description 6
- 238000011160 research Methods 0.000 description 3
- 230000002155 anti-virotic effect Effects 0.000 description 2
- 230000007547 defect Effects 0.000 description 2
- 238000000605 extraction Methods 0.000 description 2
- 230000009286 beneficial effect Effects 0.000 description 1
- 238000011161 development Methods 0.000 description 1
- 230000000694 effects Effects 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 230000004044 response Effects 0.000 description 1
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F21/00—Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
- G06F21/50—Monitoring users, programs or devices to maintain the integrity of platforms, e.g. of processors, firmware or operating systems
- G06F21/52—Monitoring users, programs or devices to maintain the integrity of platforms, e.g. of processors, firmware or operating systems during program execution, e.g. stack integrity ; Preventing unwanted data erasure; Buffer overflow
- G06F21/53—Monitoring users, programs or devices to maintain the integrity of platforms, e.g. of processors, firmware or operating systems during program execution, e.g. stack integrity ; Preventing unwanted data erasure; Buffer overflow by executing in a restricted environment, e.g. sandbox or secure virtual machine
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F21/00—Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
- G06F21/50—Monitoring users, programs or devices to maintain the integrity of platforms, e.g. of processors, firmware or operating systems
- G06F21/55—Detecting local intrusion or implementing counter-measures
- G06F21/56—Computer malware detection or handling, e.g. anti-virus arrangements
- G06F21/562—Static detection
- G06F21/563—Static detection by source code analysis
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F21/00—Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
- G06F21/50—Monitoring users, programs or devices to maintain the integrity of platforms, e.g. of processors, firmware or operating systems
- G06F21/55—Detecting local intrusion or implementing counter-measures
- G06F21/56—Computer malware detection or handling, e.g. anti-virus arrangements
- G06F21/566—Dynamic detection, i.e. detection performed at run-time, e.g. emulation, suspicious activities
Landscapes
- Engineering & Computer Science (AREA)
- Computer Security & Cryptography (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- Computer Hardware Design (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Physics & Mathematics (AREA)
- Virology (AREA)
- Health & Medical Sciences (AREA)
- General Health & Medical Sciences (AREA)
- Document Processing Apparatus (AREA)
- Telephone Function (AREA)
- Telephonic Communication Services (AREA)
Abstract
一种基于Powershell脚本的去混淆方法包括对文档进行预处理,提供Office文档自动运行的虚拟环境,并将宏安全性降到最低;利用Hook机制将Powershell代码从文档内混淆过的代码中提取出来;根据文档内恶意Powershell的混淆特征获取原始Powershell。有益效果在于:该方法可以高效快速的提取恶意文档中嵌入的Powershell,获得原始的Powershell脚本,便于安全人员进一步深度分析,对攻击的溯源取证也有一定的贡献。
Description
技术领域
本发明涉及安全技术领域,尤其是一种基于Powershell脚本的去混淆方法。
背景技术
由于反病毒技术快速发展,可执行恶意程序的传播变得越来越困难,攻击者越来越倾向利用目标电脑中已经存在的工具来进行恶意行为,这种做法会留下更少的攻击痕迹,使检测更加困难。自从Microsoft Powershell被Windows系统默认安装,Powershell就成为许多攻击小组攻击链中的一个理想工具。恶意Powershell脚本通常扮演下载器的角色,最常利用的形式就是捆绑Office宏进行入侵[1]。如图1所示,攻击者通常会通过社会工程的伪装方法,欺骗用户打开Office文档(Word、Excel),并引导用户开启宏权限,用户一旦降低宏权限,嵌入的恶意Powershell脚本根据指令下载payload完成恶意行为[2]。
因为Powershell具备脚本语言的特性,恶意Powershell非常容易被混淆,目前已统计20余种混淆方式,包括大写截断和转义字符混淆,例如:powershell.exe -EncodeCommand命令被混淆成powershell.exe -^e^c^或powershell.exe-eNco等,所以传统的基于静态签名和文件哈希值的检测方法已经失效。研究表明[1],超过一半的Powershell脚本是从命令行执行的,Windows也提供了一些执行策略来防止恶意Powershell脚本启动,然而这些策略会被攻击者轻易绕过,比如使用 Invoke-Expression命令, 该命令会接受任何字符串输入并将它视为PowerShell 代码。
目前对于Powershell的检测还大多处于对Office宏的检测,一般情况下,嵌入Powershell的Office宏中会出现Shell、VBA.Shell等命令,大多数杀毒引擎根据静态匹配关键字的方式来对Office文档性质作出判断。对于Powershell的提取与去混淆建立在人工分析基础上,通常是安全专家利用经验进行手动分析。
参考文献:
[1] Candid Wueest.The increased use of Powershell in attacks[R].CA:Symantec Corporation World Headquarters,2016:1-18。
[2]McAfee.McAfee Labs Threat Report[R].CA:McAfee,2017:53-58。
当前研究方法存在的主要不足是:(1)利用对Office宏的检测来替代恶意Powershell的检测出现极高的误报率,正常文档同样会使用Shell命令对系统功能进行调用;(2)目前对于恶意Powershell脚本的提取仍然处于人工手动分析,随着利用恶意Powershell的样本数量越来越多,混淆方式越来越复杂,单靠人工分析显然不能满足需求;(3)对于文档中嵌入的混淆过的Powershell脚本,无法自动化获取原始Powershell进行深度分析。
发明内容
本发明的目的针对现有技术存在的缺陷,提出一种基于Powershell脚本的去混淆方法,将Powershell脚本从Office文档中提取出来,并对混淆过的Powershell进行自动化解混淆,获取原始Powershell,供安全人员进一步分析,加速安全事件响应速度。
所述一种基于Powershell脚本的去混淆方法包括如下步骤:
步骤一:对文档进行预处理,提供Office文档自动运行的虚拟环境,并将宏安全性降到最低;
步骤二:第一层动态解混淆,利用Hook机制将Powershell代码从文档内混淆过的代码中提取出来;
步骤三:第二层静态解混淆,根据文档内恶意Powershell的混淆特征获取原始Powershell。
优选的,第一层动态解混淆的具体步骤为:
利用Hook机制监控所述目标Off ice文档运行时的PowerShell.exe进程和cmd.exe进程,获取命令参数;
对所述命令参数进行正则化匹配处理,获得初步去混淆的PowerShell代码;
优选的,所述动态解混淆采取\-[Ee^]{1,2}[NnCcOoDdEeMmAa^]+ [A-Za-z0-9+/=]{5,}的正则化匹配处理,并保留有效参数字段。
优选的,所述命令参数进行正则化匹配处理的步骤之后,还包括:
若匹配到一EncodeCommand命令,则保留一EncodeCommand命令后面的有效参数字段;
所述分析所述初步去混淆的PowerShell代码的混淆特征,并根据所述混淆特征对所述初步去混淆的PowerShell代码进行解混淆,获取原始PowerShell代码的步骤,具体为:对所述有效参数字段进行base64位解码,并去除\OX00和空格的混淆,获得解码后的PowerShell代码;若所述解码后的PowerShell代码中包含Split函数,则根据所述Split函数的功能对所述解码后的PowerShell代码进行处理;和/或,若所述解码后的PowerShell代码中包含ASCII编码,则对所述ASCII编码进行解码;对剩余部分的有效参数字段进行拼接和格式化处理。
与现有技术相比,本发明的有益效果是:该方法可以高效快速的提取恶意文档中嵌入的Powershell,获得原始的Powershell脚本,便于安全人员进一步深度分析,对攻击的溯源取证也有一定的贡献。
附图说明
为了更清楚地说明本发明实施例的技术方案,下面将对实施例描述所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本发明的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。
图1为本发明所述一种基于Powershell脚本的去混淆方法整体流程示意图。
具体实施方式
下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其它实施例,都属于本发明保护的范围。
如图1所示,一种基于Powershell脚本的去混淆方法包括如下步骤:
步骤一:对文档进行预处理,提供Office文档自动运行的虚拟环境,并将宏安全性降到最低;
步骤二:第一层动态解混淆,利用Hook机制将Powershell代码从文档内混淆过的代码中提取出来;
步骤三:第二层静态解混淆,根据文档内恶意Powershell的混淆特征获取原始Powershell。
优选的,第一层动态解混淆的具体步骤为:
利用Hook机制监控所述目标Off ice文档运行时的PowerShell.exe进程和cmd.exe进程,获取命令参数;
对所述命令参数进行正则化匹配处理,获得初步去混淆的PowerShell代码;
优选的,所述动态解混淆采取\-[Ee^]{1,2}[NnCcOoDdEeMmAa^]+ [A-Za-z0-9+/=]{5,}的正则化匹配处理,并保留有效参数字段。
优选的,所述命令参数进行正则化匹配处理的步骤之后,还包括:
若匹配到一EncodeCommand命令,则保留一EncodeCommand命令后面的有效参数字段;
所述分析所述初步去混淆的PowerShell代码的混淆特征,并根据所述混淆特征对所述初步去混淆的PowerShell代码进行解混淆,获取原始PowerShell代码的步骤,具体为:对所述有效参数字段进行base64位解码,并去除\OX00和空格的混淆,获得解码后的PowerShell代码;若所述解码后的PowerShell代码中包含Split函数,则根据所述Split函数的功能对所述解码后的PowerShell代码进行处理;和/或,若所述解码后的PowerShell代码中包含ASCII编码,则对所述ASCII编码进行解码;对剩余部分的有效参数字段进行拼接和格式化处理。
本发明提取了Office文档中嵌入的原始恶意Powershell脚本,主要方法有:
根据Powershell脚本特性,利用Hook机制将混淆的Powershell代码从Office文档中提取出来。
对提取出来的Powershell代码进行细粒度解混淆,获取原始Powershell脚本。
通过动静态解混淆的方法,高效快速的将原始的Powershell代码从Office文档中分离出来,加快了安全人员对恶意Powershell脚本的研究,弥补了人工分析速度慢,效率低的不足。
以上公开的本发明优选实施例只是用于帮助阐述本发明。优选实施例并没有详尽叙述所有的细节,也不限制该发明仅为所述的具体实施方式。显然,根据本说明书的内容,可作很多的修改和变化。本说明书选取并具体描述这些实施例,是为了更好地解释本发明的原理和实际应用,从而使所属技术领域技术人员能很好地理解和利用本发明。本发明仅受权利要求书及其全部范围和等效物的限制。
Claims (4)
1.一种基于Powershell脚本的去混淆方法,其特征在于:所述去混淆方法包括如下步骤:
步骤一:对文档进行预处理,提供Office文档自动运行的虚拟环境,并将宏安全性降到最低;
步骤二:第一层动态解混淆,利用Hook机制将Powershell代码从文档内混淆过的代码中提取出来;
步骤三:第二层静态解混淆,根据文档内恶意Powershell的混淆特征获取原始Powershell。
2.如权利要求1所述的一种基于Powershell脚本的去混淆方法,其特征在于:第一层动态解混淆的具体步骤为:
利用Hook机制监控所述目标Off ice文档运行时的PowerShell.exe进程和cmd.exe进程,获取命令参数;
对所述命令参数进行正则化匹配处理,获得初步去混淆的PowerShell代码。
3.如权利要求1所述的一种基于Powershell脚本的去混淆方法,其特征在于:所述动态解混淆采取\-[Ee^]{1,2}[NnCcOoDdEeMmAa^]+ [A-Za-z0-9+/=]{5,}的正则化匹配处理,并保留有效参数字段。
4.如权利要求1所述的一种基于Powershell脚本的去混淆方法,其特征在于:所述命令参数进行正则化匹配处理的步骤之后,还包括:
若匹配到一EncodeCommand命令,则保留一EncodeCommand命令后面的有效参数字段;
所述分析所述初步去混淆的PowerShell代码的混淆特征,并根据所述混淆特征对所述初步去混淆的PowerShell代码进行解混淆,获取原始PowerShell代码的步骤,具体为:对所述有效参数字段进行base64位解码,并去除\OX00和空格的混淆,获得解码后的PowerShell代码;若所述解码后的PowerShell代码中包含Split函数,则根据所述Split函数的功能对所述解码后的PowerShell代码进行处理;和/或,若所述解码后的PowerShell代码中包含ASCII编码,则对所述ASCII编码进行解码;对剩余部分的有效参数字段进行拼接和格式化处理。
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202011543327.5A CN112464224A (zh) | 2020-12-24 | 2020-12-24 | 一种基于Powershell脚本的去混淆方法 |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202011543327.5A CN112464224A (zh) | 2020-12-24 | 2020-12-24 | 一种基于Powershell脚本的去混淆方法 |
Publications (1)
Publication Number | Publication Date |
---|---|
CN112464224A true CN112464224A (zh) | 2021-03-09 |
Family
ID=74803405
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202011543327.5A Pending CN112464224A (zh) | 2020-12-24 | 2020-12-24 | 一种基于Powershell脚本的去混淆方法 |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN112464224A (zh) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN116305131A (zh) * | 2023-05-20 | 2023-06-23 | 北京长亭科技有限公司 | 脚本静态去混淆方法及系统 |
-
2020
- 2020-12-24 CN CN202011543327.5A patent/CN112464224A/zh active Pending
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN116305131A (zh) * | 2023-05-20 | 2023-06-23 | 北京长亭科技有限公司 | 脚本静态去混淆方法及系统 |
CN116305131B (zh) * | 2023-05-20 | 2023-08-11 | 北京长亭科技有限公司 | 脚本静态去混淆方法及系统 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US10956477B1 (en) | System and method for detecting malicious scripts through natural language processing modeling | |
CN106790186B (zh) | 基于多源异常事件关联分析的多步攻击检测方法 | |
Alazab | Profiling and classifying the behavior of malicious codes | |
CN105871883B (zh) | 基于攻击行为分析的高级持续性威胁检测方法 | |
JP5326062B1 (ja) | 非実行ファイル検査装置及び方法 | |
EP2767923B1 (en) | Robust malware detector | |
Zolkipli et al. | A framework for malware detection using combination technique and signature generation | |
Yuan | Phd forum: Deep learning-based real-time malware detection with multi-stage analysis | |
WO2017086837A1 (ru) | Способ обнаружения вредоносных программ и элементов | |
CN106611122A (zh) | 基于虚拟执行的未知恶意程序离线检测系统 | |
CN108804921A (zh) | 一种PowerShell代码的去混淆方法及装置 | |
US10839074B2 (en) | System and method of adapting patterns of dangerous behavior of programs to the computer systems of users | |
CN113194058B (zh) | Web攻击检测方法、设备、网站应用层防火墙及介质 | |
Ramilli et al. | Multi-stage delivery of malware | |
Markowsky et al. | The Technique for Metamorphic Viruses' Detection Based on Its Obfuscation Features Analysis. | |
Paturi et al. | Mobile malware visual analytics and similarities of attack toolkits (malware gene analysis) | |
US9959406B2 (en) | System and method for zero-day privilege escalation malware detection | |
Khushali | A Review on Fileless Malware Analysis Techniques | |
Verma et al. | A literature review on malware and its analysis | |
CN115840940A (zh) | 一种无文件木马检测方法、系统、介质及设备 | |
CN112464224A (zh) | 一种基于Powershell脚本的去混淆方法 | |
CN113067792A (zh) | 一种xss攻击识别方法、装置、设备及介质 | |
Sreekumari | Malware detection techniques based on deep learning | |
Uma et al. | Survey on Android malware detection and protection using data mining algorithms | |
Li et al. | A review on signature-based detection for network threats |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
WD01 | Invention patent application deemed withdrawn after publication | ||
WD01 | Invention patent application deemed withdrawn after publication |
Application publication date: 20210309 |