Skip to main content

AST2Vec: A Robust Neural Code Representation for Malicious PowerShell Detection

  • Conference paper
  • First Online:
Science of Cyber Security (SciSec 2023)

Part of the book series: Lecture Notes in Computer Science ((LNCS,volume 14299))

Included in the following conference series:

  • 315 Accesses

Abstract

In recent years, PowerShell has become a commonly used carrier to wage cyber attacks. As a script, PowerShell is easy to obfuscate to evade detection. Thus, they are difficult to detect directly using traditional anti-virus software. Existing advanced detection methods generally recover obfuscated scripts before detection. However, most deobfuscation tools can not achieve precise recovery on obfuscated scripts due to emerging obfuscation techniques. To solve the problem, we propose a robust neural code representation method, namely AST2Vec, to detect malicious PowerShell without de-obfuscating scripts. 6 Abstract Syntax Tree (AST) recovery-related statement nodes are defined to identify obfuscated subtrees. Then AST2Vec splits the large AST of entire PowerShell scripts into a set of small subtrees rooted by these 6 types of nodes and performs tree-based neural embeddings on all extracted subtrees by capturing lexical and syntactical knowledge of statement nodes. Based on the sequence of statement vectors, a bidirectional recursive neural network (Bi-RNN) is modeled to leverage the context of statements and finally produce vector representation of scripts. We evaluate the proposed method for malicious PowerShell detection through extensive experiments. Experimental results indicate that our model outperforms the state-of-the-art approaches.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 69.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 89.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

