Artificial intelligence (AI) has an important significance in the construction of smart grids. There is a problem of low accuracy of behavior detection due to a large number of attacks and long data fragments in the power grid data. In this paper, a behavior detection method based on a generative adversarial network (GAN) is proposed. The method focuses on optimizing the learning strategies of the generator and discriminator based on a GAN. In this regard, the loss function is converged by maximizing the root mean square error of the attack in the discriminator, and the linear activation function is used as the modulation function before the output in the generator. Therefore, the improved GAN can utilize the data enhancement features in the original mode and ensure the stability of attack behavior recognition, and then, effectively detect the attack information in the grid. The experimental results show that the method in this paper can accurately and effectively monitor abnormal attack behavior in the embedded terminals of the smart grid, and its effective detection rate is 97.6%.