GyoiThon:基於機器學習的滲透測試工具

轉載自FreeBuf.COM

簡介

GyoiThon是一款基於機器學習的滲透測試工具。javascript

GyoiThon根據學習數據識別安裝在Web服務器上的軟件(操做系統,中間件,框架,CMS等)。以後,GyoiThon爲已識別的軟件執行有效的攻擊。最終,GyoiThon會自動生成掃描結果報告。上述處理均由GyoiThon自動執行。css

處理步驟html

GyoiThon會自動執行上述「Step1」-「Step4」。java

用戶惟一的操做就是在GyoiThon中,輸入目標web服務器的首頁URL。python

這很是的簡單,幾乎不花費你任何的時間和精力,就能讓你輕鬆的識別Web服務器上的漏洞。linux

處理流程

第1步:收集HTTP響應。

GyoiThon在抓取時會收集目標網站的幾個HTTP響應。如下是GyoiThon獲取的HTTP響應示例。git

示例1github

HTTP/1.1 200 OK Date: Tue, 06 Mar 2018 03:01:57 GMT Connection: close Content-Type: text/html; charset=UTF-8 Etag: "409ed-183-53c5f732641c0" Content-Length: 15271 ...snip...

示例2web

HTTP/1.1 200 OK Date: Tue, 06 Mar 2018 06:56:17 GMT Connection: close Content-Type: text/html; charset=UTF-8 Set-Cookie: f00e68432b68050dee9abe33c389831e=0eba9cd0f75ca0912b4849777677f587; path=/; Content-Length: 37496 ...snip...

示例3正則表達式

HTTP/1.1 200 OK
Date: Tue, 06 Mar 2018 04:19:19 GMT
Connection: close
Content-Type: text/html; charset=UTF-8
Content-Length: 11819
...snip...
 <script src="/core/misc/drupal.js?v=8.3.1"></script>

第2步:識別產品名稱

GyoiThon使用如下兩種方法,來識別安裝在Web服務器上的產品名稱。

1.基於機器學習

經過使用機器學習(樸素貝葉斯),GyoiThon基於每一個軟件的略微不一樣的特徵(ETAG值、Cookie值、特定HTML標籤等)的組合來進行識別。樸素貝葉斯使用如下示例(訓練數據)的訓練數據來學習。與簽名庫不一樣的是,當在一個特徵中不能識別軟件時,樸素貝葉斯是基於HTTP響應中包含的各類特徵隨機識別的。

示例1

Etag: "409ed-183-53c5f732641c0"

GyoiThon能夠識別Web服務器軟件Apache。

這是由於GyoiThon學習了Apache的特性,例如「Etag頭值(409ed-183-53c5f732641c0)」。在咱們的研究測試中發現,Apache使用數字和小寫字母的組合做爲Etag值。而且,Etag值分開4-5位和3-4位和12位,最終位在多數狀況下爲0。

示例2

Set-Cookie: f00e68432b68050dee9abe33c389831e=0eba9cd0f75ca0912b4849777677f587;

GyoiThon能夠識別CMS Joomla !

這是由於GyoiThon學習了Joomla的特性!如「Cookie名稱(f00e6 … 9831e)」和「Cookie值(0eba9 … 7f587)」。在咱們研究測試中發現,Joomla!在多數狀況下使用32個小寫字母做爲Cookie名稱以及Cookie值。

訓練數據(示例)

Joomla! (CMS)

Set-Cookie: ([a-z0-9]{32})=[a-z0-9]{26,32}; Set-Cookie: [a-z0-9]{32}=([a-z0-9]{26,32}); ...snip...

HeartCore (日本知名CMS)

Set-Cookie:.*=([A-Z0-9]{32});.* <meta name=["'](author)["'] content=["']{2}.* ...snip...

Apache (Web服務器軟件)

Etag:.*".*-[0-9a-z]{3,4}-[0-9a-z]{13}")[\r\n] ...snip...

2.基於字符串匹配。

固然,GyoiThon也能夠經過傳統滲透測試工具中使用的字符串匹配來識別軟件。示例以下。

示例3

<script src="/core/misc/drupal.js?v=8.3.1"></script>

GyoiThon能夠識別CMS Drupal。

這很容易。

第3步:使用Metasploit進行利用。

GyoiThon使用Metasploit執行與識別軟件相對應的漏洞利用,並檢查軟件是否受此漏洞影響。

運行示例

[*] exploit/multi/http/struts_code_exec_exception_delegator, target: 1, payload: linux/x86/shell/reverse_nonx_tcp, result: failure [*] exploit/multi/http/struts_code_exec_exception_delegator, target: 1, payload: linux/x86/shell/reverse_tcp, result: failure [*] exploit/multi/http/struts_code_exec_exception_delegator, target: 1, payload: linux/x86/shell/reverse_tcp_uuid, result: failure [*] exploit/multi/http/struts_code_exec_exception_delegator, target: 1, payload: linux/x86/shell_bind_ipv6_tcp, result: failure [*] exploit/multi/http/struts_code_exec_exception_delegator, target: 1, payload: linux/x86/shell_bind_tcp, result: failure ...snip... [*] exploit/linux/http/apache_continuum_cmd_exec, target: 0, payload: generic/custom, result: failure [*] exploit/linux/http/apache_continuum_cmd_exec, target: 0, payload: generic/debug_trap, result: failure [*] exploit/linux/http/apache_continuum_cmd_exec, target: 0, payload: generic/shell_bind_tcp, result: failure [*] exploit/linux/http/apache_continuum_cmd_exec, target: 0, payload: generic/shell_reverse_tcp, result: failure [*] exploit/linux/http/apache_continuum_cmd_exec, target: 0, payload: generic/tight_loop, result: bingo!!

