This article investigates the resilience of the consensus-based distributed microgrid energy management system (MG-EMS) against profit-driven attacks. A holistic framework, called reputation-based collaborative distributed EMS (R-CoDEMS), is proposed to model the system dynamics, profitdriven adversaries, and the cybersecurity of the distributed MG-EMS under profit-driven attacks. Simulation results on a real microgrid system indicate that the R-CoDEMS can effectively detect, mitigate, and recover from the attacks in a fully distributed fashion. The main technical contributions of this research work are: (1) systematically formulating and quantifying the system adversary, assets, threats, vulnerabilities, and risks of the consensus-based distributed MG-EMS; (2) proposing a reputation-based attack detection and mitigation strategy to overcome single and coordinated profit-driven attacks.