Difference between revisions of "IQ Reply Spoofing"

Jump to navigation Jump to search
Line 3: Line 3:
Most XMPP stacks provide a convenience method to send an IQ request that returns the IQ response (or e.g. throw an exception on timeout). To collect the response the incoming IQ stanzas are matched against a filter. Often the filter looks like
Most XMPP stacks provide a convenience method to send an IQ request that returns the IQ response (or e.g. throw an exception on timeout). To collect the response the incoming IQ stanzas are matched against a filter. Often the filter looks like


<code>
StanzaFilter badFilter = AndFilter(StanzaTypeFilter(IQ), StanzaIdFilter(iqrequest.id))
StanzaFilter badFilter = AndFilter(StanzaTypeFilter(IQ), StanzaIdFilter(iqrequest.id))
</code>


Such a filter would therefore match every IQ stanza with the same ID as the request. But this is not enough. A malicious attacker that is able to guess the IQ ID is able to send a spoofed IQ response, which causes the malicious response to be evaluated by the XMPP stack. This gives the attacker the ability to trigger code parts (usually parsing related code) he normally wouldn't have access to. For example, he could able to add contacts to the victims rooster.
Such a filter would therefore match every IQ stanza with the same ID as the request. But this is not enough. A malicious attacker that is able to guess the IQ ID is able to send a spoofed IQ response, which causes the malicious response to be evaluated by the XMPP stack. This gives the attacker the ability to trigger code parts (usually parsing related code) he normally wouldn't have access to. For example, he could able to add contacts to the victims rooster.
Line 9: Line 11:
The solution is to additionally verify the from attribute of the result IQ, since its value can not be spoofed:
The solution is to additionally verify the from attribute of the result IQ, since its value can not be spoofed:


<code>
StanzaFilter iqResponseFilter = AndFilter(badFilter, IQFromFilter(iqrequest.to))
StanzaFilter iqResponseFilter = AndFilter(badFilter, IQFromFilter(iqrequest.to))
</code>


Now the devil is in the details: It's valid to send an stanza, and this includes an IQ request, without a to attribute (RFC 6120 § 8.1.1.1). Furthermore some servers may reply with the users full JID if the request was send to the bare JID. IQFromFilter must therefore, besides matching stanzas that have exactly the same 'from' value as the requests 'to' attribute, follow those rules:
Now the devil is in the details: It's valid to send an stanza, and this includes an IQ request, without a to attribute (RFC 6120 § 8.1.1.1). Furthermore some servers may reply with the users full JID if the request was send to the bare JID. <code>IQFromFilter</code> must therefore, besides matching stanzas that have exactly the same 'from' value as the requests 'to' attribute, follow those rules:


If 'to' is not set, match stanzas where 'from' is
If 'to' is not set, match stanzas where 'from' is