References

  1. Fang, Y., Zhou, X., Huang, C.: Effective method for detecting malicious PowerShell scripts based on hybrid features. Neurocomputing 448, 30–39 (2021)

    Article  Google Scholar 

  2. Hendler, D., Kels, S., Rubin, A.: Detecting malicious PowerShell commands using deep neural networks. In: Proceedings of the 2018 on Asia Conference on Computer and Communications Security (2018)

    Google Scholar 

  3. Chai, H., Ying, L., Duan, H., Zha, D.: Invoke-deobfuscation: AST-based and semantics-preserving deobfuscation for PowerShell scripts. In: 2022 52nd Annual IEEE/IFIP International Conference on Dependable Systems and Networks (DSN), pp. 295–306 (2022)

    Google Scholar 

  4. Li, Z., Chen, Q.A., Xiong, C., Chen, Y., Zhu, T., Yang, H.: Effective and light-weight deobfuscation and semantic-aware attack detection for PowerShell scripts. In: Proceedings of the 2019 ACM SIGSAC Conference on Computer and Communications Security (2019)

    Google Scholar 

  5. Blake, A., David, M.: Identifying encrypted malware traffic with contextual flow data. In: Proceedings of the 2016 ACM Workshop on Artificial Intelligence and Security, AISec 2016, pp. 35–46 (2016)

    Google Scholar 

  6. Hendler, D., Kels, S., Rubin, A.: AMSI-based detection of malicious PowerShell code using contextual embeddings. In: Proceedings of the 15th ACM Asia Conference on Computer and Communications Security (2019)

    Google Scholar 

  7. Zhang, J., Wang, X., Zhang, H., Sun, H., Wang, K., Liu, X.: A novel neural source code representation based on abstract syntax tree. In: Proceedings of the 41st International Conference on Software Engineering, pp. 783–794. IEEE Press (2019)

    Google Scholar 

  8. Mou, L., Li, G., Zhang, L., Wang, T., Jin, Z.: Convolutional neural networks over tree structures for programming language processing (2015)

    Google Scholar 

  9. Mikolov, T., Karafiát, M., Burget, L., Cernock, J., Khudanpur, S.: Recurrent neural network based language model. In: Interspeech, Conference of the International Speech Communication Association, Makuhari, Chiba, Japan, September (2015)

    Google Scholar 

  10. ISTR Living off the land fileless attack techniques. https://www.symantec.com/content/dam/symantec/docs/security-center/whitepapers/istr-living-off-the-land-and-fileless-attack-techniques-en.pdf. Accessed 11 Apr 2023

  11. karttoon, psencmds (2019). https://github.com/pan-unit42/iocs/commits/master/psencmds. Accessed 13 Dec 2019

  12. MalwareBazaar. https://bazaar.abuse.ch/

  13. Bohannon, D.: Invoke-obfuscation - powershell obfuscator. https://github.com/danielbohannon/Invoke-Obfuscation

  14. Powersploit - a powershell post-exploitation framework. https://github.com/PowerShellMafia/PowerSploit

  15. Empire - a PowerShell and python post-exploitation agent. https://github.com/EmpireProject/Empire

  16. Tang, D., Qin, B., Liu, T.: Document modeling with gated recurrent neural network for sentiment classification. In: Proceedings of the 2015 Conference on Empirical Methods in Natural Language Processing, pp. 1422–1432 (2015)

    Google Scholar 

  17. Bahdanau, D., Cho, K., Bengio, Y.: Neural machine translation by jointly learning to align and translate. arXiv preprint arXiv:1409.0473 (2014)

  18. Wei, H.-H., Li, M.: Supervised deep features for software functional clone detection by exploiting lexical and syntactical information in source code. In: Proceedings of the 26th International Joint Conference on Artificial Intelligence, pp. 3034–3040. AAAI Press (2017)

    Google Scholar 

  19. Rusak, G., Al-Dujaili, A., O’Reilly, U.M.: AST-based deep learning for detecting malicious PowerShell. In: ACM CCS (2018)

    Google Scholar 

  20. Liu, C., Xia, B., Yu, M., Liu, Y.: PSDEM: a feasible de-obfuscation method for malicious PowerShell detection. In: IEEE ISCC (2018)

    Google Scholar 

  21. Psdecode - PowerShell script for deobfuscating encoded PowerShell scripts. https://github.com/R3MRUM/PSDecode

  22. Ugarte, D., Maiorca, D., Cara, F., Giacinto, G.: PowerDrive: accurate de-obfuscation and analysis of PowerShell malware. In: Perdisci, R., Maurice, C., Giacinto, G., Almgren, M. (eds.) DIMVA 2019. LNCS, vol. 11543, pp. 240–259. Springer, Cham (2019). https://doi.org/10.1007/978-3-030-22038-9_12

    Chapter  Google Scholar 

  23. Malandrone, G.M., Virdis, G., Giacinto, G., Maiorca, D.: PowerDecode: a PowerShell script decoder dedicated to malware analysis. In: ITASEC (2021)

    Google Scholar 

  24. Gao, Y., Peng, G., Yang, X.: PowerShell malicious code family classification based on deep learning. J. Wuhan Univ. (Nat. Sci. Ed.) 68(1), 8–16 (2022). https://doi.org/10.14188/j.1671-8836

  25. Mikolov, T., Sutskever, I., Chen, K., Corrado, G.S., Dean, J.: Distributed representations of words and phrases and their compositionality. In: Advances in Neural Information Processing Systems, pp. 3111–3119 (2013)

    Google Scholar 

  26. Bohannon, D., Holmes, L.: Revoke-Obfuscation: PowerShell Obfuscation Detection Using Science (2017). https://www.fireeye.com/blog/threatresearch/2017/07/revoke-obfuscation-powershell.html

  27. VirusTotal. https://www.virustotal.com/

  28. Ruaro, N., Pagani, F., Ortolani, S., Kruegel, C., Vigna, G.: SYMBEXCEL: automated analysis and understanding of malicious excel 4.0 macros. In: 43rd IEEE Symposium on Security and Privacy, SP 2022, San Francisco, CA, USA, 22–26 May 2022, pp. 1066–1081. IEEE (2022)

    Google Scholar 

  29. LLVM. https://www.llvm.org/

  30. Cozzi, E., Graziano, M., Fratantonio, Y., Balzarotti, D.: Understanding Linux malware. In: 2018 IEEE Symposium on Security and Privacy (S &P), pp. 161–175 (2018)

    Google Scholar 

Download references

Acknowledgments

This work was supported by the National Key R &D Program of China with No. 2021YFB3101402.

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Wen Wang .

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 2023 The Author(s), under exclusive license to Springer Nature Switzerland AG

About this paper

Check for updates. Verify currency and authenticity via CrossMark

Cite this paper

Miao, H. et al. (2023). AST2Vec: A Robust Neural Code Representation for Malicious PowerShell Detection. In: Yung, M., Chen, C., Meng, W. (eds) Science of Cyber Security . SciSec 2023. Lecture Notes in Computer Science, vol 14299. Springer, Cham. https://doi.org/10.1007/978-3-031-45933-7_13

Download citation

  • DOI: https://doi.org/10.1007/978-3-031-45933-7_13

  • Published:

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-031-45932-0

  • Online ISBN: 978-3-031-45933-7

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics