What the hacker did is he scanned all those Jailbroken iPhones with SSH enabled and Default root password. Using that password he then sent a message to the hacked iPhones.

If you have jailbreak your iPhone and want to secure yourself from such infiltration, only thing you need to do is that enable SSH only when needed and make sure you change the root password used to SSH into iPhone.

Change Root Password of Your iPhone

In this iPhone guide you will learn how to change root password of your jailbroken iPhone or iTouch. Install the MobileTerminal. If you don’t have MobileTerminal installed in your iPhone then:

Now tap the confirm button at the top-right.
Once you’re done with the installation, press the big Return to Cydia button.

Now press the Home button to close the Cydia and open the MobileTerminal from your iPhone SpringBoard.