douyi1779 2017-09-09 18:29
浏览 64
已采纳

localhost上的SQL注入不起作用

So I'm trying to design a very simple and vulnerable website to demo how an SQL injection works, but when I attempt an injection with

');SELECT * FROM users;--

I get an error message stating:

Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT * FROM users;--')' at line 1

Source code is as follows :

welcome1.html:

<form action="test.php" method="get">  
  <div><label for="firstname">First name:  
    <input type="text" name="firstname" id="firstname"/></label>  
  </div>  
  <div><label for="lastname">Last name:  
    <input type="text" name="lastname" id="lastname"/></label></div>  
    <div><label for="email">E-mail : 
    <input type="text" name="email" id="email"/></label></div>  
    <div><label for="password">password:  
    <input type="text" name="password" id="password"/></label></div>  
  <div><input type="submit" value="GO"/></div>  
</form>

test.php:

<html>
<body>
 
 
<?php
$con = @mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect ' . mysql_error());
  }
 
mysql_select_db("accounts", $con);
$firstname = $_GET['firstname'];  
$lastname = $_GET['lastname']; 
$email = $_GET['email'];  
$password = $_GET['password']; 
$sql="INSERT INTO users(firstname, lastname, email, password)
VALUES
('$firstname','$lastname','$email','$password')";



if(!mysql_query("INSERT INTO users(firstname, lastname, email, password) VALUES ('$firstname','$lastname','$email','$password')"))
  {
  die('Error: ' . mysql_error());
  }

echo "1 record added";
 
mysql_close($con)
?>
</body>
</html>

running on WAMP server 3.0.6 on win10 I'm a noob when it comes to html/php if it wasn't obvious thanks

</div>
  • 写回答

1条回答 默认 最新

  • doudg60800 2017-09-09 18:36
    关注

    The kind of SQL injection you are attempting will not work with the mysql_query() API. That API doesn't support multi-query, so you can't execute two statements in one call to mysql_query(). It's a syntax error for the SQL to contain any content after the semicolon (;).

    It would work with mysqli_multi_query(). See also http://php.net/manual/en/mysqli.quickstart.multiple-statement.php

    Also with PDO, which IIRC does support multi-query by default in PDO::query().

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
  • ¥15 python爬取bilibili校园招聘网站
  • ¥30 求解达问题(有红包)
  • ¥15 请解包一个pak文件
  • ¥15 不同系统编译兼容问题
  • ¥100 三相直流充电模块对数字电源芯片在物理上它必须具备哪些功能和性能?
  • ¥30 数字电源对DSP芯片的具体要求
  • ¥20 antv g6 折线边如何变为钝角
  • ¥30 如何在Matlab或Python中 设置饼图的高度
  • ¥15 nginx中的CORS策略应该如何配置