I doubt if there actually is a gain for them to it. Terrorism is the smallest scale military action there is. Even lower on the scale-ladder than guerilla warfare. They don't have anything to "make a fist" with, so they resort to "annoying" their enemies through acts of terrorism. Because, well, a terrorist attack doesn't really "do" anything, save for causing suffering for human loss and materialistic damage, but it doesn't have a real impact on the country's functioning. The impact comes afterwards, when the people and the government get consumed by the terror. It's a scare tactic in the end. They won't achieve anything but for them, it's their holy war.
Nothing substantially can be gained through terrorism. What it does for the terrorists is give them satisfaction i suppose. But like Rukas said, usually those people are so twisted they can't look at things objectively. They probably have goals, yet so unrealistic, but they believe it's achievable.