The record for strongest cosmic magnet belongs to neutron star SGR 0418+5729, observed by the European Space Agency in 2009. Scientists devised a new technique for processing X-ray emissions that allowed them observe the magnetic field under the star’s surface. The ESA themselves described it as a “magnetic monster.”
Magnetars are pretty small, around 20 kilometers (12 mi) wide. Size-wise, you’d be able to fit one quite easily on the Moon. But it’d probably be best if you didn’t: Even from that distance, the magnetic field would be strong enough to stop a locomotive on Earth. Luckily, this one is 6,500 light years away.