天天看点

SQL注入中information_schema

实验简介

实验所属系列:WEB安全应用

实验目的

通过本次实验,掌握SQL注入中,通过information_schema这个数据库爆库名、表名以及字段名的原理。

实验环境

windows 7、安装wamp环境

预备知识

MySQL语法:https://dev.mysql.com/doc/refman/5.7/en/select.html

MySQL查询数据:http://www.runoob.com/mysql/mysql-select-query.html

实验步骤

在phpmyadmin中,在左侧点击information_schema数据库。 展开后如下图,显示了该数据库中的所有表

 也可以执行如下SQL语句来查看该库中的所有表:

      show tables;

SQL注入中information_schema

想要查看数据库的数据保存目录,可以执行select @@datadir

SQL注入中information_schema

双击桌面的WampServer运行。弹出来的列表中点击MySQL,再选择MySQL控制台。

SQL注入中information_schema

 弹出一个命令行窗口,这就是mysql客户端,此时要求输入密码,root的密码为空,直接回车

SQL注入中information_schema

 使用命令use information_schema,进入information_schema 数据库

首先执行show databases;查看所有的数据库,然后再执行select schema_name from schemata;。

执行desc tables,看表结构

SQL注入中information_schema

 执行select count(*) from tables;,查看有多少条记录

SQL注入中information_schema

 当前数据有142条

SQL语句为:select * from tables limit 141,1\G 查询任意一条语句

SQL注入中information_schema

 查看sqli数据库中的表,SQL语句为:show tables from sqli;

SQL注入中information_schema

想要通过information_schema数据库来查询sqli数据库中所有的表,使用如下SQL语句:

      select TABLE_NAME from information_schema.TABLES where TABLE_SCHEMA = 'sqli';

SQL注入中information_schema

 desc COLUNMS 语句

SQL注入中information_schema

 首先确定该表有多少条记录,执行select count(*) from colum

查询最后一条语句

SQL注入中information_schema

 查看sqli的user表是否存在该字段,执行SQL语句:show columns from sqli.user;

SQL注入中information_schema

通过information_schema数据库的columns表查询sqli数据库中user表中所有的字段,可以执行如下SQL语句:

      select column_name from information_schema.columns where TABLE_SCHEMA='sqli' and TABLE_NAME='user';

SQL注入中information_schema

 查询结果一致。

分析与思考

为什么网上的SQL注入语句中,数据库名都是用的字符的16进制值、

在处理sql注入时,我们通常对完整的ASCII码范围不感兴趣,因为并非所有字符在数据库中都是有效或者是允许的,因为这我么们只关注ascii码范围在32~126,他留下了一个94个字符。该范围用7位表示。

SQL注入中information_schema

为什么网上的SQL注入语句中,数据库名都是用的字符的16进制值?