Imagine emerging into the sun after 17 long years spent lying underground, only for your butt to fall off.

That ignominious fate regularly befalls America’s cicadas. These bugs spend their youth underground, feeding on roots. After 13 or 17 years of this, they synchronously erupt from the soil in plagues of biblical proportions for a few weeks of song and sex. But on their way out, some of them encounter the spores of a fungus called Massospora.

A week after these encounters, the hard panels of the cicadas’ abdomens slough off, revealing a strange white “plug.” That’s the fungus, which has grown throughout the insect, consumed its organs, and converted the rear third of its body into a mass of spores. The de-derriered insects go about their business as if nothing unusual has happened. And as they fly around, the spores rain down from their exposed backsides, landing on other cicadas and saturating the soil. “We call them flying saltshakers of death,” says Matt Kasson, who studies fungi at West Virginia University.

Massospora and its butt-eating powers were first discovered in the 19th century, but Kasson and his colleagues have only just shown that it has another secret: It doses its victims with mind-altering drugs. Perhaps that’s why “the cicadas walk around as if nothing’s wrong even though a third of their body has fallen off,” Kasson says.

To study these fungi, “you really have to be in the right place at the right time,” Kasson says. For him, the time was May 2016, when billions of periodical cicadas emerged throughout the northeastern United States. He and his colleagues collected around 150 of the unfortunate saltshakers. And a year later, a colleague supplemented this collection with infected banger-wing cicadas—a different species that emerges annually.

Greg Boyce, a member of Kasson’s team, looked at all the chemicals found in the white fungal plugs of the various cicadas. And to his shock, he found that the banger-wings were loaded with psilocybin—the potent hallucinogen found in magic mushrooms. “At first, I thought: There’s absolutely no way,” he says. “It seemed impossible.” After all, no one has ever detected psilocybin in anything other than mushrooms, and those fungi have been evolving separately from Massospora for around 900 million years.

The surprises didn’t stop there. “I remember looking over at Greg one night and he had a strange look on his face,” Kasson recalls. “He said, ‘Have you ever heard of cathinone?’” Kasson hadn’t, but a quick search revealed that it’s an amphetamine. It had never been found in a fungus before. Indeed, it was known only from the khat plant that has long been chewed by people from the Middle East and the Horn of Africa. But apparently, cathinone is also produced by Massaspora as it infects periodical cicadas.

The team took great pains to check that Massospora really does contain these unexpected drugs. They showed that the substances are found only in the infected cicadas and not in the uninfected ones. They found that the fungus has the right genes for making these chemicals, and contains the precursor substances that you’d expect.

And at some point during this work, it dawned on Kasson that he was working with illicit substances. Psilocybin, in particular, is a Schedule I drug, and researchers who study it need a permit from the Drug Enforcement Administration. “I thought: Oh, crap,” he says. “Then I thought: OH CRAP. The DEA is going to come in here, tase me, and confiscate my flying saltshakers.”

He sent them an email. “This is … interesting,” read the initial response. “You have to understand that this is not something we normally get emails about.” After some discussion, the agency decided that no permit was required, since the drug is found in such small quantities within the cicadas, and since Kasson had no plans for concentrating it.

I asked Kasson if it’s possible to get high by eating Massospora-infected cicadas. Surprisingly, he didn’t say no. “Based on the ones we looked at, it would probably take a dozen or more,” he said. But it’s possible that earlier in the infections, before the conspicuous saltshaker stage, the fungus might pump out higher concentrations of these chemicals. Why? Kasson suspects that the drugs help the fungus control its hosts.

Infected cicadas behave strangely. Despite their horrific injuries, males become hyperactive and hypersexual. They frenetically try to mate with anything they can find, including with other males. They’ll even mimic the wing-flicking signals of females to lure males toward them. None of this does them any good—their genitals have either been devoured by the fungus or have fallen off with the rest of their butts. Instead, this behavior only benefits the fungus, allowing its spores to find new hosts.

Kasson suspects that cathinone and psilocybin are responsible for at least some of these behaviors. “If I had a limb amputated, I probably wouldn’t have a lot of pep in my step,” he said. “But these cicadas do. Something is giving them a bit more energy. The amphetamine could explain that.”

Psilocybin’s role is harder to explain. The drug might make humans hallucinate, but no one knows if cicadas would similarly trip. There is, however, a theory that magic mushrooms evolved psilocybin to reduce the appetites of insects that might compete with them for decaying wood. Perhaps by suppressing the appetites of cicadas, Massospora nudges them away from foraging and toward incessant mating.

There are many parasitic fungi that manipulate the behavior of insect hosts, including the famous Ophiocordyceps fungi, which can turn ants into zombies. “There’s a lot of curiosity about how these fungi might actually manipulate behavior, and this is the first time that anyone has identified chemical compounds that could play that role,” says Kathryn Bushley from the University of Minnesota. “That’s really significant.”

The discovery opens up a lot of questions, says Corrie Moreau from the Field Museum of Natural History. What exactly do these drugs do to the cicadas? And, she wonders, “do other cicada-infecting fungi share these same molecules, or has each manipulating fungus evolved a unique compound to induce the desired behavior?”

“And maybe there are other players involved,” Kasson added. He pointed to another study, which I wrote about last week, in which a different fungus seems to use a virus to control the minds of flies. “We might think that it’s just a host and a fungus, but maybe it’s more complicated than that.”