To me, the biggest critical factor is knowing that it was an attacker and bad enough to warrant the caution. If I know that, I probably know (or at least have a good idea who the miscreant is), but even if I don't know who it was, I know that the team committed misconduct and the goal should not stand. I lean towards the philosophy of cautioning the most likely offender (but being willing to change if the team fesses up to the right offender).
But if you can't stomach there is another option that can be squeezed out of Law 12. I don't have to know the offender before I blow the whistle--I know an offense has occurred, so I should stop play. The precise language of Law 12 is "commits any other offence, not mentioned in the Laws, for which play is stopped to caution or send off a player. " I stopped play to caution a player--whether or not I can find the player to give the caution to. (Admittedly a bit cute, but arguably defensible.) And if you struggle with that, the fall back is that play was stopped for the caution, and since you can't give a caution, the restart is a DB--not a good result, but better than an unambiguously undeserved goal.
Law 5 clearly teaches that
I don't see any way to say that it is within the spirit of the game for the referee to know that an attacker committed a cautionable act of unsporting behavior but to allow the goal (game winning or not) to stand because he fails to identify the culprit.