xss漏洞学习笔记

1.存储型xss(恶意脚本被永久存储在目标服务器上,当其他用户访问包含该脚本的页面时触发)

test.html:

复制代码
<!DOCTYPE html>
<html>
<head>
    <title>xss1</title>
</head>
<body>
    <form action = 'comments.php' method='POST'>
        <textarea name='comment'></textarea>
        <button type='submit'>submit</button>
    </form>    
</body>
</html>

comments.php:

复制代码
php+HTML
<?php
    $comments=getCommentFromDB();
    foreach($comments as $comment){
        echo '<div>'.$comment.'</div>';//未转义直接输出
    }
?>

攻击载荷:<script>alert(0)</script>

2.反射型xss(恶意脚本作为请求的一部分发送到服务器,服务器立即响应返回并执行

test.html:

复制代码
<!DOCTYPE html>
<html>
<head>
    <title>xss1</title>
</head>
<body>
    <form action = 'comment.php' method='POST'>
        <textarea name='comment'></textarea>
        <button type='submit'>submit</button>
    </form>	
</body>
</html>

comment.php:

复制代码
php+HTML
<?php
    $comment=$_POST['comment'];
    echo '<div>'.$comment.'</div>';//未转义直接输出
?>

攻击载荷:<script>alert(0)</script>

3.dom型xss(漏洞完全在客户端发生,恶意脚本通过修改dom树来执行

test.html:

复制代码
<!DOCTYPE html>
<html>
<head>
    <title>xss2 dom</title>
<body>
    <input type="text" id ="input">
    <button onclick="display()">display</button>
    <div id="output"></div>
    <script>
        function display(){
            const userInput = document.getElementById('input').value;
            document.getElementById('output').innerHTML=userInput;//直接使用innerHTML插入数据
	}
    </script> 
</body>
</head>
</html>

攻击载荷:<img src=x οnerrοr=alert(0)>

原文地址:xss漏洞学习笔记

相关推荐
一隅论数智3 天前
给AI一张“业务概念地图“:本体如何从哲学走向企业智能
大数据·人工智能·经验分享·笔记·学习·学习方法·政务
XiHongShi20163 天前
STM32F407 RTC定时器例程,建议保存
stm32·单片机·学习
爱吃苹果的日记本3 天前
离散数学第六课
学习·离散数学
AI职业加油站4 天前
AI智能体应用工程师证书:政策红利下的职业新风口
大数据·运维·人工智能·学习·职场发展
深圳老胡4 天前
STM32F407 控制 L6470 步进电机驱动 —— 控制过程简介
笔记·stm32·单片机·嵌入式硬件·代码规范
旖旎夜光4 天前
力控面试题 01.01: 判定字符是否唯一(位运算) —— 题解
c++·学习·算法·leetcode·力控
奇思妙想聪明勤奋的小羊4 天前
DeepAgents第5章:子Agent 与上下文隔离—让 Agent学会委派
人工智能·python·学习·语言模型
Because_of_Her14 天前
并查集-听课笔记
笔记·算法·并查集
霍霍的袁4 天前
【C++】map 和 set 的使用 | 从用法到底层
开发语言·c++·学习·visual studio