### Set up web driver directory for selenium Source: https://github.com/13o-bbr-bbq/machine_learning_security/blob/master/Generator/README.md Create a web_drivers directory and move the downloaded chromedriver.exe into it. The example uses Google Chrome driver; the directory listing shows the expected file placement. ```powershell PS C:\machine_learning_security\Generator> mkdir web_drivers PS C:\machine_learning_security\Generator> mv chromedriver.exe web_drivers PS C:\machine_learning_security\Generator> ls .\web_drivers Directory: C:\machine_learning_security\Generator\web_drivers Mode LastWriteTime Length Name ---- ------------- ------ ---- -a---- 2018/07/27 12:32 6737408 chromedriver.exe ``` -------------------------------- ### Step.1: Get python3-pip Source: https://github.com/13o-bbr-bbq/machine_learning_security/wiki/Installation Updates the package list and installs python3-pip. Run as root on Kali Linux. ```bash root@kali:~# apt-get update root@kali:~# apt-get install python3-pip ``` -------------------------------- ### Step.0: Git clone DeepExploit's repository Source: https://github.com/13o-bbr-bbq/machine_learning_security/wiki/Installation Clones the machine_learning_security repository from GitHub. Run this as root on Kali Linux. ```bash root@kali:~# git clone https://github.com/13o-bbr-bbq/machine_learning_security.git ``` -------------------------------- ### Step.5: Initialize Metasploit DB Source: https://github.com/13o-bbr-bbq/machine_learning_security/wiki/Installation Initializes the Metasploit database (postgreSQL) using the msfdb command. Run as root on Kali Linux. ```bash root@kali:~# msfdb init ``` -------------------------------- ### Git clone DeepGenerator repository Source: https://github.com/13o-bbr-bbq/machine_learning_security/blob/master/Generator/README.md Clone the DeepGenerator repository from GitHub. This is the first step in installation. ```powershell PS C:\> git clone https://github.com/13o-bbr-bbq/machine_learning_security.git ``` -------------------------------- ### Install required packages Source: https://github.com/13o-bbr-bbq/machine_learning_security/blob/master/Recommender/README.md Changes to the Recommender directory and installs dependencies using pip. Note: the command uses 'python install' which may be a typo for 'pip install'. ```bash local@client:~$ cd machine_learning_security/Recommender local@client:~$ python install -r requirements.txt ``` -------------------------------- ### Step.2: Install required python packages Source: https://github.com/13o-bbr-bbq/machine_learning_security/wiki/Installation Changes to the DeepExploit directory and installs the required Python packages from requirements.txt using pip3. ```bash root@kali:~# cd machine_learning_security/DeepExploit root@kali:~/machine_learning_security/DeepExploit# pip3 install -r requirements.txt ``` -------------------------------- ### Step.7: Launch RPC Server Source: https://github.com/13o-bbr-bbq/machine_learning_security/wiki/Installation Loads the msgrpc plugin with the specified ServerHost, ServerPort, User, and Pass. The output shows the MSGRPC service details and successful plugin load. The values must match those in config.ini. ```bash msf> load msgrpc ServerHost=192.168.220.144 ServerPort=55553 User=test Pass=test1234 [*] MSGRPC Service: 192.168.220.144:55553 [*] MSGRPC Username: test [*] MSGRPC Password: test1234 [*] Successfully loaded plugin: msgrpc ``` -------------------------------- ### Generated injection codes (XSS examples) Source: https://github.com/13o-bbr-bbq/machine_learning_security/blob/master/Generator/README.md Example injection codes generated by DeepGenerator, including reflected XSS payloads. These are outputs of the tool and demonstrate the type of codes it can produce. ```html size=kind= ``` -------------------------------- ### Step.6: Launch Metasploit Framework Source: https://github.com/13o-bbr-bbq/machine_learning_security/wiki/Installation Launches Metasploit on the remote server (e.g., Kali Linux). The output shows the Metasploit banner and the msf> prompt. ```bash root@kali:~# msfconsole ______________________________________________________________________________ | | | METASPLOIT CYBER MISSILE COMMAND V4 | |______________________________________________________________________________| \\ / / \\ . / / x \\ / / \\ / + / \\ + / / * / / / . / X / / X / ### / # % # / ### . / . / . * . / * + * ^ #### __ __ __ ####### __ __ __ #### #### / \\ / \\ / \\ ########### / \\ / \\ / \\ #### ################################################################################ ################################################################################ # WAVE 4 ######## SCORE 31337 ################################## HIGH FFFFFFFF # ################################################################################ https://metasploit.com =[ metasploit v4.16.15-dev ] + -- --=[ 1699 exploits - 968 auxiliary - 299 post ] + -- --=[ 503 payloads - 40 encoders - 10 nops ] + -- --=[ Free Metasploit Pro trial: http://r-7.co/trymsp ] msf > ``` -------------------------------- ### Install required Python packages Source: https://github.com/13o-bbr-bbq/machine_learning_security/blob/master/Generator/README.md Navigate to the Generator directory, check pip version, and install dependencies from requirements.txt. Requires Python 3.6 and pip 10.0.1 as shown. ```powershell PS C:\> cd machine_learning_security/Generator PS C:\machine_learning_security\Generator> pip -V pip 10.0.1 from c:\users\itaka\anaconda3\lib\site-packages\pip (python 3.6) PS C:\machine_learning_security\Generator> pip install -r requirements.txt ``` -------------------------------- ### Step.3: Edit config.ini of DeepExploit Source: https://github.com/13o-bbr-bbq/machine_learning_security/wiki/Installation Edit config.ini to set the server_host value to match the IP address of your Kali Linux. The snippet shows the relevant [Common] section with example values. ```ini root@kali:~/machine_learning_security/DeepExploit# vim config.ini ...snip... [Common] server_host : 192.168.220.144 server_port : 55553 msgrpc_user : test msgrpc_pass : test1234 ``` -------------------------------- ### Step.7: config.ini values for msgrpc Source: https://github.com/13o-bbr-bbq/machine_learning_security/wiki/Installation Shows the [Common] section of config.ini that must match the arguments used in the msgrpc load command. ```ini [Common] server_host : 192.168.220.144 server_port : 55553 msgrpc_user : test msgrpc_pass : test1234 ``` -------------------------------- ### Check generated injection codes with cd result and ls Source: https://github.com/13o-bbr-bbq/machine_learning_security/blob/master/Generator/README.md Navigates to the result directory and lists its contents to inspect the generated injection codes. ```powershell PS C:\machine_learning_security\Generator> cd result PS C:\machine_learning_security\Generator\result> ls ``` -------------------------------- ### Step.4: Edit proxychains.conf and config.ini Source: https://github.com/13o-bbr-bbq/machine_learning_security/wiki/Installation Edit /etc/proxychains.conf to match the ProxyList info with the proxy_host and proxy_port in config.ini. The two blocks show the relevant sections from both files. ```text root@kali:~/machine_learning_security/DeepExploit# vim /etc/proxychains.conf ...snip... [ProxyList] ...snip... socks4 127.0.0.1 1080 ``` ```text root@kali:~/machine_learning_security/DeepExploit# vim config.ini ...snip... proxy_host : 127.0.0.1 proxy_port : 1080 ``` -------------------------------- ### Recommender Output with Rankings and Probabilities Source: https://github.com/13o-bbr-bbq/machine_learning_security/blob/master/Recommender/README.md Example output from running the Recommender. It shows Scrapy log lines, feature vectors, loading of trained data, and ranked injection codes with probabilities. The note warns that recommendation accuracy depends on training data quality. ```text Using TensorFlow backend. 2018-06-06 14:20:49 [scrapy.utils.log] INFO: Scrapy 1.5.0 started (bot: scrapybot) 2018-06-06 14:20:49 [scrapy.utils.log] INFO: Versions: lxml 3.7.3.0, libxml2 2.9.4, cssselect 1.0.3, parsel 1.4.0, w3lib 1.19.0, Twisted 17.5.0, Python 3.6.1 |Anaconda custom (64-bit)| (default, May 11 2017, 13:25:24) [MSC v.1900 64 bit (AMD64)], pyOpenSSL 17.0.0 (OpenSSL 1.0.2o 27 Mar 2018), cryptography 1.8.1, Platform Windows-7-6.1.7601-SP1 ...snip... 2018-06-06 14:20:58 [scrapy.core.engine] DEBUG: Crawled (200) (referer: https://192.168.220.129/wavsep/active/index-xss.jsp) 2018-06-06 14:21:04 [scrapy.core.engine] DEBUG: Crawled (200) (referer: https://192.168.220.129/wavsep/active/index-xss.jsp) 2018-06-06 14:21:05 [scrapy.core.scraper] DEBUG: Scraped from <200 https://192.168.220.129/wavsep/active/Reflected-XSS/RXSS-Detection-Evaluation-GET/index.jsp> ...snip... [*] Loading train data and Create label. ---------------------------------------------------------------------------------------------------------------------------------- [*] Target url: https://192.168.220.129/wavsep/active/Reflected-XSS/RXSS-Detection-Evaluation-GET/Case02-Tag2TagScope.jsp?userinput=textvalue Parameter: userinput [*] Feature: [7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] [*] Loading trained data: C:\Users\i.takaesu\Documents\GitHub\Recommender\src\../trained_data\recommender.h5 [*] Recommended. [+] Rank Injection code Probability ============================================================================= [+] 1 0.9992570281028748 [+] 2 0.0006935920100659132 [+] 3 3.7410824006656185e-05 [*] Elapsed time :0.4894998073577881[sec] ---------------------------------------------------------------------------------------------------------------------------------- [*] Target url: https://192.168.220.129/wavsep/active/Reflected-XSS/RXSS-Detection-Evaluation-GET/Case24-Js2ScriptTag.jsp?userinput=1234 Parameter: userinput [*] Feature: [6, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0] [*] Loading trained data: C:\Users\i.takaesu\Documents\GitHub\Recommender\src\../trained_data\recommender.h5 [*] Recommended. [+] Rank Injection code Probability ============================================================================= [+] 1 0.9942600727081299 [+] 2 src=saivs.js 0.0057328855618834496 [+] 3 6.2975282162369695e-06 [*] Elapsed time :0.439500093460083[sec] ...snip... ``` -------------------------------- ### Move tidy directory to DeepGenerator root Source: https://github.com/13o-bbr-bbq/machine_learning_security/blob/master/Generator/README.md Move the downloaded tidy-5.4.0-win64 directory to the Generator root. The directory listing shows the expected project structure after moving. ```powershell PS C:\users\itaka\Downloads> mv tidy-5.4.0-win64 C:\machine_learning_security\Generator\ PS C:\users\itaka\Downloads> ls C:\machine_learning_security\Generator Directory: C:\machine_learning_security\Generator Mode LastWriteTime Length Name ---- ------------- ------ ---- d----- 2018/09/18 6:39 .idea d----- 2018/09/11 16:10 gene d----- 2018/09/11 14:55 html d----- 2018/09/10 7:05 img d----- 2018/09/14 11:46 result d----- 2018/09/11 14:28 tidy-5.4.0-win64 d----- 2018/09/10 8:02 web_drivers d----- 2018/09/13 7:46 weight d----- 2018/09/13 15:19 __pycache__ -a---- 2018/09/13 11:36 1477 config.ini -a---- 2018/09/13 15:15 17510 gan_main.py -a---- 2018/09/11 15:41 14595 ga_main.py -a---- 2018/09/11 13:26 3697 generator.py -a---- 2018/09/11 11:30 4911 util.py ``` -------------------------------- ### Run DeepGenerator with python generator.py Source: https://github.com/13o-bbr-bbq/machine_learning_security/blob/master/Generator/README.md Executes the DeepGenerator script from the Generator directory. The output shows launch information, genetic algorithm population creation, and evaluation progress across generations. ```powershell PS C:\machine_learning_security\Generator> python generator.py [+] Launched : chrome 68.0.3440.106 [+] 1/10 Create individuals using Genetic Algorithm. [+] Evaluating html place : body_tag [+] Create population. [*] Created individual : [74, 59, 50, 24, 28]. [*] Created individual : [61, 49, 66, 18, 4]. [*] Created individual : [38, 47, 4, 9, 22]. ...snip... [*] Evaluation individual in body_tag: 97/100 in 1 generation [*] Evaluation individual in body_tag: 98/100 in 1 generation [*] Evaluation individual in body_tag: 99/100 in 1 generation [*] Evaluation individual in body_tag: 100/100 in 1 generation [+] 1 generation result: Min=-1.8, Max=0, Avg=-0.92. [+] Evaluate individual : 2/1000 generation. [*] Evaluation individual in body_tag: 1/100 in 2 generation [*] Evaluation individual in body_tag: 2/100 in 2 generation ``` -------------------------------- ### Prohibit scanning of specific server in config.ini Source: https://github.com/13o-bbr-bbq/machine_learning_security/wiki/Usage Shows how to add IP addresses to the 'prohibited_list' in config.ini to prevent scanning of specific servers. The list uses '@' as a separator, as shown with three example IPs. ```ini [Metasploit] lport : 4444 proxy_host : 127.0.0.1 proxy_port : 1080 prohibited_list : 192.168.220.1@192.168.220.2@192.168.220.254 path_collection : path@uri@dir@folder@file ``` -------------------------------- ### Change Exploit module's option in exploit_tree.json Source: https://github.com/13o-bbr-bbq/machine_learning_security/wiki/Usage Shows how to modify the 'user_specify' field in exploit_tree.json to override the default value of an exploit module option. The example changes the TARGETURI option for exploit/unix/webapp/joomla_media_upload_exec from '/joomla' to '/my_original_dir/'. ```json "unix/webapp/joomla_media_upload_exec": { "targets": { "0": [ "generic/custom", "generic/shell_bind_tcp", "generic/shell_reverse_tcp", ...snip... "TARGETURI": { "type": "string", "required": true, "advanced": false, "evasion": false, "desc": "The base path to Joomla", "default": "/joomla", "user_specify": "/my_original_dir/" }, ``` -------------------------------- ### Check scan report with firefox report/DeepExploit_test_report.html Source: https://github.com/13o-bbr-bbq/machine_learning_security/wiki/Usage Opens the generated scan report in a web browser using Firefox. The report is located at report/DeepExploit_test_report.html. ```bash root@kali:~/machine_learning_security/DeepExploit# firefox report/DeepExploit_test_report.html ``` -------------------------------- ### Train Deep Exploit with python3 DeepExploit.py -t -m train Source: https://github.com/13o-bbr-bbq/machine_learning_security/wiki/Usage Executes Deep Exploit in training mode against a specified vulnerable host. Requires Python 3.6.5rc1. The -t option specifies the target IP address and -m train sets the execution mode. ```bash root@kali:~/machine_learning_security/DeepExploit# python3 -V Python 3.6.5rc1 root@kali:~/machine_learning_security/DeepExploit# python3 DeepExploit.py -t 192.168.184.132 -m train ``` -------------------------------- ### Test using trained Deep Exploit with python DeepExploit.py -t -m test Source: https://github.com/13o-bbr-bbq/machine_learning_security/wiki/Usage Executes Deep Exploit in testing mode against a target host. The -t option specifies the target IP address and -m test sets the execution mode. ```bash root@kali:~/machine_learning_security/DeepExploit# python DeepExploit.py -t 192.168.184.129 -m test ``` -------------------------------- ### Recommend with target URL Source: https://github.com/13o-bbr-bbq/machine_learning_security/blob/master/Recommender/README.md Run the recommendation process with the TEST argument and a target URL. The URL must include the port number, e.g., "http://example.com:80/path/". ```bash local@client:~$ python main.py TEST "target url of crawling origin." ``` -------------------------------- ### Run Recommender with python main.py Source: https://github.com/13o-bbr-bbq/machine_learning_security/blob/master/Recommender/README.md Command-line invocation of the Recommender tool against a target URL. The output shows Scrapy crawling, feature extraction, loading a trained model, and ranked injection code recommendations with probabilities. Accuracy depends on training data quality. ```bash local@client:~$ python main.py https://192.168.220.129/wavsep/active/index-xss.jsp ``` -------------------------------- ### Train Recommender Model with python main.py TRAIN Source: https://github.com/13o-bbr-bbq/machine_learning_security/blob/master/Recommender/README.md Run the training command for the recommender model. The output shows the model architecture, training progress over 1000 epochs, and final evaluation metrics. After training, the model is saved to a .h5 file and can be used with pyRecommender. ```bash local@client:~$ python main.py TRAIN Using TensorFlow backend. [*] Loading train data and Create label. [*] Training model.. [+] Train samples: 1410 _________________________________________________________________ Layer (type) Output Shape Param # ================================================================= dense_1 (Dense) (None, 50) 900 _________________________________________________________________ activation_1 (Activation) (None, 50) 0 _________________________________________________________________ dropout_1 (Dropout) (None, 50) 0 _________________________________________________________________ dense_2 (Dense) (None, 100) 5100 _________________________________________________________________ activation_2 (Activation) (None, 100) 0 _________________________________________________________________ dropout_2 (Dropout) (None, 100) 0 _________________________________________________________________ dense_3 (Dense) (None, 100) 10100 _________________________________________________________________ activation_3 (Activation) (None, 100) 0 _________________________________________________________________ dropout_3 (Dropout) (None, 100) 0 _________________________________________________________________ dense_4 (Dense) (None, 141) 14241 _________________________________________________________________ activation_4 (Activation) (None, 141) 0 ================================================================= Total params: 30,341 Trainable params: 30,341 Non-trainable params: 0 _________________________________________________________________ Train on 1015 samples, validate on 113 samples Epoch 1/1000 32/1015 [..............................] - ETA: 10s - loss: 4.9794 - acc: 0.0000e+00 416/1015 [===========>..................] - ETA: 0s - loss: 5.0210 - acc: 0.0072 832/1015 [=======================>......] - ETA: 0s - loss: 4.9810 - acc: 0.0096 1015/1015 [==============================] - 1s 504us/step - loss: 4.9619 - acc: 0.0108 - val_loss: 4.8834 - val_acc: 0.0088 Epoch 2/1000 32/1015 [..............................] - ETA: 0s - loss: 4.7992 - acc: 0.0312 416/1015 [===========>..................] - ETA: 0s - loss: 4.8381 - acc: 0.0168 768/1015 [=====================>........] - ETA: 0s - loss: 4.8196 - acc: 0.0195 1015/1015 [==============================] - 0s 149us/step - loss: 4.8007 - acc: 0.0177 - val_loss: 4.7378 - val_acc: 0.0000e+00 ...snip... Epoch 999/1000 32/1015 [..............................] - ETA: 0s - loss: 0.1324 - acc: 0.9375 480/1015 [=============>................] - ETA: 0s - loss: 0.2703 - acc: 0.8438 928/1015 [==========================>...] - ETA: 0s - loss: 0.2592 - acc: 0.8491 1015/1015 [==============================] - 0s 124us/step - loss: 0.2593 - acc: 0.8463 - val_loss: 0.2351 - val_acc: 0.8142 Epoch 1000/1000 32/1015 [..............................] - ETA: 0s - loss: 0.1828 - acc: 0.9688 480/1015 [=============>................] - ETA: 0s - loss: 0.2484 - acc: 0.8708 928/1015 [==========================>...] - ETA: 0s - loss: 0.2671 - acc: 0.8610 1015/1015 [==============================] - 0s 121us/step - loss: 0.2708 - acc: 0.8581 - val_loss: 0.2387 - val_acc: 0.8142 [*] Finish training. [*] Evaluation. [+] Test loss: 0.3130897362815573 [+] Test acc: 0.7801418448170871 [+] Saved model: "Your environment path"/Recommender/src/../trained_data/recommender.h5 ``` -------------------------------- ### Train the model Source: https://github.com/13o-bbr-bbq/machine_learning_security/blob/master/Recommender/README.md Run the training process with the TRAIN argument. ```bash local@client:~$ python main.py TRAIN ``` -------------------------------- ### Edit Keras configuration (keras.json) Source: https://github.com/13o-bbr-bbq/machine_learning_security/blob/master/Recommender/README.md Navigate to the .keras directory in your home directory and edit keras.json to set the backend to tensorflow. The provided JSON shows the expected configuration. ```bash local@client:~$ cd "your home directory"/.keras local@client:~$ vim keras.json ``` ```json { "epsilon": 1e-07, "floatx": "float32", "image_data_format": "channels_last", "backend": "tensorflow" } ``` -------------------------------- ### Clone pyRecommender repository Source: https://github.com/13o-bbr-bbq/machine_learning_security/blob/master/Recommender/README.md Clones the machine_learning_security repository from GitHub, which contains the pyRecommender project. ```bash local@client:~$ git clone https://github.com/13o-bbr-bbq/machine_learning_security.git ``` -------------------------------- ### Import libraries and set constants for spam detection Source: https://github.com/13o-bbr-bbq/machine_learning_security/blob/master/Security_and_MachineLearning/Chap2_SpamDetection.md Sets up imports for email processing, NLTK, pandas, and scikit-learn, and defines MAX_COUNT as the maximum target mail number. ```python # -*- coding: utf-8 -*- import os import codecs import urllib.request import nltk import mailbox import numpy as np import pandas as pd from email.header import decode_header from nltk.corpus.reader import * from nltk.corpus.reader.util import * from sklearn.naive_bayes import MultinomialNB from sklearn.feature_extraction.text import CountVectorizer # Max target mail number. MAX_COUNT = 5 ``` -------------------------------- ### Define get_stopwords() to fetch Japanese and symbol stopwords Source: https://github.com/13o-bbr-bbq/machine_learning_security/blob/master/Security_and_MachineLearning/Chap2_SpamDetection.md Downloads a Japanese stopword list from the SlothLib SVN repository and combines it with Japanese and English symbol lists. Returns the concatenated list for use in text preprocessing. ```python # Get stopwords (Japanese and symbols). def get_stopwords(): url = 'http://svn.sourceforge.jp/svnroot/slothlib/CSharp/Version1/SlothLib/NLP/Filter/StopWord/word/Japanese.txt' slothlib_file = urllib.request.urlopen(url) slothlib_stopwords = [line.decode('utf-8').strip() for line in slothlib_file] jpn_stopwords = [ss for ss in slothlib_stopwords if not ss == u''] jpn_symbols = ['’', '”', '‘', '。', '、', 'ー', '!', '?', ':', ';', '(', ')', '*', '¥'] eng_symbols = ["'", '"', '`', '.', ',', '-', '!', '?', ':', ';', '(', ')', '*', '--', '\\'] return jpn_stopwords + jpn_symbols + eng_symbols ```