They have tiny claws that enable them to hook onto the walls. They can overcome gravity due to their minuscule weight and the force put out by the legs are stronger than the overall weight so in turn they can climb any surface. Same principle with bees and how they stick upside down. They also has a sticky substance on their legs on hairs to keep still on a surface.
Try looking at the ant's legs...You can see that there are thin fiber (sort of hair). Try looking at spiders because they also have hairy feet... I think that because of these fibers the ants are able to climb walls because these fibers kind of hold on to the walls.
I think they spit on there hands and then clime