March 2009

You are currently browsing the monthly archive for March 2009.

April 2nd  

There’s a small buzz going on on various PSP sites regarding April 2nd.
You might randomly see some people’s signature on forums waiting for “April 2nd”.

Since a few people asked me what this could possibly means, well, here is the answer.

Have you ever wondered what the “M33″ means in the name of the custom firmware that is installed on your dear PSP? Well it means “March 33rd”, which happens to be “April 2nd”. (march 33 is also the name of a terrorist group in the videogame “conflict-Global Terror”)

Does this mean that Dark-Alex will have the answer to all PSP3000 owners in 4 days? Probably not, so don’t hold your breath, but hey, I myself can’t help but hoping something will happen :D

On a related note, I’ve been receiving lots of gamesave files and various crash notifications to test with psplink since I’ve published this article on how to look for gamesave exploits.
I’m happy to get those, so keep’em coming, but don’t be offended if I don’t reply to you or if I don’t find the time to even test your stuff. Time is a precious thing that I unfortunately lack. The best piece of advice I can give you if you want things to move, is to try by yourself if possible. This is how you will learn how to use all the available tools and go further.

I know I don’t have the same skills as people who’ve been doing that for years now, but be sure that whenever one of those crashes seems interesting enough, I try to let the right people know about it.



The windows version is now available in the download section. Check the README for details on the controls. You NEED the psp version too, as you have to copy the contents of the Res directory from the PSP version to the windows version. Also, you might need the Microsoft Visual C++ 2005 SP1 Redistributable Package (see link on the download page).

Advantages of the windows version over the PSP version include: fullscreen mode, and better quality images support.

A way for people who don’t have a CFW on their PSP to enjoy Wagic :)

For the first time, I didn’t announce the release of this new version on my blog but on a different website.
The reason is that I came across the Neoflash Spring competition a few days ago and decided to give a try at this contest with Wagic.

Apparently, anyone can vote, so if you want to try new homebrew games AND show your support to whichever one is your favorite (hint: it starts with a “W” ;) ), it’s a great opportunity. No, seriously, there seems to be great games this year too!

This contest is also the reason why this version is probably not as polished as I wished, because I had to compile and test in a hurry (Note that I didn’t do a public beta this time, but many thanks to Dr.Solomat and leungclj for their help! I promiss, I won’t do last minute stuff like that again).

We already found a few bugs in this release, some of them that have been here for ages, other ones that are new, but nothing that prevents the game from being playable, and nothing that prevents it to be even better than the previous version. Anyways, if you find bugs, you know you can yell at me.

So what’s in this release?

Well, first, it seems it’s not always clear what this game does, so let’s start with a quick reminder:

Wagic is an heroic-fantasy game in which you battle as a sorcerer against your PSP. It is based on the rules of a very famous collectible card game. In Wagic, you create a deck of creatures and spell cards, then play with this deck against the AI’s decks. As you win battles, you earn credits that you can spend in the Shop to buy more cards and improve your deck.

Changelog for version 0.5.1:

  • More than 300 new cards, including news Sets (Lorwyn, Invasion, Mirage). Special Thanks to Dr.Solomat and leungclj!
  • A new difficulty mode has been added… but you need to unlock it, and I won’t tell you how ^_^ (congrats to the first one who’ll get access to the difficult mode)
  • Bug fixes for persist, shroud, Ardakar wastes, Ankh of Mishra, Ascendant Evincar, Castle, Dingus Egg, Druid of the Anima, Farmstead, icatian priest, Spirit weaver, Kird Ape, Sedge Troll, Unsummon, …
  • New parser keywords:foreach(see plague rats in RV) and aslongas(see blanchwood armor in 10E)
  • The AI can now use a few activated abilities. Actually, most of them (except mana abilities that are not on lands), but with no strategy yet :)

Screenshots

download

 

 

 
download page
 

Important: This article is NOT related to Matiaz’s “eggsploit” but to another vulnerability discovered months before that.

