当前位置:网站首页>XSS practice - cycle and two cycle problem at a time
XSS practice - cycle and two cycle problem at a time
2022-08-03 21:11:00 【hug kitten】
一次循环--demo6.html
<!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>
</head>
<body>
<form id=x>
<input id=attributes>
<input id=attributes>
</form>
</body>
<script>
console.info(x.attributes);
const data = decodeURIComponent(location.hash.substr(1));
const root = document.createElement('div');
root.innerHTML = data;
//这里模拟了XSS过滤的过程,方法是移除所有属性
for (let el of root.querySelectorAll('*')) {
for (let attr of el.attributes) {
el.removeAttribute(attr.name);
}
}
document.body.appendChild(root);
</script>代码分析
const data = decodeURIComponent(location.hash.substr(1)); #截取#号后面的值
const root = document.createElement('div'); #创建一个div
root.innerHTML = data; #然后将#The value after the number is assigned todiv
for (let el of root.querySelectorAll('*')) { #选中div下面的所有子元素
for (let attr of el.attributes) { #Get all attributes of child elements
el.removeAttribute(attr.name); #Delete all acquired properties
测试结果
我们传递了<img src=1 οnerrοr=alert(1)>

但是却发现src=1的属性被删除了,οnerrοr=alert(1)properties are still preserved,这是为什么呢?Let's first understand the deletion order here.We use breakpoint debugging to test the sequence of it

Let's first debug the situation to see the value step by step,通过断点调试,我们发现srcIt was removed after entering it as the first attribute,剩下的属性onerror仅一位,However, when the number of loops is greater than the number of strings, the attribute cannot be deleted.
我们使用一个pythonThe code tests the order in which elements are removed:

我们发现在a数组下,We just took out3个值,In anticipation we should take out6个值,This is why it should be deleted while looping.
这就有很大的问题,Because when deleting elements, we don't know which elements are deleted because of the index problem,So we only need to make multiple attempts to bypass a loop:
<img test=aaa src=1 title=bbb οnerrοr=alert(1)>

两次循环--demo4.html
<!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>
</head>
<body>
</body>
<script>
const data = decodeURIComponent(location.hash.substr(1));;
const root = document.createElement('div');
root.innerHTML = data;
// 这里模拟了XSS过滤的过程,方法是移除所有属性,sanitizer
for (let el of root.querySelectorAll('*')) {
let attrs = [];
for (let attr of el.attributes) {
attrs.push(attr.name);
}
for (let name of attrs) {
el.removeAttribute(name);
}
}
document.body.appendChild(root);
</script>
</html>The problem of the two loops is to put the attributes into an array first and then delete them,At this time, there is no one-cycle problem.
So we use two methods to bypass.
绕过方法1:DOM cobbing
The stuff that will enter the loop is not put into the code we need,That way it doesn't matter if you delete it
Then if we let the unused properties enter the loop,What is needed has not entered the loop yet?
tabindex:全局属性,指示其元素是否可以聚焦,and where does it participate in sequential keyboard navigation.使用Tab键获取焦点.
<form%20 tabindex=1 οnfοcus="alert(1);this.removeAttribute('onfocus'); "autofocus="true"><input name=attributes><input name=attributes></form>

这样就是将<form%20 tabindex=1 οnfοcus="alert(1);this.removeAttribute('onfocus'); "autofocus="true">Triggered,Deleted is the latter<input>里面的属性.
绕过方法2:不进循环
<svg><svg/οnlοad=alert(1)>
为什么一个<svg>没有成功,Two were successful?It can be before the filter code is executed,Execute malicious code ahead of time.
svg标签会阻塞DOM的构造.JSright in the environmentDOMThe operation again causes backflow,为DOMTree construction causes additional effects.在script标签内的JS执行完毕以后,DOM树才会构建完成,Only then will the following content be loaded,Then it will be triggered when an error is found in loading the contenterror事件.
That is, the malicious code has been executed before entering the loop,So it doesn't make sense whether to enter the loop or not.
边栏推荐
- Use setTimeout to realize setInterval
- LeetCode_Digit Statistics_Medium_400. Nth Digit
- Leetcode sword refers to Offer 15. 1 in the binary number
- glusterfs 搭建使用
- leetcode 16.01. 交换数字(不使用临时变量交换2个数的值)
- CC2530_ZigBee+华为云IOT:设计一套属于自己的冷链采集系统
- Why BI software can't handle correlation analysis
- 敏捷交付的工程效能治理
- 15年软件架构师经验总结:在ML领域,初学者踩过的五个坑
- 史兴国对谈于佳宁:从经济模式到落地应用,Web3的中国之路怎么走?
猜你喜欢

Likou 707 - Design Linked List - Linked List

肝完 Alibaba 这份面试通关宝典,我成功拿下今年第 15 个 Offer

华为设备配置VRRP与BFD联动实现快速切换

idea2021.1.3版本如何启动多个客户端程序

TweenMax.js向日葵表情变化

解决npm -v查看npm版本出现npm WARN config global `--global`, `--local` are deprecated. Use `--location报错

字节跳动软件测试岗,前两面过了,第三面HR天坑,结局透心凉...

有趣的opencv-记录图片二值化和相似度实现

Abs (), fabs () and LABS ()

idea2021配置svn报错Cannot run program “svn“ (in directory “xxx“):CreateProcess error=2,系统找不到指定的文件
随机推荐
Android build error: Plugin with id ‘kotlin-android‘ not found.
2022-8-3 第七组 潘堂智 锁、多线程
2022年1~7月语音合成(TTS)和语音识别(ASR)论文月报
How can a cloud server safely use local AD/LDAP?
ES6--剩余参数
ES6 deconstruction assignment - array object deconstruction and deconstruction
基于DMS的数仓智能运维服务,知多少?
Abs (), fabs () and LABS ()
4. 模块化编程
ES6简介及let、var、const区别
系统运维系列 之CSV文件读取时内容中包含逗号的处理方法
Leetcode 16. Numerical integral power (power + fast recursive/iteration)
ES6 introduction and let, var, const
XSS线上靶场---prompt
力扣707-设计链表——链表
Leetcode 899. An orderly queue
chart.js多条曲线图插件
canvas螺旋动画js特效
Markdown语法
leetcode 16.01. Swap numbers (swap the values of 2 numbers without using temporary variables)