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漏洞学习笔记

相关推荐
摇滚侠18 小时前
《SpringBoot 3:入门与应用实战》第 13 章 整合 MyBatis MyBatis 概述 阅读笔记 37
spring boot·笔记·mybatis
是隼人18 小时前
buuctf-pwn PWN1题解(学习过程持续更新)
c语言·学习·安全·pwn入门·ctf入门
HugoStudio_SWAN18 小时前
洛谷 P1321 单词覆盖还原——从蜡板上的密信到数字水印
c++·学习·程序人生·算法
春风解人意18 小时前
从零开始学习嵌入式P33----网络基础之HTTP
网络·学习·http
励志不掉头发的内向程序员19 小时前
【LibreCAD 2D架构】从鼠标点击到屏幕像素:LibreCAD绘图架构全链路解析之Action与命令系统
linux·开发语言·c++·qt·学习·系统架构
小道士写程序19 小时前
自然语言处理NLP - 第8章 词向量与神经网络:从手工特征到学习表示
神经网络·学习·自然语言处理
摇滚侠19 小时前
《SpringBoot 3:入门与应用实战》第 13 章 整合 MyBatis 整合 MyBatis 阅读笔记 38
spring boot·笔记·mybatis
m4Rk_19 小时前
【论文阅读】Agent 记忆机制(59):Synapse——让相关记忆沿情景—语义图被逐步激活
论文阅读·人工智能·学习·开源·github
风123456789~20 小时前
【架构专栏】4.8 信息安全的保障体系与评估方法 4/4
笔记·系统架构设计
William一直在路上20 小时前
MCP 规范版本对比:2025-11-25 vs 2026-07-28
学习·ai·llm