第一部分:1.MySQL数据库的基础知识

     SQL注入学习之路专栏,里面的内容是基于Sqli-labs这个环境来进行学习的,从原理一步一步来学习。(我在window Sever 2003虚拟机中通过phpstudy 2016搭建了Sqli-labs环境。)

下面开始我们的学习之旅:

1.启动 mysql,然后通过查询检查下数据库:

show databases;

2. Sqli-labs环境中使用的数据库名为 security,所以我们选择 security数据库来执行命令。

ues security;

3.查看下security数据库中有哪些表

4.我们可以在security数据库中看到有四张表,然后我们查看这四张表的结构。

desc emails;

desc referers;

desc uagents;

desc users;

5.我们还要了解下系统数据库,即 information_schema。

use information_schema;

6.看下有哪些表。

show tables;

7.我们枚举这整张表。(注意该表中的TABLE_SCHEMA和TABLE_NAME)

desc tables;

8.现在我们来使用下面这个语句查询,使用这个查询,我们可以看到表名。

select table_name from information_schema.tables where table_schema = "security";

9. 注:MySQL 中 Schema 等价于 数据库。(便于理解,要想知道他们的关系可自行查阅资料。)


10.Mysql 有一个系统数据库 information_schema,存储着所有的数据库的相关信息,一般的,
我们利用该表可以进行一次完整的注入。以下为一般的流程。


猜数据库
select schema_name from information_schema.schemata


猜某库的数据表------以security数据库为例。
select table_name from information_schema.tables where table_schema='xxxxx';


猜某表的所有列------以emails表为例。
select column_name from information_schema.columns where table_name='xxxxx';


获取某列(字段)的内容---以emails表中的id,email_id 为例。
select *** from ****

1.limit子句(top子句)

用于规定要返回的记录的数目:
select * from users limit 3——返回前3条


select * from users limit 1,2——返回索引1开始的前2条(索引从0开始)

2.concat()函数

用于连接字符串:
select concat('11','22','33')——输出"112233"
select concat_ws('-','11','22','33')——输出"11-22-33",第一个参数是其它参数的分隔符
group_concat(column_name)——将字段的所有数据用,连接作为字符串输出

3.内置数据库information_schema

系统数据库information_schema数据库中含有很重要的三张表:schemata,tables和columns。

schemata表中存储了Mysql中所有数据库的信息,包括数据库名,编码类型等,show databases的结果取之此表。
tables表有schema_name一个字段,为数据库名。

tables表中存储了Mysql中所有数据库的表的信息(索引根据数据库名),show tables from schema_name的结果取之此表。
tables表有table_nametable_schema两个字段,分别为表名和表所在数据库。

columns表中存储了Mysql中所有表的字段信息,show columns from schema_name.table_name的结果取之此表。
columns表有column_nametable_nametable_schema三个字段,分别为字段名、字段所在表名和表所在数据库。

4.order by关键字

select * from table_name order by 3——按第三列(第三个字段)排序
order by column_name asc/desc——升序/逆序

通常利用order by num和回显来判断该表有几个字段:若num=4时报错则说明该表有3个字段。

5.union操作符

两个查询返回的列数必须相同。
两个select语句对应列所返回的数据类型必须相同(或至少是兼容的)。

通常利用联合查询的特点,使原查询左边为空,使我们定义的查询结果返回出来。

如该表共3个字段,界面显示第2、3个字段,我们便可以构造:
select * from users where id=-1 union select 1,2,3 from users
这里的2,3可以换成任意想要的结果。

来自:https://www.jianshu.com/p/b5ab19751955的一段小知识点。

再补充:

发布了31 篇原创文章 · 获赞 35 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/weixin_39934520/article/details/104779724