Chinaunix

标题: netfilter 抓包乱码问题 [打印本页]

作者: coconut-zj    时间: 2012-03-22 10:06
标题: netfilter 抓包乱码问题
遇上一个问题:
在写netfilter一个模块时, 在local_in 那个hook上捕获的sk_buff 我想取出其中的应用层数据。
各位大侠们知道怎么定位skb_buff->data 和读取数据吗?
内核版本是2.6以上的。 已经没有 union {}h 那些结构了。

我做出来的结果是这样的:

。。。。//此部分以判断收到的包是tcp包

struct sk_buff* sb = skb_copy(skb,GFP_ATOMIC);
//移动到tcp头
struct iphdr* ip_header = ip_hdr(sb);
skb_pull(sb,ip_hdrlen(sb));
//计算tcp头大小 并移动到tcp的报文内容处
int l = (char) (*(sb->data+12)>>4);
printk("head length:\t%d\n",l);
skb_pull(sb,l*4);
//读取数据
if(sb->data != NULL)
        {
                int len = sb->len - sb->data_len ;
                int i=0;
                while (i < len) printk("%c",  *(sb->data + i++));
                printk("\n\n");
        }

运行时 打开百度www.baidu.com 时抓到的包如下:

local_in:        119.075.217.109->xxx.xxx.xxx.xxx(我的ip)
[ 7705.739321] head length:        5       
[ 7705.739329] HTTP/1.1 200 OK
[ 7705.739346] Date: Thu, 22 Mar 2012 02:01:46 GMT
[ 7705.739381] Server: BWS/1.0
[ 7705.739398] Content-Length: 3400
[ 7705.739419] Content-Type: text/html;charset=gb2312
[ 7705.739457] Cache-Control: private
[ 7705.739480] Expires: Thu, 22 Mar 2012 02:01:46 GMT
[ 7705.739517] Content-Encoding: gzip
[ 7705.739540] Connection: Keep-Alive
[ 7705.739563]
[ 7705.739566]
[ 7705.739567]
[ 7705.739608] local_in:        119.075.217.109->110.064.087.181
[ 7705.739612] head length:        5
[ 7705.739620] $Qha        ¡8ÛŽö      (一堆乱码@!)


问题困扰很久了, 求教求教!
作者: platinum    时间: 2012-03-23 16:16
[ 7705.739517] Content-Encoding: gzip

使用了压缩,你用 tcpdump、wireshark、其他 sniffer 抓,也都是乱码
作者: coconut-zj    时间: 2012-03-23 16:38
回复 2# platinum


    看来也的确是啊。 解压缩{:2_174:}




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2