Is it difficult for a GA aircraft to escape a thunderstorm?
If you take off with a storm 20 minutes away from the airport, it won't have been "unforecast"; the NWS is much better than that. They can pretty accurately predict what's going to happen regarding various fronts at least 24 hours in advance, in turn giving you the advance notice to adjust your flight schedule to ensure you can get around the storm or well away from it.

But let's say someone goofed (probably you), and now you find yourself climbing into the air off the tarmac with the leading wall of a cumulonimbus looming over the horizon, which will be between you and your intended destination before you reach it.

First rule; never fly toward the storm. Cumulonimbus formations are deadly to small craft, and even commercial airliners prefer to stay at altitude in a holding pattern well above the storm and let it pass by before attempting to land. These "thunderheads" produce torrential rains, powerful and frequent lightning, strong updrafts, hailstones ranging from pebbles up to grapefruit, and turbulent cyclonic winds that can culminate in tornadoes. Your Cessna 172 stands no chance.

Flying away from the storm will, at worst, gain you the time between the storm's speed and yours that you can use to find an open airstrip and put down. As Michael Kjorling said in his answer, most Cessna 172 variants cruise at over 100kts, which would require the storm moving across the ground as fast as a Category 2 hurricane rotates, so in most scenarios even if you're flying in still air with the storm moving over the cooler air you're flying in, if you just put the squall line to your rudder you should gain ground. Ideally, the storm will be pushing a mass of air in front of it which will give you a tailwind, and thus you'll be able to put that much more distance between you and the storm front.

Second rule; unless your planned flight is a cross-country flight heading pretty directly away from the incoming front, get on the ground as quickly as you can do so safely, and find a shelter for your aircraft. Obviously, being at your home FBO where you rent your tiedown or hangar is best, but anywhere you can slip your aircraft under a roof or awning for a couple hours will do. Remember that unless you have your instrument rating, the conditions during and after most thunderstorms are IMC and thus illegal (and deadly) for you to fly in.

If you're flying a pressurized aircraft, and/or you have instrument privileges, you have more options, the best of which is to get above the storm and wait it out. However, your Cessna 172 is not pressurized, so unless you have an oxygen bottle aboard (and are endorsed to use it) you're limited to about 12,500 feet and only for a half-hour, well below the top layers of a thunderhead, so you'll have to outrun it, get around it, or put down and shelter in place while it blows over you.