Ok, so I brag about how you can find exploits, yet I’ve been very quiet myself about my own attempts at it. Well that’s because I’ve not been successful so far. This post is a mix of bad news and good news, so read on if you’re interested.

What is this about?

A few months ago, I came across a bug in the libtiff library. As you may or may not know, the PSP uses this library for TIFF images decoding. This bug has been half-patched (I’ll talk about the “half” part later in this article) in firmware 4.21, but this was interesting because the first PSP3000 packages shipped with firmware 4.20.

If you want to read more about this, please go to lan.st, that’s where everything’s explained.

The point is, there was a buffer underflow vulnerability, and that was a possibility to have an exploit.

Why isn’t there a Proof of concept yet?

This one is easy: I never managed to turn the bug into an exploit. However I am so close that it gets on my nerves. I decided that I spent too much time working on this so I gave up, but I still have the hope that someone might use this successfully (as a matter of fact, someone DID use this successfully).

Here’s what’s going on on the PSP:

First we launch usbsfhost_pc.exe and psph.exe on the PC. On the PSP, we launch PSPLINK from the Game menu. In pspsh, we need to type the following commands to start the XMB from PSPLink:

Now that this is done, I am in the XMB, and I go to the photo folder, that contains the crafted tiff file. I do that the same way as I did in my youtube video (except I’m doing all that with PSPLink running, remember?)

What happens when the PSP crashes? Well, the following:

as you can see, my crafted value ends up in $v1 (0×61616161), and the PSP crashes when it tries to load something from an address that doesn’t exist (0x616161B9, which is 0×61616161+88).

Ok, but wait, there’s nothing interesting here, right? I told you recently that we need $ra or $sp to contain cool values, correct? Yeah, well, as I told you, it’s always better to look at the code to make sure of what’s going on. The code crashed at address 0x09B25584 (that’s the value of the EPC), so let’s see what it looks like there.

Ok, so the code loads a value into $v0 by reading it at [contents of $v1]+88, and then performs a jump at… $v0!!! So that’s it, I’ve got my jump!

If I can craft my image to put 1) a real address instead of 0×61616161 (for example, 0×08800000), and, at this address, another real address (say, 0×08900000), well I can have the code jump to 0×08900088.

Now let me tell you a secret, it’s quite easy to do that, I’ve done it, and you can do it too if you play with the inject.rb file (link at the end of the post)

I can jump to an arbitrary address, so what’s the problem?

Well… there are 2 issues actually. The first one is that even if I can jump to wherever I want, I didn’t find any way to inject code at a specific location yet. I tried to load other images before the crafted tiff, it only half worked, and the code never ends in a reliable position in memory. I tried the tiff itself, but theoretically it cannot accept more than 256 bytes of code, and practically, I never managed to input more than 30-40 bytes in it. It’s close to impossible to have something running with so little flexibility.

The second issue is that I didn’t show you the whole dump… there is actually another thread crashing. And when a thread crashes, the PSP shuts down.

So even if I could solve the first issue (where to put the code), this thread would still crash, and take the PSP down with it. So what is this thread ? Well that’s easy, it’s the decoding thread, the exact same one I’m using to create the underflow.

As I am in an infinite loop, the underflow never stops, and end up trying to write to an invalid address (0x087FFFFF… 0×08800000 being the beginning of the user RAM)

So what needs to be done?

Easy: find a reliable way to input code into RAM before using the crafted tiff. (With a crafted png that we display just before the tiff? a crafted mp3 that plays while we look at the image? There are probably dozens of solutions for that, but I could’nt find anything reliable).

Once this is done, I guess the first thing the code should do is stop the underflow, by changing the code that decreases the value of $a0 into something less dangerous such as a nop.

As I said, easy, right? Well, I don’t know how to do all this. Stopping the underflow shouldn’t be too big of an issue once we know where to put code to run…but that’s the issue right now.

