[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
I think I managed to create a piece of Javascript that I could
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 17
Thread images: 1
File: Untitled.png (18 KB, 640x400) Image search: [Google]
Untitled.png
18 KB, 640x400
I think I managed to create a piece of Javascript that I could use to run untrusted javascript securely in someone's browser. However, I think there's no such thing as secure untrusted javascript execution. Can the wizards around here tell me how they'd break this?
// Checks whether the arg is a valid argument identifier
var filter = function (x) {
var any = "$a-zA-ZÀÈÌÒÙàèìòùÁÉÍÓÚÝáéíóúýÂÊÎÔÛâêîôûÃÑÕãñõÄËÏÖÜäëïöüçÇßOoÅåÆæÞþÐð";
var y = x.match("^[" + any + "][\\d" + any + "]*$");
return !!y;
}

// Creates a function that doesn't have access to the navigator/window/document
var safeFn = function (str) {
try {
// Check whether the code is syntaxically correct
new Function(str);
// Create a function that has everything forbidden as an argument
var str = "return (function(arg," + Object.getOwnPropertyNames(window).filter(filter).join() + "){ " + str + " ; })(arguments[0]);";
return new Function(str);
} catch (e) {
return e;
}
};

var x = safeFn("return arg + 1");

The only thing you can do is set the content of the "str" variable. How would you gain access to cookies/DOM/XMLHttpRequest?
>>
Fuck off with your homework.
>>
>>54766866
>Impossible task
>Homework
You haven't even taken the time to look at the problem at hand, retard.
>>
>>54766738
>plz help me with muh homewo... huh... challenge

FUCK OFF
>>
>>54766913
>>54766890
>>
>>54766738
Using
new Fonction()
is terribly unsecure. But I have to admit that other that finding a path to the Window object by navigating through the prototype chain of
arguments 
I don't see where there could be an exploit. What do you plan on doing with this ?
>>
>>54766987
>What do you plan on doing with this ?
Navigating through the prototype chain of arguments to find a path to the Window object and submitting it to my professor as a homework solution.
>>
>>54766987
I'm thinking about creating a website where you could code an AI for a game in live and have it fight other AIs. You could update the code in realtime and things like that. That's why I need to be able to execute untrusted code securely.
>>
>>54766987
>finding a path to the Window object by navigating through the prototype chain of arguments
There's no path, though.
>>
>>54767018
Check out vindinium.org. It's not "live coding" but it might give you a few ideas.
Also do take a look at https://alexnisnevich.github.io/untrusted/, it's all done un JavaScript and prevents the player from tampering too much with the game's internals.
>>
>>54767119
I already knew of both untrusted and vindinium. Didn't think about looking at untrusted's code, though. Thanks.
>>
>>54767119
Oh man, the validation of untrusted.js is shit. It checks for "forbidden" words and just prevents code from being run. Can't use that shit.
>>
>>54766738
If not in strict mode you should be able to access window by doing:
(function(){return this})()

On mobile, so I can't check.
>>
>>54767385
Nope - returns an anonymous function even without strict mode.
>>
>>54767430
Like this:
safeFn("return (function(){return this})()")().alert(1)
>>
>>54767686
Oh, well done. I'll keep on doing terrible hacks until I admit that I have to create my own interpreter, then.
Thanks !
>>
>>54767713
A bit late, but strict mode plus binding the returned function to e.g. null would prevent it I think.
Thread replies: 17
Thread images: 1

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.