A complete stranger can impose duties on us, independently of any consent on our part. While you're having a conversation with a friend, Jane walks up to the two of you and makes a nasty bigoted remark. You may well now have the duty to express your disapproval (through a cold look, or through pointedly ignoring her). She goes on from the remark and commits murder. You now have the duty to try to contribute to her punishment.
It is tempting to say that these duties are consequent on some implicit agreement between you and society. But that, I think, is mistaken. For the duty to disapprove of Jane's remark and to contribute to her punishment are not just duties you owe society: they are duties of justice to Jane. While a failure to express the called-for disapproval of the remark does do harm to the victims of the remark, the duty would exist even if the remark had no victims (suppose Jane makes a remark about a group that she thinks is real, but which is not, and where the remark is nasty that it would be unjustified even if the group were real). Likewise, there would be a duty to punish Jane for murder even if the murder did not in fact harm anyone, and if Jane could not be expected to commit any further crimes. (How could a murder fail to harm? Well, suppose that Patrick has just shot an arrow at George. George is standing at the top of the cliff. Jane doesn't know about Patrick, and pushes George over the precipice. She thus extends George's life, because he would die sooner of the arrow than of the cliff. But she is a murderer. We can tweak the case to make George's death be less painful, too, as a result.)
Similarly, a complete stranger can gain a claim in justice to our gratitude by offering us unsolicited help (I am assuming a case where the offer is not irksome).