Or at least this is the theory proposed in Brain Evolution Through The Lens Of Parasite Manipulation by Marco del Giudice.
The paper starts with an overview of parasite manipulation of host behavior. These are the stories you hear about toxoplasma-infected rats seeking out cats instead of running away from them, or zombie ants climbing stalks of grass so predators will eat them. The parasite secretes chemicals that alter host neurochemistry in ways that make the host get eaten, helping the parasite transfer itself to a new organism.
Along with rats and ants, there is a dizzying variety of other parasite manipulation cases. They include parasitic wasps who hack spiders into forming protective webs for their pupae, parasitic flies that cause bees to journey far from their hive in order to spread fly larva more widely, and parasitic microorganisms that cause mosquitoes to draw less blood from each victim (since that forces the mosquitoes to feed on more victims, and so spread the parasite more widely). Parasitic nematodes make their ant hosts turn red, which causes (extremely stupid?) birds to mistake them for fruit and eat them. Parasitic worms make crickets seek water; as the cricket drowns, the worms escape into the pond and begin the next stage of their life cycle. Even mere viruses can alter behavior; the most famous example is rabies, which hacks dogs, bats, and other mammals into hyperaggressive moods that usually result in them biting someone and transmitting the rabies virus.
Even our friendly gut microbes might be manipulating us. People talk a lot about the “gut-brain axis” and the effect of gut microbes on behavior, as if this is some sort of beautiful symbiotic circle-of-life style thing. But scientists have found that gut microbes trying to colonize fruit flies will hack the flies’ food preferences to get a leg up – for example, a carb-metabolizing microbe will secrete hormones that make the fly want to eat more carbs than fat in order to outcompete its fat-metabolizing rivals for gut real estate; there are already papers speculating that the same processes might affect humans. Read Alcock 2014 and you will never look at food cravings the same way again.