<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Javascript on System Overlord</title><link>https://systemoverlord.com/tags/javascript.html</link><description>Recent content in Javascript on System Overlord</description><generator>Hugo</generator><language>en-us</language><managingEditor>david@systemoverlord.com (David Tomaschik)</managingEditor><webMaster>david@systemoverlord.com (David Tomaschik)</webMaster><lastBuildDate>Mon, 02 Jun 2014 03:43:33 +0000</lastBuildDate><atom:link href="https://systemoverlord.com/tags/javascript/index.xml" rel="self" type="application/rss+xml"/><item><title>Secuinside Quals 2014: Javascript Jail (Misc 200)</title><link>https://systemoverlord.com/2014/06/02/secuinside-quals-2014-javascript-jail/</link><pubDate>Mon, 02 Jun 2014 03:43:33 +0000</pubDate><author>david@systemoverlord.com (David Tomaschik)</author><guid>https://systemoverlord.com/2014/06/02/secuinside-quals-2014-javascript-jail/</guid><description>&lt;p&gt;The challenge was pretty straightforward: connect to a service that&amp;rsquo;s running a Javascript REPL, and extract the flag. You were provided a check function that was created by the checker function given below:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#!javascript
function checker(flag, myRand) {
 return function (rand) {
 function stage1() {
 var a = Array.apply(null, new Array(Math.floor(Math.random() * 20) + 10)).map(function () {return Math.random() * 0x10000;});
 var b = rand(a.length);

 if (!Array.isArray(b)) {
 print(&amp;quot;You're a cheater!&amp;quot;);
 return false;
 }

 if (b.length &amp;lt; a.length) {
 print(&amp;quot;hmm.. too short..&amp;quot;);
 for (var i = 0, n = a.length - b.length; i &amp;lt; n; i++) {
 delete b[b.length];
 b[b.length] = [Math.random() * 0x10000];
 }
 } else if (b.length &amp;gt; a.length) {
 print(&amp;quot;hmm.. too long..&amp;quot;);
 for (var i = 0, n = b.length - a.length; i &amp;lt; n; i++)
 Array.prototype.pop.apply(b);
 }

 for (var i = 0, n = b.length; i &amp;lt; n; i++) {
 if (a[i] != b[i]) {
 print(&amp;quot;ddang~~&amp;quot;);
 return false;
 }
 }

 return true;
 }

 function stage2() {
 var a = Array.apply(null, new Array((myRand() % 20) + 10)).map(function () {return myRand() % 0x10000;});
 var b = rand(a.length);

 if (!Array.isArray(b)) {
 print(&amp;quot;You're a cheater!&amp;quot;);
 return false;
 }

 if (b.length &amp;lt; a.length) {
 print(&amp;quot;hmm.. too short..&amp;quot;);
 for (var i = 0, n = a.length - b.length; i &amp;lt; n; i++) {
 delete b[b.length];
 b[b.length] = [Math.random() * 0x10000];
 }
 } else if (b.length &amp;gt; a.length) {
 print(&amp;quot;hmm.. too long..&amp;quot;);
 for (var i = 0, n = b.length - a.length; i &amp;lt; n; i++)
 Array.prototype.pop.apply(b);
 }

 for (var i = 0, n = b.length; i &amp;lt; n; i++) {
 if (a[i] != b[i]) {
 print(&amp;quot;ddang~~&amp;quot;);
 return false;
 }
 }

 return true;
 }

 print(&amp;quot;stage1&amp;quot;);

 if (!stage1())
 return;

 print(&amp;quot;stage2&amp;quot;);

 if (!stage2())
 return;

 print(&amp;quot;awesome!&amp;quot;);
 return flag;
 };
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;As you can tell, there are two nearly identical stages that create an array of random length (10-30) consisting of random values. The only difference is in how the random values are generated: once from Math.random, and, in stage 2, from a function provided by the factory function. This function was not available to us to reverse the functionality of.&lt;/p&gt;</description></item></channel></rss>