Optical Network-on-Chip (ONoC) has recently emerged as a power- and latency-efficient solution to improve the performance of Multi-processor System-on-Chips (MPSoCs). ONoCs take advantage of optical communications to transfer a bulk of data with much lower energy consumption compared to their electrical counterparts. However, the temperature sensitivity of optical routers might be exploited by adversaries to conduct thermal attacks on the optical components of such MPSoCs. In this paper, for the first time, we exploit this vulnerability and define a thermal attack on optical and electro-optical MPSoCs. According to our evaluations, the proposed thermal attack can be conducted under various scenarios and has the potential to alter the functionality of an MPSoC by inducing a range of malicious activities, including 1) Packet misdelivery, drops, and losses, 2) Data errors in normal and secure packets, and 3) Putting the network in a deadlock situation. In addition to the thermal attack, this paper also proposes an efficient countermeasure based on a stochastic source routing of secure packets, making it challenging for the adversary to track and attack the packets. Our evaluations confirm that the proposed countermeasure effectively protects MPSoCs against thermal attacks.