In this paper, we first consider a pinning node selection and control gain co-design problem for complex networks. A necessary and sufficient condition for the synchronization of the pinning controlled networks at a homogeneous state is provided. A quantitative model is built to describe the pinning costs and to formulate the pinning node selection and control gain design problem for different scenarios into the corresponding optimization problems. Algorithms to solve these problems efficiently are presented. Based on the developed results, we take the existence of a malicious attacker into consideration and a resource allocation model for the defender and the malicious attacker is described. We set up a leader-follower Stackelberg game framework to study the behaviour of both sides and the equilibrium of this security game is investigated. Numerical examples and simulations are presented to demonstrate the main results.