Aha! There's the source of all your troubles, my Pakistani friends. Now this seems like an isolated incident to you and you must be wondering what did I see in this. let me explain. I saw the "gun culture" that has gone horribly wrong. Coupled with fundamentalism and brainwashing, this gun culture's going out of control resulted in Taliban. In Hindi, we Indians have a saying "Jisji laathi, uski bhains" (might is right loosely).
The Taliban and other terrorist groups didn't come out all of a sudden or due to foreign involvement against you, but simply locals who had a twisted thinking of religion and wielded firepower, took to themselves to brainwash people by taking religion as excuse and using gun culture to get to where they are.
The only solution is to break down this concept. Commoners need to have a formal procedure to get gun licenses and only 1 gun per family should be allowed. This will reduce the violent tendencies of people and hence their susceptibility to fall prey to fundamentalist teachings.
If it has spread already, then your government needs to raid all houses by any means, fine these people (no matter how big this gets) and ask them to keep only 1 gun per house with proper license and background verification.
If this is done, then maybe extremism will vanish slowly.