xss攻击反面教材
蚌埠住了,今天看了下xss攻击,就手痒想试试,结果出问题了;
基本情况就是:
利用一个input和button模拟用户输入,利用一个div模拟评论区,
打算在输入框里输入js,预期结果是往评论区里植入一个div;
结果代码放在script里可以跑,放在输入框里就跑不起来,
各位大佬给我看看,就当练习吧。
废话不多说,上代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.submit{
background-color:rgb(0, 255, 106);
}
.content{
width: 400px;
height: 400px;
border: 1px solid red;
}
</style>
</head>
<body>
<div>
<input type="text" name="" id="">
<button class="submit" onclick="submit()">提交</button>
<div class="content"></div>
</div>
</body>
<script>
let inp = document.getElementsByTagName('input')[0];
let but = document.getElementsByClassName('submit')[0];
let content = document.getElementsByClassName('content')[0];
let submit= function(){
content.innerHTML=inp.value;
console.log('提交成功');
let node=document.createElement('div'); //新建节点
node.innerText='我是新建的节点div' ;
node.style.height=100+'px';
node.style.width=100+'px';
node.style.backgroundColor='red';
content.appendChild(node); //添加节点
}
</script>
</html>
往输入框里输入:
<script> let node=document.createElement('div');
node.innerText='我是新建的节点div' ;
node.style.height=100+'px';
node.style.width=100+'px';
node.style.backgroundColor='red';
content.appendChild(node); </script>
但是什么也没有发生。。。。。。