certain behavior requires a spanking. for example, a 9 year old putting their finger on an electric socket. Just being firm in the tone of your voice is not good enough. A spanking, in certain situations, lets a child know not to ever do that again.
I don't agree with spanking or getting too excessive with your tone of voice. It could lead to unnecessary fear, excessive anxiety and guilt in his future relationships. Its fairly normal and curious behavior at that age as John says. Be firm in your tone of voice but don't overdo it.
just give him a good spanking and say don't do this again.
It's that simple!
Exhibitionism among children has a lot to do with curiosity and is fairly common. It's an opportunity to teach your son about what is appropriate behavior. I'd be more worried if he were a teenager or if it continues. Just use it as a chance to teach him and don't worry yet unless similar behaviors continue.