I've just spent some time looking at these on Dictionary.com, and the truth is that I'm not sure there's any easy way to explain the difference!
These are the definitions that come closest to clarifying the distinction for me:
attain (verb used with object)
to come to or arrive at, esp. after some labor or tedium; reach: to attain the age of 96; to attain the mountain peak.
obtain (verb used with object)
to come into possession of; get, acquire, or procure, as through an effort or by a request: to obtain permission; to obtain a better income. [ I think this is the most general of the three - not as much effort is required to obtain as to attain.]
gain (verb used with object)
1. to get (something desired), esp. as a result of one's efforts: to gain possession of an object; to gain permission to enter a country. [This usage is synonymous with attain and obtain.]
2. :up: to acquire as an increase or addition: to gain weight; to gain speed. [This is the most distinctive meaning.]