How to fix broken screw hole in ceiling box? (re: ceiling light fixture; how to replace the box?)
The box up there is similar to the one below.

If you have attic access, you can remove the old box and replace it fairly easy.
If you don't have access, then you'll have to cut the tabs the nails are in so you can remove the box. Be very careful not to cut the wires going into the box. A keyhole saw or hack saw blade with a handle works great. Once the box is out, you can get a ceiling box that screws right into the stud where the old box was.