This paper investigates an attack detection and security control strategy for unmanned aerial vehicles (UAVs) in the presence of malicious attacks. The detection, estimation, and compensation of the attack are the key points of the proposed scheme. This article considers that the desired trajectory sent by the ground control station (GCS) to the UAV is maliciously tampered with. First, a description of the UAV system and the desired trajectory attack is presented. The mathematical model is constructed by analyzing the characteristics of the desired trajectory attack. Secondly, an unknown input observer (UIO) is designed to generate the state estimation error. The attack detection framework is constructed by taking into account the state estimation error and the trajectory tracking error. Thirdly, an attack estimation observer with a prescribed H∞ performance is designed to compensate for the impact of attacks on the control system. A disturbance observer (DO) is used to compensate for the system disturbance. Finally, the simulation results are presented on Matlab and Gazebo to validate the effectiveness of the proposed security control strategy.