One of the main challenges in the development process of secure systems is how to detect as early as possible the system's vulnerabilities and weaknesses, and also how to quantify the severity of attacks through them. In this paper, we rely on the concept of attack surfaces to implement a secure cyber physical system in Java. Attack surfaces can be sometimes detected automatically, regarding the used language, by matching them against known attacks still is a step apart. Further, systems and attacks are not usually modeled with compatible formalism. This paper develops a modeling framework that automates the whole process by generating attacks for cyber physical systems. First, we formalize a system using UML class and activity diagrams. Further, we use UML to develop a meta language for cyber physical systems, cyber attacks, and cyber counter measures. The framework instantiates the dependent-application diagrams for the domain/application in test, searches for the existing attack surfaces; then it generates the possible attacks that might exploit the found vulnerabilities/weaknesses. Further the proposed framework generates the proper java code for the composition counter measures, attacks, and CPS models.