TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Executing non-alphanumeric JavaScript without parentheses

123 点作者 kkl将近 9 年前

8 条评论

drostie将近 9 年前
Ctrl-F template strings... yep, there they are.<p>So if you didn&#x27;t know, ES6 added template strings, which are these really awesome things because they have multiline and string interpolation capabilities (and they&#x27;re safely far away from JSON, which in my opinion shouldn&#x27;t have such capabilities). They are very pretty and incredibly handy; you write<p><pre><code> console.log(` I&#x27;m so ${scared} in case ${ I.fall.off() } my chair And I&#x27;m wonderin&#x27; how I&#x27;ll get down the stair `); </code></pre> and this gets converted into<p><pre><code> console.log(&quot;\nI&#x27;m so &quot; + scared + &quot; in case &quot; + I.fall.off() + &quot; my chair\nAnd I&#x27;m wonderin&#x27; how I&#x27;ll get down the stair\n&quot;); </code></pre> Except for one thing: they&#x27;re called &quot;template strings&quot; because actually this is a sort of &quot;default behavior&quot; which can be metaprogrammed. There is a default interpreter which could be written:<p><pre><code> function interpret(text_segments, ...split_segments) { var out = &quot;&quot;; for (var i = 0; i &lt; split_segments.length; i++) { out += text_segments[i] + split_segments[i]; } return out + text_segments[i]; } </code></pre> but... you can write one of your own, if you want, and put it on the beginning. Therefore:<p><pre><code> &gt; console.log(`abc ${[1,2,3]} def`) abc 1,2,3 def undefined &gt; console.log `abc ${[1,2,3]} def` [ &#x27;abc &#x27;, &#x27; def&#x27; ] [ 1, 2, 3 ] undefined </code></pre> Notice that the side effect of console.log has happened with the arguments given to it, allowing for code execution.<p>As for mitigation... add detection of backticks to whatever code was detecting parentheses. It&#x27;s not a very widely used symbol in any context other than shell scripting and LaTeX anyways, so you&#x27;re probably good to go if you just outlaw that character before calling eval() on the whole.
评论 #12103477 未加载
评论 #12104400 未加载
taternuts将近 9 年前
Spent a couple minutes figuring out how to spell &quot;butts&quot;:<p>[[]+{}][+[]][++[[]][+[]]+[++[[]][+[]]][+[]]]+[!![]+[]][+[]][++[[]][+[]]+[++[[]][+[]]][+[]]]+[!![]+[]][+[]][+[]]+[!![]+[]][+[]][+[]]+[![]+[]][+[]][++[[]][+[]]+[++[[]][+[]]][+[]]+[++[[]][+[]]][+[]]]
nubs将近 9 年前
I&#x27;ve done something similar with PHP, by casting an array to a string (The string &quot;Array&quot;) and using &quot;variable variables&quot;. If only there was a way to call functions in PHP without using letters in the code... <a href="https:&#x2F;&#x2F;gist.github.com&#x2F;nubs&#x2F;5849633#file-nodigitsorquoteseither-php" rel="nofollow">https:&#x2F;&#x2F;gist.github.com&#x2F;nubs&#x2F;5849633#file-nodigitsorquotesei...</a>
评论 #12102558 未加载
amarpatel将近 9 年前
I found this article had more depth: <a href="http:&#x2F;&#x2F;patriciopalladino.com&#x2F;blog&#x2F;2012&#x2F;08&#x2F;09&#x2F;non-alphanumeric-javascript.html" rel="nofollow">http:&#x2F;&#x2F;patriciopalladino.com&#x2F;blog&#x2F;2012&#x2F;08&#x2F;09&#x2F;non-alphanumeri...</a>
评论 #12103079 未加载
评论 #12102029 未加载
posterboy将近 9 年前
what&#x27;s the use case? Circumventing code insertion filters?
评论 #12102202 未加载
评论 #12102160 未加载
sarreph将近 9 年前
This article did give me the <i>out-loud-at-the-office</i> chuckle and a whispered &quot;what the f°°°&quot; that only awe-inspiring hacks far above my programming intelligence level can provoke. :)
jerluc将近 9 年前
Reminds me of Church encoding or even iota reductions, where you reduce a set of higher level symbols to primitive symbols that in combination have provably the same meaning.
Retr0spectrum将近 9 年前
If you want to automate this process: <a href="http:&#x2F;&#x2F;www.jsfuck.com&#x2F;" rel="nofollow">http:&#x2F;&#x2F;www.jsfuck.com&#x2F;</a>
评论 #12101881 未加载