By 2018, Nasa is hoping to put a rover on the lunar surface that will be able to extract hydrogen, water and oxygen from the soil.
The RESOLVE (Regolith and Environment Science and Oxygen & Lunar Volatile Extraction) mission will grab handfuls of lunar dirt and heat them up to a temperature where hydrogen, oxygen and water vapour can escape. The two ingredients can then be combined to make water.
A similar experiment will be mounted on the next Mars rover, due to launch in 2020. However this version will involve extracting carbon dioxide from the Martian atmosphere, filtering out dust, and then processing the CO2 into oxygen.
Both missions are early experiments in the science of terraforming - turning other planets into environments that humans could live in without specialised equipment. Without oxygen and water we're unlikely to survive for too long - but bringing it from home is difficult, so it's far preferable to be able to conjure it up in-situ.
If the experiments are successful, future missions may involve industrialising the process, eventually allowing us to drink Martian water and breathe lunar air.