TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Executing non-alphanumeric JavaScript without parentheses

123 pointsby kklalmost 9 years ago

8 comments

drostiealmost 9 years ago
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 未加载
taternutsalmost 9 years ago
Spent a couple minutes figuring out how to spell &quot;butts&quot;:<p>[[]+{}][+[]][++[[]][+[]]+[++[[]][+[]]][+[]]]+[!![]+[]][+[]][++[[]][+[]]+[++[[]][+[]]][+[]]]+[!![]+[]][+[]][+[]]+[!![]+[]][+[]][+[]]+[![]+[]][+[]][++[[]][+[]]+[++[[]][+[]]][+[]]+[++[[]][+[]]][+[]]]
nubsalmost 9 years ago
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 未加载
amarpatelalmost 9 years ago
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 未加载
posterboyalmost 9 years ago
what&#x27;s the use case? Circumventing code insertion filters?
评论 #12102202 未加载
评论 #12102160 未加载
sarrephalmost 9 years ago
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. :)
jerlucalmost 9 years ago
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.
Retr0spectrumalmost 9 years ago
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 未加载