【PHP】 简单的SQL注入Demo

SQL注入原理是通过字符串的拼接组合来实现黑客想要实现的结果

以下为一个简单的注入Demo,当用户名填写为 ' or 1=1# 的时候,SQL语句变为

select * from users where username='' or 1=1#' and password=''

#后面内容为注释,这句话就相当于 select * form users; 从而实现了注入效果


<html>
<head>
<title>Sql注入演示</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
</head>

<body >
<form action="" method="post">
    <fieldset >
        <legend>Sql注入演示</legend>
        <table>
            <tr>
                <td>用户名:</td>
                <td><input type="text" name="username"></td>
            </tr>
            <tr>
                <td>密  码:</td>
                <td><input type="text" name="password"></td>
            </tr>
            <tr>
                <td><input type="submit" value="提交"></td>
                <td><input type="reset" value="重置"></td>
            </tr>
        </table>
    </fieldset>
</form>
</body>
</html>

<?php

    if($_POST['username']){
        
        $conn=@mysql_connect("localhost",'root','') or die("数据库连接失败!");;

        mysql_select_db("test",$conn) or die("您要选择的数据库不存在");

        $name=$_POST['username'];

        $pwd=md5($_POST['password']);

        $sql="select * from users where username='$name' and password='$pwd'";

        echo $sql."<br><br>";

        $query=mysql_query($sql);

        $arr=mysql_fetch_array($query);

        if(is_array($arr)){

            echo "登陆成功!";

        }else{

            echo "您的用户名或密码输入有误,请重新登录!";

        }
    }

?>

原文链接 http://www.php100.com/html/webkaifa/PHP/PHPyingyong/2012/0210/9803.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值