Skip to content

Coldwave96/WebshellCNN

Repository files navigation

WebshellCNN

Webshell作为黑客惯用的入侵工具,是以php、asp、jsp、perl、cgi、py等网页文件形式存在的一种命令执行环境。黑客在入侵一个网站服务器后,通常会将webshell后门文件与网站服务器WEB目录下正常网页文件混在一起,通过Web访问webshell后门进行文件上传下载、访问数据库、系统命令调用等各种高危操作,达到非法控制网站服务器的目的,具备威胁程度高,隐蔽性极强等特点。

本仓库尝试通过一个 TextCNN + 二分类网络合成的综合深度神经网络实现对于 Webshell 的静态检测。TextCNN 用于处理向量化后的词数组,二分类网络用于处理手动提取的数字化特征(文件的大小以及熵值等等)。

Datasets

原始数据集采集自 Github,下面是详细的仓库列表.

黑样本

  1. tennc/webshell
  2. JohnTroony/php-webshells
  3. xl7dev/webshell
  4. tutorial0/webshell
  5. bartblaze/PHP-backdoors
  6. BlackArch/webshells
  7. nikicat/web-malware-collection
  8. fuzzdb-project/fuzzdb
  9. lcatro/PHP-webshell-Bypass-WAF
  10. linuxsec/indoxploit-shell
  11. b374k/b374k
  12. LuciferoO/webshell-collector
  13. tanjiti/webshell-Sample
  14. JoyChou93/webshell
  15. webshellpub/awsome-webshell
  16. xypiie/webshell
  17. leett1/Programe/
  18. lhlsec/webshell
  19. feihong-cs/JspMaster-Deprecated
  20. threedr3am/JSP-Webshells
  21. oneoneplus/webshell
  22. fr4nk404/Webshell-Collections
  23. mattiasgeniar/php-exploit-scripts

白样本:

  1. WordPress/WordPress
  2. yiisoft/yii2
  3. johnshen/PHPcms
  4. https://www.kashipara.com
  5. joomla/joomla-cms
  6. laravel/laravel
  7. learnstartup/4tweb
  8. phpmyadmin/phpmyadmin
  9. rainrocka/xinhu
  10. octobercms/october
  11. alkacon/opencms-core
  12. craftcms/cms
  13. croogo/croogo
  14. doorgets/CMS
  15. smarty-php/smarty
  16. source-trace/phpcms
  17. symfony/symfony
  18. typecho/typecho
  19. leett1/Programe/
  20. rpeterclark/aspunit
  21. dluxem/LiberumASP
  22. aspLite/aspLite
  23. coldstone/easyasp
  24. amasad/sane
  25. sextondb/ClassicASPUnit
  26. ASP-Ajaxed/asp-ajaxed
  27. https://www.codewithc.com

Network

Run

首先将仓库下载到本地,验证环境中 Python 版本为 3.10.13。

安装依赖

pip install -r requirements.txt

验证环境中包版本:

Package Name Version
tensorflow 2.15.0.post1
pandas 2.2.0
nltk 3.8.1
scikit-learn 1.4.1.post1
joblib 1.3.2

训练

不修改原始参数的情况下,直接运行python train.py。参数介绍如下:

Args Name Default Value Description
--config.version v1 Version
--data.webshell_folder Dataset/webshell Path to the folder which contains webshells
--data.normal_folder Dataset/normal Path to the folder which containd normal files
--data.file_extensions ['.php', '.asp', '.aspx', '.jsp', '.java'] File extension list for training
--train.max_features 5000 Max tokens for TextVectorizer
--train.sequence_length 1024 Output sequence length for TextVectorizer
--train.embedding_dim 300 Ouput dimensions of the embedding layer
--train.num_epochs 5 Number of training epochs
--train.batch_size 32 Training batch size
--train.validation_split 0.2 Proportion of validation split in train dataset

预测

不修改原始参数的情况下,直接运行python predict.py。参数介绍如下:

Args Name Default Value Description
--config.version v1 Version
--config.folder Output/ Folder which contains all config and weight of model/scaler/TextVectorizer
--data.unknown_folder Dataset/predict Folder to be detected
--data.file_extensions ['.php', '.asp', '.aspx', '.jsp', '.java'] File extension list for training
--predict.max_features 5000 Max tokens for TextVectorizer
--predict.sequence_length 1024 Output sequence length for TextVectorizer
--predict.embedding_dim 300 Ouput dimensions of the embedding layer

⚠️config.version/data.file_extensions/train.max_features/train.sequence_length/train.embedding_dim参数需要和训练时设置的参数一致。

Evaluation

结果评估如下。

训练过程

结果评估

About

Detect webshell through a TextCNN network.

Resources

Stars

Watchers

Forks

Languages