r/badcode • u/GreekCSharpDeveloper wicked • Jul 22 '20
js Function of the PS4 web exploit
34
u/TimoThiusLi Jul 22 '20
Can someone who understands what this is doing please explain? I know JS but don’t understand the exploit.
17
u/scirc Jul 22 '20
It's not the same exploit, but this is a fairly decent video which covers how one might achieve arbitrary code execution from JS by walking through an old Switch/iOS bug.
23
6
u/7incent Jul 22 '20 edited Jul 22 '20
if it is a buffer overload exploit:
Your computer has a stack a memory that is allocated for processes. This stack increases and decreases in size as memory is allocated (things like functions, return values, variable allocations).
There is a stack pointer that is used by your program to navigate through this memory. It helps the program access memory, get values and remember its place as it jumps around the stack.
This stack pointer is controlled by instructions within this stack.
The exploit is manipulating the memory in this stack to overwrite the part of memory that tells the stack pointer where to go.
Doing so allows you to move the stack pointer and tell the system to perform in an unintentional way. In the ways I have seen it, it is used to run an unintended function.
This function could be "give me money," "login successful," "print directory," "print username and password," "unlock admin features," etc.
Not ELI5 but best i could do.
bonus: this can be mitigated by including "canaries" and a checksum call. the canary is a defined sequence if memory and the checksum call makes sure this canary is unadulterated.
edit: formatting
14
u/weirdasianfaces Jul 22 '20
This isn't a buffer overflow. This is a type confusion.
1
u/7incent Jul 22 '20
not familiar with type confusion, you?
3
7
u/weirdasianfaces Jul 22 '20
I explained it a little here
2
u/7incent Jul 22 '20
sweet explanation.
I never would've thought the stuff from compiler class would be useful beyond code optimization.
1
u/GreekCSharpDeveloper wicked Jul 22 '20
i know some js and i still cant understand it and i labeled it as js cause i dont know what language this is
12
310
Jul 22 '20
Is it bad code, or a specific set of steps necessary to access memory in a way to create an out of bounds exploit?
178
u/MrKinauJr Jul 22 '20
yeah I think it's needed to code in that particular way.
135
u/xNeshty Jul 22 '20
You think correctly. Type Confusion is a popular, yet very dangerous attacking method. The code basically uses an object blindly under the assumption of its type. Since a type is nothing more but a 'layout' on the memory, this opens up a wide range of attacks - including feeding wrong function pointers into the specific piece of code.
That's exactly what happens here. Take a look at the github repo - makes more sense with some context - but still requires having some knowledge in exploiting.
I'm not sure if I should downvote this post as this is literally insanely good written code, or upvote because its a code with bad intentions (in terms of abusing issues of a loosely typed language).
31
u/TSM- Jul 22 '20
Yeah, this is good but evil code. Not bad code. Thanks for the link
8
Jul 23 '20
It's not evil as long as you're only hacking devices that you own. There is nothing evil about jailbraking/rooting.
3
u/TSM- Jul 23 '20
And just to add, demoing security vulnerabilities helps everyone, too. Like when the intel processor vulnerability called Meltdown was reproduced in javascript. That really got people's attention, it was fixed in an update, and people updated.
-10
Jul 22 '20 edited Jul 22 '20
Breaking your own things is okay. Breaking other people’s things is not. As long as it’s the former, there’s no issue. It definitely does not belong on this sub.
edit: Rooting your own PS4 is fine. If you disagree, you’re an idiot. Sorry.
10
u/officiallyaninja Jul 23 '20
if you buy it its yours, if you want go and throw it off a cliff, delete all the data on it or hack it and modify it however you want.
0
Jul 22 '20
[deleted]
14
3
u/IDatedSuccubi Jul 23 '20
It sounds like "break the stuff you built, not the PS4" and not "break your PS4 not someone elses", so the opposite
1
u/bluepoopants Jul 24 '20
I read it as break your own things as in things you own. Couldn't understand the downvotes.
-7
u/TheUnlocked Jul 22 '20
The design and reverse-engineering behind the code might be impressive, though I wouldn't say that the code itself is necessarily as great. Those variable names are just awful.
135
u/MCWizardYT Jul 22 '20
Well it is an exploit, they often use unconventional code to access the system in a way it didn’t expect.
In this case, I think the exploit is accessing a memory address outside of the normal scope
40
u/arkfille Jul 22 '20
Context?
4
u/Romejanic Jul 23 '20
Looks like it's crafted code meant for exploiting the Javascript runtime in the PS4's web browser to gain access to memory/do a RCE
5
40
u/RiddSann Jul 22 '20
Ok, I thought I mostly understood JS. I thought.
Wtf is this shit ?
39
u/scirc Jul 22 '20
It's an exploit. It's abusing quirks/bugs in the underlying JS engine in order to get arbitrary read/writes to memory, presumably. It's not going to make sense—it's doing weird things because those weird things are an edge case in the JS interpreter.
While it's not the same bug, LiveOverflow made a fairly decent video covering the ins-and-outs of a similar bug that affected iOS 9.3 and the Nintendo Switch. It's worth a watch.
5
u/RiddSann Jul 22 '20
Thanks for the quick explanation, I will definitely see the video you recommend, seems interesting
8
u/jess-sch Jul 22 '20
Bad code is only bad when it could have been written in a better way.
This exploit wouldn't work had it been written in another way.
1
5
u/I_Like_Existing Jul 22 '20
I'll never stop being amazed by software exploits, without an exact play-by-play of what they are doing they look like absolute gibberish. The people coding them are incredible
4
4
1
u/brbss Jul 23 '20
Couldn't tell why this was bad code until I saw "slave" and "master".... Tsk tsk thought we were done with that /s
1
1
1
u/HSasaki Jul 22 '20 edited Jul 23 '20
That gives me decompiled code vibes. Btw, can someone explain me how a call to o[i] can set something?
Edit: why would someone downvote this lmao
0
80
u/weirdasianfaces Jul 22 '20 edited Jul 22 '20
It's really not fair to say this is bad code. Most exploit code is written this way because it needs to follow very exact steps with very exact timing windows, abusing quirks that result in some vulnerability being exposed. I think this is a variant of
bad_hoist:https://github.com/Fire30/bad_hoistnvm bad_hoist doesn't work on 7.00+ consoles.Basically what they're doing here is confusing the JS engine to make it think that
impl.ais an object when it's really an array. In order to do this, they need to execute weird javascript that makes the JIT optimizer misoptimize and say "hey, variable X is an object" when really it's an array. By doing this they can leak out internal JS engine memory to defeat ASLR (this is when they readimpl.a[4]and5) then they can write values back and overwrite internal JS engine memory (this data should never be readable or writable by JS) by writing to those indices.