第4步:生成掃描報告。

GyoiThon生成彙總漏洞的報告。

報告的樣式爲html。

樣板

視頻演示:https://www.youtube.com/watch?v=jmi43eZOE9w

使用

Step.0初始化Metasploit DB

首先,使用msfdb命令初始化metasploit db(postgreSQL)。

root@kali:~# msfdb init

Step.1啓動Metasploit框架

你能夠在安裝Metasploit Framework的遠程服務器(如Kali Linux)上啓動Metasploit。

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 >

Step.2啓動RPC服務器

啓動Metasploit的RPC服務器。

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
msgrpc選項 描述
ServerHost Metasploit啓動的服務器IP地址。上面的例子爲:192.168.220.144。
ServerPort Metasploit啓動的服務器端口號。上面的例子爲:55553。
User 身份驗證用戶名 (默認 => msf)。上面的例子爲:test。
Pass 身份驗證密碼 (默認 => 隨機字符串)。上面的例子爲:test1234。

Step.3編輯配置文件。

你必須在config.ini中更改如下值

...snip... [GyoiExploit] server_host : 192.168.220.144 server_port : 55553 msgrpc_user : test msgrpc_pass : test1234 timeout : 10 LHOST : 192.168.220.144 LPORT : 4444 ...snip...
配置 描述
server_host Metasploit啓動的服務器IP地址。你在Step2中設置的ServerHost值。
server_port Metasploit啓動的服務器端口號。你在Step2中設置的ServerPort值。
msgrpc_user 身份驗證用戶名。你在Step2中設置的User值。
msgrpc_pass 身份驗證密碼。你在Step2中設置的Pass值。
LHOST Metasploit啓動的服務器IP地址。你在Step2中設置的ServerHost值。

Step.4編輯目標(target)文件。

GyoiThon使用host.txt訪問目標服務器。

因此,你必須在執行GyoiThon以前編輯host.txt。

host.txt的樣本

target server => 192.168.220.148
target port => 80
target path => /oscommerce/catalog/

192.168.220.148 80 /oscommerce/catalog/

你必須使用空格分隔IP地址,端口號和目標路徑。

Step.5運行GyoiThon

執行命令以下。

local@client:~$ python gyoithon.py

Step.6查看掃描報告

使用任意瀏覽器打開並查看報告。

local@client:~$ firefox "gyoithon root path"/classifier4gyoithon/report/gyoithon_report.html

提示

1.如何添加字符串匹配模式。

簽名路徑包括對應於每一個產品類別的四個文件。

local@client:~$ ls "gyoithon root path"/signatures/ signature_cms.txt signature_framework.txt signature_os.txt signature_web.txt

signature_cms.txt

這個文件包含CMS的字符串匹配模式。

signature_framework.txt

這個文件包含FrameWork的字符串匹配模式。

signature_os.txt

這個文件包含操做系統的字符串匹配模式。

signature_web.txt

這個文件包含Web服務器軟件的字符串匹配模式。

若是你想添加新的字符串匹配模式,你能夠在每一個文件的最後一行添加新的字符串匹配模式。

例如)在signature_cms.txt中添加CMS的新字符串匹配模式。

tikiwiki@(Powered by TikiWiki) wordpress@<.*=(.*/wp-).*/.*> wordpress@(<meta name="generator" content="WordPress).*> ...snip... typo@.*(href="fileadmin/templates/).*> typo@(<meta name="generator" content="TYPO3 CMS).*> "new product name"@"regex pattern" [EOF]

注意

以上新產品名稱必須是Metasploit可識別的名稱。你必須使用@分隔新產品名稱和正則表達式模式。

2.如何添加學習數據。

簽名路徑包括對應於每一個產品類別的四個文件。

local@client:~$ ls "gyoithon root path"/classifier4gyoithon/train_data/ train_cms_in.txt train_framework_in.txt train_os_in.txt train_web_in.txt

train_cms_in.txt

這個文件包含CMS的學習數據。

train_framework_in.txt

這個文件包含FrameWork的學習數據。

train_os_in.txt

這個文件包含操做系統的學習數據。

train_web_in.txt

這個文件包含Web服務器軟件的學習數據。

若是你想添加新的學習數據,你能夠在每一個文件的最後一行添加學習數據。

例如)在train_cms_in.txt中添加CMS的新學習數據。

joomla@(Set-Cookie: [a-z0-9]{32}=.*); joomla@(Set-Cookie: .*=[a-z0-9]{26,32}); ...snip... xoops@(xoops\.js) xoops@(xoops\.css) "new product name"@"regex pattern" [EOF]

注意

以上新產品名稱必須是Metasploit可識別的名稱。你必須使用@分隔新產品名稱和正則表達式模式。

你必須刪除訓練過的數據(* .pkl)。

local@client:~$ ls "gyoithon root path"/classifier4gyoithon/trained_data/ train_cms_out.pkl train_framework_out.pkl train_web_out.pkl local@client:~$ rm "gyoithon root path"/classifier4gyoithon/trained_data/*.pkl

3.如何更改「利用模塊的選項」。

當GyoiThon利用時,它會使用Exploit模塊選項的默認值。

若是你想更改選項值,請在exploit_tree.json中輸入任意值到「user_specify」,以下所示。

"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/" },

上面的例子是將exploit模塊「exploit/unix/webapp/joomla_media_upload_exec」中的TARGETURI選項的值更改成「/joomla」中的「/my_original_dir/」。

*參考來源:GitHub,FB小編 secist 編譯,轉載自FreeBuf.COM

相關文章
相關標籤/搜索