我有一张搜索表:
<form method="POST">
<input type="search" name="q">
<input type="submit" value="Search" name="search">
</form>
然后在php文件中:
if( isset($_POST['q']) ){
//Assigning the posted query to a variable.
$query = $_POST['q'];
//Get matches from the DB.
$stmt = $conn->prepare('SELECT * FROM posts WHERE title OR description LIKE :s');
$stmt->bindValue(':s', '%' . $query . '%', PDO::PARAM_STR);
$stmt->execute();
$count = $stmt->rowCount();
//if there are matches.
if($count > 0){
//Get the matches.
$matches = $stmt->fetchAll();
foreach($posts as $post){
//Do Something.
}
}
}
现在一切都好了,我想,为什么我要这样做:
<input type="search" value="<?php if(isset($_POST['q'])){echo $_POST['q'];} ?>" name="q">
或:
<input type="search" value="<?php if(isset($query)){echo $query;} ?>" name="q">
可能导致袭击?
1条答案
按热度按时间6ie5vjzr1#
攻击者可以使用xss向不知情的用户发送恶意脚本。
例如,攻击者可以在其网站中创建一个表单,该表单被重定向到包含以下内容的您的地址:
通过使用这种方法,攻击者可以做一些简单但危险的事情。
最危险的事情之一是((复制和使用目标用户的cookie))。这意味着攻击者可以在其表单中键入此作为默认值:
正如你所见,黑客可以很容易地保存目标用户的cookie。。。
现在黑客有了用户的cookie(假设用户已经登录),所以他可以很容易地把这个放到浏览器的控制台中,以目标用户的身份登录!!:
为了更好地理解,您可以通过执行
document.cookie
在浏览器控制台中,执行以下操作将其粘贴到其他浏览器或pc:document.cookie="Put the copied cookie here"
请注意,每个网站和每次登录时保存的cookie是不同的,所以这很难,黑客需要一点机会来做到这一点:)p、 s:您可以按f12进入浏览器控制台。
如果你想让我用更多的代码来解释,就在评论中说:)