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

相关推荐
demodeom26 分钟前
Win11 + RTX 5080 本地 Coding 模型测试笔记(已弃坑)
笔记
peijiping1 小时前
Agent 工具执行:并行(parallel_tool_calls)和后台(run_in_background)到底有什么区别? (学习笔记)
笔记·学习·ai agent·claude code
Oll Correct1 小时前
Adobe illustrator 案例四:吃豆人 (Pac-Man)图标绘制
笔记·ui·adobe·illustrator
何事误红尘1 小时前
KF32A学习笔记(二):IDE基本使用、srec和hex格式、FreeRTOS移植
学习
LuminousCPP1 小时前
单链表专题(四)-刷题复盘篇-LeetCode 138 随机链表复制|原地拷贝法突破复杂指针操作
数据结构·笔记·算法·leetcode·链表
萌新小白YXY2 小时前
SAE J1587/SAE J1708 协议笔记
笔记·单片机·嵌入式硬件
IT古董2 小时前
【MES学习笔记系列】MES 推荐书籍与资源
笔记·学习
迪丽热爱2 小时前
每日英语-11
学习
一米阳光86612 小时前
软考(中级)软件设计师核心笔记(9)算法——时间复杂度与空间复杂度、查找算法、排序算法
笔记·算法·职场发展·软考·软件设计师·中级职称
米饭不加菜2 小时前
常用基本求导公式与法则(超详细推导版——上)
经验分享·笔记