Mars is a dusty place and most of the compounds are made up of iron. Thus the dust is highly magnetic. Magnets are used to collect these dust particles. The study of these particles may give us an idea about the planet's history.
Each rover has three sets of magnetic targets that will collect airborne dust for analysis by the science instruments.
The Rock Abrasion Tool carries one set. When the RAT grinds into the rocks, the dust from these outer rock surfaces can be studied.
A second set of two magnets is mounted on the front of the rover. It is mounted at such an angle, that non-magnetic particles falls off.