Key Laboratory of Aerospace Information Security and Trusted Computing,Ministry of Education,School of Cyber Science and Engineering,Wuhan University,Wuhan 430072,Hubei,China
PowerShell has been widely used in advanced persistent threat attacks in recent years due to its high concealment, high ease of use, and simple operating environment, and the function-based family classification of the PowerShell malicious code used in it is the key to detect new variant codes. Since the current work mainly focuses on the malicious detection of PowerShell and lacks in depth mining at the function level, this paper proposes a family classification method for malicious PowerShell based on the functional level. This method extracts the semantic information of malicious PowerShell by constructing a bidirectional gated recurrent network and attention mechanism and effectively utilizes the semantic features of PowerShell code to achieve family classification. Experiments show that the method has the advantages of high accuracy, high recall, and less time consumption. Furthermore, all indicators are higher than 96% on the actual data set, and the classification effect is good.
PowerShell是Windows平台特有的可执行脚本语言,在Windows7及以后的版本中默认安装。由于PowerShell[2]简单易用且与Windows平台交互方便,被广泛应用于Windows平台的自动化运维,但同样因为它的便捷性,使其成为APT攻击链中不可缺少的角色,PowerShell恶意代码的身影频繁出现。据安全公司McAfee在2020年7月发布的网络安全威胁报告[3]数据显示:与上一季度相比,2020年第一季度新型PowerShell恶意软件数量增长了689%。利用PowerShell可以轻易完成:下载攻击载荷至内存运行、修改注册表、操作文件、执行定时任务以及与命令和控制(command and control)服务器通信等常见的恶意行为,并且运行环境的差异性不会对其产生影响。
为了解决已有恶意代码分类工作主要集中于PE文件分析,针对PowerShell恶意代码家族分类存在精度较低、耗时较长,缺乏对PowerShell恶意代码功能层面的深入挖掘等问题,本文从PowerShell代码的功能角度出发,提出一种基于注意力机制、代码语义特征和双向门控循环网络(bidirectional gated recurrent unit, BiGRU)的PowerShell恶意代码家族分类方法AA-PSFC(abstract syntax tree and attention based BiGRU for PowerShell malware family classification)。该方法通过捕捉抽象语法树的上下文语义及局部特征,忽略无关信息,实现对PowerShell恶意代码家族的高效分类。
深度学习无法直接对AST节点序列进行训练,本文采用Google于2013年提出的一款词向量工具Word2Vec进行特征映射。Word2Vec作为一种神经网络模型,通过将输入的语料转化为K维空间向量,再利用向量来计算文本之间的相似性。该模型具备两种训练模式,分别是连续词袋 (continuous bag of words,CBOW)模型和Skip-gram模型。CBOW模型根据中心词“w(t)”周围的词生成中心词的词向量,而Skip-gram模型则是根据中心词“w(t)”的词向量预测邻近词的词向量。虽然前者的效率更高,但是当其遇到低频词的时候,准确率大大下降。Skip-gram模型弥补了上述缺点,在本文处理的AST节点序列中,提取的节点类型出现频率从几十次到几千次不等。图3显示了本文用于训练的数据中低频语法树节点类型的出现情况。从图3中可知,不同家族类型的低频节点交错出现,各家族类型的低频节点主要集中在10~30频次区域。为了能够更好地处理低频的语法节点,本文采用Skip-gram模型作为Word2Vec的训练模型。
HENDLERD, KELSS, RUBINA. Detecting malicious PowerShell commands using deep neural networks[C]//Proceedings of the 2018 on Asia Conference on Computer and Communications Security. New York:Association for Computing Machinery,2018:187-197. DOI:10.1145/3196494.3196511 .
[6]
HENDLERD, KELSS, RUBINA. AMSI-based detection of malicious PowerShell code using contextual embeddings[C]//Proceedings of the 15th ACM Asia Conference on Computer and Communications Security. New York: Association for Computing Machinery,2020: 679-693. DOI:10.1145/3320269.3384742 .
[7]
MIKOLOVT, CHENK, CORRADOG, et al. Efficient estimation of word representations in vector space[EB/OL]. [2021-05-29]. DOI: 10.3126/jiee.v3i1.34327 .
[8]
BOJANOWSKIP, GRAVEE, JOULINA, et al. Enriching word vectors with subword information[J]. Transactions of the Association for Computational Linguistics, 2017,5(1): 135-146. DOI:10.1162/tacl_a_00051 .
[9]
TAJIRIY, MIMURAM. Detection of malicious PowerShell using word-level language models[C]//Advances in Information and Computer Security. New York: Springer International Publishing, 2020: 39-56. DOI:10.1007/978-3-030-58208-1_3 .
[10]
LEQ V, MIKOLOVT. Distributed representations of sentences and documents[C]//Proceedings of the 31st International Conference on Machine Learning. New York: Proceedings of Machine Learning Research Press, 2014:1188-1196.
[11]
NATARAJL, KARTHIKEYANS, JACOBG, et al. Malware images: Visualization and automatic classification[C]//Proceedings of the 8th International Symposium on Visualization for Cyber Security. New York: Association for Computing Machinery, 2011:1-7.DOI:10.1145/2016904.2016908 .
[12]
KIMH J. Image-based malware classification using convolutional neural network[C]//International Conference on Ubiquitous Information Technologies and Applications. New York: Springer International Publishing, 2017:1352-1357. DOI: 10.1007/978-981-10-7605-3_215 .
CHENX H, WEIS N, QINZ Z. Malware family classification based on deep learning visualization[J]. Computer Engineering and Applications, 2021,57(22): 131-138. DOI:10.3778/j.issn.1002-8331.2007-0291(Ch ).
WANGG D, LUT L, YINH R, et al. Malicious code family detection technology based on CNN-BiLSTM[J]. Computer Engineering and Applications, 2020, 56(24): 72-77. DOI:10.3778/j.issn.1002-8331.1911-0001(Ch ).
[17]
RUSAKG, AL-DUJAILIA, O'REILLYU M. AST-based deep learning for detecting malicious PowerShell[C]//Proceedings of the 2018 ACM SIGSAC Conference on Computer and Communications Security. New York: Association for Computing Machinery,2018: 2276-2278. DOI:10.1145/3243734.3278496 .