I'm writing a sniffer for http packets with libpcap. Sometimes printing the content of the http payload I get strange characters.. do you know what could they be?
*xNT:���3�@�"P#1u`��$%S{M��
or
�~�tsE��}>a�����}/���`�▒�A�y
Thanks, for the answers.
If the header is in plain text so the problem is my code.
Anyway, can a POST request be coded in base64?
This is probably binary data that your display font has no characters for. HTTP does not necessarily transport text, it could be images or any other form of raw binary the client requested. Hard to say without seeing the rest of the TCP package.
In
utils_http.c
you have the following function:This is making the assumption that the TCP payload always starts 20 bytes after the beginning of the TCP header (always 20 because
sizeof(*tcp) == 20
). This doesn't take into account any TCP options. If you receive a packet with TCP options (which are very common),handle_http()
will have the binary-encoded TCP options at the beginning of its buffer which might be what you're seeing.Try something like this instead:
Or better yet, I have no idea why you're constantly making dozens of copies of your buffer every chance you get. You can just pass pointers around unless I'm missing something:
The HTTP header Content-Type should tell you the type of payload. The HTTP headers should also say whether compression is used.
Compare what you get with http://web-sniffer.net/ or use something like Wireshark