My understanding is that the Freemasons were the pestilence in the Church that was infusing Modernism into Her. If you read Pope Leo XIII encyclicals on Fɾҽҽmαsσɳɾყ, and Saint Pius X encyclicals on the modernists, you'll see this theme repeated.
They both recognized the fact that both the Freemasons and the Modernists were so engulfed in the Church as occult (hidden) enemies, that it was hard to get them out, and that's why they warned through their encyclicals, and Saint Pius X, with the Oath against Modernism, to be watchful for the enemies, because they both knew this would be the method to try to destroy the Church.
An apt way to describe it, maybe, would be to lump the communists and the Freemasons (which the Freemasons themselves describe as "only a mask" when they speak of communism) as two different corporations owned by the same entity (Satan.)
Perhaps another way of saying it, would be a criminal adopting several different aliases to disguise his true identity, and cover up his behavior.
Same, same with the Freemasons, Modernists, Communists, Protestants, whatever you want to call them. They all work for the same entity: all to different degrees (some for nefarious purposes with full knowledge in the case of Freemasons, some for reasons of indifferentism like the Modernists, some for "social justice" like the communists, some because of ignorance like many protestants, and some because of pernicious heresy and rejection of authority like some other protestants) perhaps not really knowing that they work towards the same goal, and that is the destruction of the Church and the seeming (short lived) triumph of Satan.
Hope that helps.