Cyber-physical systems are a combination of cyberspace and physical processes in which physical systems and processes are monitored and managed by the cyber layer. The purpose of entering the physical world is to increase the flexibility and efficiency of systems. Today, these systems play a key role in critical infrastructure. This development, on the other hand, has exposed these systems to serious security risks that did not exist before. Therefore, addressing the security and reliability of these systems is essential. In this paper, a method for modeling and evaluating the reliability of cyber-physical systems against security attacks is presented. In this method, the attacker behavior in intrusion and attack on the system is modeled along with the behavior of the system by considering defensive measures such as the use of redundant components and intrusion detection systems. Quantitative reliability assessment was performed using accessibility metrics and mean time to system failure. Finally, in an example, the applicability of the proposed method is represented.