27.07.2006 00:19
How Firekeeper reassembles HTTP response body
Reassembling HTTP response body is not a trivial task, it requires some tradeoffs between efficiency and accuracy. I've just finished to implement solution, that in my opinion is the best. It is based on a way that Snort reassembles TCP streams.
The simplest solution would be to cache response body and not to pass it further, until it is completed. When the whole body arrives, test if it breaks some rules and pass it or cancel. Unacceptable drawback of this solution is its low efficiency. Firefox can process response body before it is fully downloaded and, for example, start to download pictures that are on a page before the whole page is available. This simple solution would disable this optimisation. It would also require unacceptable amount of resources (mainly memory) to handle large responses like for example large files downloading.
Better solution is to cache only fragments of a response. Fragments should have a random size within some range. Each fragment can be tested separately and passed to a browser if it doesn't break any rule. This is how Snort handles TCP stream reassembly. Drawback of this solution is that it isn't 100% accurate. But because fragments have a random size, it is impossible for an attacker to guess where is a border of a fragment and to format a response in such a way that suspicious data is always spread between two fragments and undetected. To further increase accuracy I made following improvement: part of a data from the end of a fragment (also of a random size) is appended to the beginning of a next fragment. It is possible to bypass this system only for attacks which detection requires processing of a large amount of data. But essentially attacks have short fingerprints and can be easily detected with this approach.