For the Greeks, obscenities were not "dirty", they were simply words or expressions which could be used to cut to the chase, so with them someone either described what it was like sleeping with your rival’s girlfriend (I was fucking away pulling out the tip as if it was a sausage), either communicated the earthy beauty of sexual organs (I’ve never seen a prettier cock), or casted aspersions on someone’s sexual proclivities, since in the ancient Greek world, obscene words were not considered "rude" as such, just very blunt.
However, the Old Comedy was one of the few literary genres where obscenity seems to have been even more actively embraced and contributed decidedly to its growth as a standard and accepted element in the comic performances. Its shock value and aura of scandal made it a reliable vehicle for humour, whether in the service of personalized mockery or more generalized buffoonery. It is precisely this hint of scandal - moral as well as verbal - that has puzzled audiences and scholars, then as now, who often find themselves wondering where this kind of humour comes from and how it can exist with impunity in a literary context, while remaining so problematic and insulting in everyday life.
Aristotle admitted (POETICS, 1449b2) that it was impossible to know what comedy was like before it became officially recognized at the City Dionysia in 486 BCE, but he would have been able to know that a variety of Greek rituals — not only Dionysian ones — incorporated such comic elements as laughter, mockery, or obscenity and that the inherently performative aspects of ritual could sometimes feel as much like secular theater as religious worship. Nevertheless the writers understood that the essential quality of obscene words and prases lies in referring to objects and acts which are private and doing so in a direct way.
Scholars have spent much energy over the past century and a half collecting the available textual and visual evidence for Greek rituals of this sort, but they have not been able to establish with any certainty a diachronic evolution from ritual to comedy. Affiliations specifically between comic laughter and the laughter attested for various Greek rituals — including those for Dionysus, Demeter and Persephone, Apollo, and Heracles — have been well established, but even this connection does not solve the puzzle of which might have "come first", nor does it address the question of a historical relationship between comic and ritual obscenity. Not all laughter is obscene, after all, nor are all aspects of Old Comedy, though whichever is the case, with the rise of New Comedy during the IV century BCE, obscenity and indecency, invaded prose narratives, with works like Philaenis.