As the information technology develops, network attacks have become complex and diverse. To improve the effectiveness and accuracy of data security defense strategies, an optimal defense method based on improving evolutionary game model between heterogeneous groups is proposed. Specifically, based on traditional evolutionary game theory, the player type space is added to divide the heterogeneous groups, and the group type and game strategy are extended to N to solve the problems in heterogeneous groups. Considering the game is interfered by the environment, a set of dynamic environment functions is added to increase the adaptability of the model when dealing with changing complex networks. Taking into account the influence of information communication within the group, the information flow degree is added to increase the accuracy of evolution rate and solve the problem that traditional model cannot reveal the difference in the evolution rate of players. Based on the new model, taking the game between two types of invaders and one type of defender as an example, the calculation method of evolution direction at any time and the judgment method for the stability of equilibrium point are discussed. Finally, the effectiveness of the improved model is verified through the comparison of simulation experiments, and a new scheme is provided for current network data protection.