The electric power grid is a cyber-physical system (CPS) that plays a fundamental role in modern society. With the integration of renewable energy sources and advanced communication technologies, Smart Grids (SGs) can enhance both the profitability and reliability of the electric power system. The communication network that interconnects numerous remotely distributed generators, devices, and controllers plays a vital role in grid control, and current trends favor the widespread adoption of Internet of Things (IoT) devices. However, this network is inherently vulnerable to cyberattacks.This dissertation presents a hybrid methodology to model and analyze the dynamic behavior of an electrical microgrid by integrating System Dynamics and Agent-Based Modeling. As a primary contribution, it incorporates a cyberattack module that simulates the impact of malware targeting IoT devices, exploiting vulnerabilities within the electric system. This approach provides a robust platform for identifying cyber-physical vulnerabilities, evaluating mitigation strategies, and contributing to the development of future resilience and energy cybersecurity policies. Finally, the study presents its conclusions along with recommendations for future research on modeling emerging cyber threats in distributed power systems.