利用SQL注入漏洞登录后台

发表于:2012-2-10 09:45

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:MarcoFly    来源:51Testing软件测试网采编

  接下来,贴上登录界面的源代码:

  1. <html>  
  2. <head>  
  3. <title>Sql注入演示</title>  
  4. <meta http-equiv="content-type" content="text/html;charset=utf-8">  
  5. </head>  
  6. <body >  
  7. <form action="validate.php" method="post">  
  8. <fieldset >  
  9. <legend>Sql注入演示</legend>  
  10. <table>  
  11.        <tr>  
  12.               <td>用户名:</td><td><input type="text" name="username"></td>               
  13.        </tr>  
  14.        <tr>  
  15.               <td>密&nbsp;&nbsp;码:</td><td><input type="text" name="password"></td>  
  16.        </tr>  
  17.        <tr>  
  18.               <td><input type="submit" value="提交"></td><td><input type="reset" value="重置"></td>  
  19.        </tr>  
  20. </table>  
  21. </fieldset>  
  22. </form>  
  23. </body>  
  24. </html>

  附上效果图:

  当用户点击提交按钮的时候,将会把表单数据提交给validate.php页面,validate.php页面用来判断用户输入的用户名和密码有没有都符合要求(这一步至关重要,也往往是SQL漏洞所在)

  代码如下:

  1. <html>  
  2.  
  3. <head>  
  4.  
  5.        <title>登录验证</title>  
  6.  
  7.        <meta http-equiv="content-type" content="text/html;charset=utf-8">  
  8.  
  9. </head>  
  10.  
  11. <body>  
  12.  
  13. <?php  
  14.  
  15.        $conn=@mysql_connect("localhost",'root',''or die("数据库连接失败!");;  
  16.  
  17.        mysql_select_db("injection",$conn) or die("您要选择的数据库不存在");  
  18.  
  19.        $name=$_POST['username'];  
  20.  
  21.        $pwd=$_POST['password'];  
  22.  
  23.        $sql="select * from users where username='$name' and password='$pwd'";  
  24.  
  25.        $query=mysql_query($sql);  
  26.  
  27.        $arr=mysql_fetch_array($query);  
  28.  
  29.        if(is_array($arr)){  
  30.  
  31.               header("Location:manager.php");  
  32.  
  33.        }else{  
  34.  
  35.               echo "您的用户名或密码输入有误,<a href=\"Login.php\">请重新登录!</a>";  
  36.  
  37.        }  
  38.  
  39. ?>  
  40.  
  41. </body>  
  42.  
  43. </html>

32/3<123>
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号