And what about firmwares above 4.20? I saw a crash on 5.02 too!

The fact is that the bug hasn’t been correctly solved. However, it’s been patched enough to prevent anything useful from happening with this vulnerability beyond firmware 4.20

download

libtiff crash 4.20

This is an article to help you recognize an exploitable vulnerability (e.g MaTiAz’s Gripshift) from a non exploitable (or at least, not easily enough) crash (e.g. yyoossk’s Phantasy star). Is think it can also be seen as a rough tutorial on “how to look for gamesave exploits on the PSP”

If, as me, you badly want your psp3000 to be hacked, it is likely that you follow closely what happens on PSP dedicated websites.
From time to time, some random guy pops up on a forum with an “idea” on how to hack the PSP, or, on better days, someone comes up with a savegame that crashes the PSP, in the hope that it will be useful. Reporting a crash is actually a good thing to do, crashes are the first step to an exploit, and if they don’t lead to an exploit, at least it can help Sony to improve their product ;)

Recently, a guy nicknamed yyoossk tried to reproduce what MaTiAz had done with Gripshift, in the Japanese Demo of “Phantasy star portable” (see here and here). Wow, an exploit in a demo, that would be very cool, no need for expensive ebay UMDs!!! This is why I decided to give it a try. I will try to explain in this article why his crash is only a crash and will probably never be turned into an exploit.

I will compare the Phantasy star portable crash to what happens with the Gripshift exploit.
Before I start, you have to know that I don’t claim to be the best hacker or programmer in the world. I’m just a bit above the “complete Noob” level, with enough experience in IT to understand what I see on my screen. So this text might be inaccurate on some parts.

To read this article, you need strong understanding of basic programming concepts such as variables, addresses, and arrays. You should also have a browser window open on the MIPS assembly list of commands. MIPS assembly knowledge is not really required if you know the basics of programing, but it sure helps to have a general idea of what assembly language is.

The basics of a savegame exploit

Most savegame exploits rely on the concept of “buffer overflow”, which consists in writing more data in an array than you should. For example, if you have an array of size 10, and try to write 11 elements in it, you’ll have a buffer overflow of 1 element. What happens in that case is that you write somewhere in memory you weren’t supposed to, and this can give interesting results that I will talk about later. For more information on buffer overflows, please read this article.

Now, a very popular way of looking for buffer overflows (in savegames but not only) is to put a very long string somewhere. Strings are often represented as an array of char, and are therefore a very easy target. Moreover, a string such as the player name is usually very easy to identify in a decrypted savegame file. You can’t easily tell which number represents the amount of gold coins you have in your inventory, but it is very easy to look for “wololo” inside the file.

Once this string is located, the first step is to try and put a very long name in there. This is what MaTiAz did with gripshift (“spartaaaaaaaaa”), and probably what was attempted in the Phantasy star crash too.

Of course, you cannot do this through the game itself (the interface won’t allow you to input more than, say, 10 characters), so to do this you have to decrypt your savegame, edit the decrypted version, then reencrypt it. A tool such as savegame-deemer is very useful in that case, since it allows you to work directly on decrypted savegames without worrying about the decryption/encryption process.

So basically, you put some garbage into a savegame file, and try to see if this makes the game crash. In most cases, the game will not crash, but simply tell you that your save data is invalid. Game over, you won’t find any exploit with this game and this method (it doesn’t necessarily mean that the game doesn’t have any flaw, just that you’ll have to think more, but that’s beyond what I want to explain in this article)

But what if the game crashes when loading your data? Well it means some programmers didn’t do their job properly, and there is a vulnerability in the game. IT DOESN’T MEAN THERE IS AN EXPLOIT YET, right now it is just a bug. To see if it is interesting for us, we have to run it through PSPLink and analyze the error dump.

Launching the game in PSPLink

