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

相关推荐
nnsix1 小时前
Unity 动态批处理、静态批处理、GPU Instaning、SRP Batcher 笔记
笔记·unity·单一职责原则
情绪总是阴雨天~1 小时前
OCR光学字符识别技术:完整原理与实战学习笔记
笔记·学习·ocr
searchforAI1 小时前
B站视频怎么转文字稿?AI自动总结要点+生成思维导图教程
人工智能·笔记·学习·ai·语音识别·知识管理·视频总结
只做人间不老仙1 小时前
C++ grpc 拦截器示例学习
开发语言·c++·学习
踏着七彩祥云的小丑1 小时前
Go学习第7天:Map集合 + 递归函数 + 类型转换
开发语言·学习·golang·go
me8321 小时前
【AI】Langchain4j开发学习笔记
人工智能·笔记·学习
LuminousCPP1 小时前
数据结构 - 单链表第一篇:单链表基础操作
c语言·数据结构·经验分享·笔记·学习
juesdo1 小时前
青岑CTF web入门 EZCMD系列
web安全·网络安全·php
wubba lubba dub dub7501 小时前
【无标题】
学习