This is where the difficulty starts. For that you’ll need a PSP with a custom firmware, and PSPLink installed. I won’t go into the details of installing PSPLink, they can be found pretty much everywhere. PSPLink comes with a few prx files. We need to use PSPLink as a plugin because we will be launching a game. Long story short, you need to have usbhostfs.prx and psplink.prx in your seplugins directory. And they have to be in your seplugins/game.txt file, and you need to activate them in the recovery menu. Again, I won’t go into the details here, you basically need the same setup as if you wanted to run remoteJoy, minus the remote joystick part :p
Once everything is installed, you run usbhostfs_pc and psph from your computer, you connect your psp with a USB cable to your computer, and you launch the game.

If everything works smoothly, usbhostfs_pc should say “connected to device”, and pspsh should say “all modules loaded” then display a prompt “/host0:>”

When you load the savegame, the game will crash, and you should have a memory dump displayed in pspsh, as below

What are we looking for?

Now comes the difficult bit about assembly. PSPLink shows us the state of the various registers just before the crash. register are just 32 bits integers used in any program, and they can represent everything (characters, addresses in memory, integers…) depending on how the program interprets them.
what we want when we write an exploit is to be able to jump to an arbitrary position in the memory. Unfortunately, there are not so many ways to do that. The only solution I know about is to overwrite the contents of the register named “$ra“. ra means “return address”, so you understand why it is so important. This is where the code will go when it leaves a subroutine, with the command “j $ra” (jump to $ra). $ra itself usually gets its data from $sp, so if we can manipulate data related to $sp, that’s a good sign too.
Other registers are not useless, they are the ones that will eventually fill the contents of $sp and $ra, but that becomes too complex to explain here (and, honestly, I don’t know much about it and it requires detailed analysis of the program, which I am not willing to do)

Comparing the Gripshift crash (why it works) and the Phantasy Star crash (why it doesn’t)



Let’s compare our two crashes.

The Gripshift crash

we put lots of letters “a” in the players name. What we see on the crash report is that $ra is now equal to 0×61616161. This is very interesting since 61 is the hexadecimal value of the letter “a”: bingo, we basically found an easy way to jump to an arbitrary location in memory. What’s remaining is to replace the “aaaa” with a regular address, in which we will put some code. (Note that I edited MaTiAz’s original POC to have it actually crash rather than run some code)

The Phantasy star crash:

we see some “61″ here and there, but nothing interesting in $sp or $ra. That’s a very bad start. But we can still have a look at the code, see if those $a1, $a2,$a3 will do something good.


Nothing seems to be doing anything with $sp, then the code jumps one time, two times, meh… it’s too complex, that’s usually where you can give up and start looking for flaws in another game.

So, the Phantasy star crash means nothing?

Not exactly, it is a bug, so there might be a way to exploit it, but when a jump is not obvious, you’ll spend less time looking for a crash in another game and try again, really. Looking for a jump that might not even exist is not fun and could take hundreds of hours, it’s just not worth it (If you’re willing to do it, you’d rather be decrypting the firmware and look for exploits in the Kernel!).

This is too complex for me, isn’t there another way for me to tell if a crash is “a good one” or not?

Well, first you can use your brain. You know how the PSP scene has worked so far. When someone comes whith a potential exploit, you can be sure some serious guys will give it a try if it’s worth it. If after a few weeks there is no “serious” discussion on the issue (involving code or “proof of concept”files), you should lower your hopes.
Also, in this specific case, there was another sign that it wouldn’t work: if it were as easy as the Gripshift exploit, the crash would occur when the user name is loaded. This is not the case here, as you can see the player’s name displayed right after you load the savegame.

So Phantasy star’s demo does have a security check on the player’s name length. This is not a proof that the crash is useless, but a huge hint that it can’t be as easy as the gripshift one.

I personally think it is good to report a crash the way yyoossk did. his report was detailed and he provided all the files to reproduce the issue, which is the reason that made me want to try it (that, and the fact that it was on a demo to which everyone has access). If there were dozens of reports like this one every day, some of them would definitely contain useable flaws!