免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 5376 | 回复: 13
打印 上一主题 下一主题

[网络子系统] 移植iptables模块 [复制链接]

论坛徽章:
1
2015元宵节徽章
日期:2015-03-06 15:52:30
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2013-12-20 15:23 |只看该作者 |倒序浏览
路由器有三种上网方式pppoe,静态IP,DHCP,我移植了一个网址及字符过滤模块(解析HTTP的)到iptables中,使用pppoe上网时过滤可以起作用,在内核(ipv4>netfilter目录下)可以打印出skb->data内容(就是HTTP内容),但是用静态IP及DHCP上网时,过滤就不起作用,skb->data没有我提交HTTP相关内容。测试时间模块,三种方式下都正常。我在ip_rcv()函数开始打印skb内容,pppoe下可以看到skb包的内容(请求的内容),静态IP及DHCP上网时就没有这个包。这是哪里的问题呢,静态IP及DHCP模式下难道请求上网的包没走forward,感觉好怪啊,求指点!!!!

论坛徽章:
1
2015元宵节徽章
日期:2015-03-06 15:52:30
2 [报告]
发表于 2013-12-20 15:25 |只看该作者
这是pppoe模式下打印的内容
<4>----------------INPUT---SKB CONTENT----------------------
<4>len:59, data_len:0, mac_len:14
<4>transport_header:81cd20f0, network_header:81cd20f0, mac_header:81cd20e2
<4>pkt type:0, protocol:8, local_df:0
<4>frag count:0
<4>data:
<4>    E  ;R   @      d    0  5 ' P             www baidu com  
<4>      
<4>------------------------------------------------------
<4>----------------INPUT---SKB CONTENT----------------------
<4>len:52, data_len:0, mac_len:14
<4>transport_header:81ce30f0, network_header:81ce30f0, mac_header:81ce30e2
<4>pkt type:0, protocol:8, local_df:0
<4>frag count:0
<4>data:
<4>    E  4R @ @      ds    P                           
<4>------------------------------------------------------
<4>----------------INPUT---SKB CONTENT----------------------
<4>len:118, data_len:0, mac_len:0
<4>transport_header:81dd30f8, network_header:81dd30f8, mac_header:81dd30f8
<4>pkt type:0, protocol:8, local_df:0
<4>frag count:0
<4>data:
<4>    E  vV @   1= ` ! %   5   b  'w           www baidu com  
<4>                    www a shifen  +       Z  s   +       Z
<4>      s  
4>------------------------------------------------------
<4>----------------INPUT---SKB CONTENT----------------------
<4>len:52, data_len:0, mac_len:0
<4>transport_header:80f720f8, network_header:80f720f8, mac_header:80f720f8
<4>pkt type:0, protocol:8, local_df:0
<4>frag count:0
<4>data:
<4>    E  4R @ 7   s  %   P  Y            P              
<4>------------------------------------------------------
<4>----------------INPUT---SKB CONTENT----------------------
<4>len:46, data_len:0, mac_len:14
<4>transport_header:81dd40f0, network_header:81dd40f0, mac_header:81dd40e2
<4>pkt type:0, protocol:8, local_df:0
<4>frag count:0
<4>data:
<4>    E  (R @ @      ds    P    Y   P   a         
<4>------------------------------------------------------
<4>net_device names, in:br0, out ppp0
<4>--------------------SKB CONTENT----------------------
<4>len:40, data_len:0, mac_len:14
<4>transport_header:81dd40f0, network_header:81dd40f0, mac_header:81dd40e2
<4>pkt type:0, protocol:8, local_df:0
<4>frag count:0
<4>data:
<4>    E  (R @ ?      ds    P    Y   P   a   
<4>
<4>************************************************
<4>match: type=IPT_WEBSTR_HOST
<4>get_http_info: seq=3398681730
<4>get_http_info: datalen=40
<4>----------------INPUT---SKB CONTENT----------------------
<4>len:631, data_len:0, mac_len:14
<4>transport_header:81ce90f0, network_header:81ce90f0, mac_header:81ce90e2
<4>pkt type:0, protocol:8, local_df:0
<4>frag count:0
<4>data:
<4>    E  wS @ @  i   ds    P    Y   P      GET / HTTP/1.1  
<4>    Accept: image/gif, image/jpeg, image/pjpeg, image/pjpeg,
<4>     application/x-shockwave-flash, application/vnd.ms-excel
<4>    , application/vnd.ms-powerpoint, application/msword, app
<4>    lication/xaml+xml, application/x-ms-xbap, application/x-
<4>    ms-application, */*  Accept-Language: zh-cn,sv-FI;q=0.5
<4>     User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows
<4>    NT 5.1; Trident/4.0; InfoPath.2; .NET4.0C; .NET4.0E; .NE
<4>    T CLR 2.0.50727)  Accept-Encoding: gzip, deflate  Host:
<4>    www.baidu.com  Connection: Keep-Alive  Cookie: BAIDUID=9
<4>    DE6709A712CD48B88ADE2F918FD2082:FG=1; H_PS_LC=130_3; BD_
<4>    TMP_CK=true   
<4>------------------------------------------------------
<4>net_device names, in:br0, out ppp0
<4>--------------------SKB CONTENT----------------------
<4>len:631, data_len:0, mac_len:14
<4>transport_header:81ce90f0, network_header:81ce90f0, mac_header:81ce90e2
<4>pkt type:0, protocol:8, local_df:0
<4>frag count:0
<4>data:
<4>    E  wS @ ?  i   ds    P    Y   P      GET / HTTP/1.1  
<4>    Accept: image/gif, image/jpeg, image/pjpeg, image/pjpeg,
<4>     application/x-shockwave-flash, application/vnd.ms-excel
<4>    , application/vnd.ms-powerpoint, application/msword, app
<4>    lication/xaml+xml, application/x-ms-xbap, application/x-
<4>    ms-application, */*  Accept-Language: zh-cn,sv-FI;q=0.5
<4>     User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows
<4>    NT 5.1; Trident/4.0; InfoPath.2; .NET4.0C; .NET4.0E; .NE
<4>    T CLR 2.0.50727)  Accept-Encoding: gzip, deflate  Host:
<4>    www.baidu.com  Connection: Keep-Alive  Cookie: BAIDUID=9
<4>    DE6709A712CD48B88ADE2F918FD2082:FG=1; H_PS_LC=130_3; BD_
<4>    TMP_CK=true   
<4>
<4>************************************************
<4>match: type=IPT_WEBSTR_HOST
<4>get_http_info: seq=3398681730
<4>get_http_info: datalen=631
<4>find_pattern2: pattern = 'Host: ', dlen = 631
<4>Host found=1
<4>HOST=www.baidu.com, hostlen=13
<4>keyword=www.baidu.com, nlen=13, hlen=13
<4>search_linear: haystack=www.baidu.com, needle=www.baidu.com
<4>match: Verdict =======> DROP

   

论坛徽章:
1
2015元宵节徽章
日期:2015-03-06 15:52:30
3 [报告]
发表于 2013-12-20 15:28 |只看该作者
这是dhcp上网方式下打印的内容:
<4>----------------INPUT---SKB CONTENT----------------------
<4>len:59, data_len:0, mac_len:14
<4>transport_header:81d570f0, network_header:81d570f0, mac_header:81d570e2
<4>pkt type:0, protocol:8, local_df:0
<4>frag count:0
<4>data:
<4>    E  ;X-  @      d       5 '}             www baidu com  
<4>      
<4>------------------------------------------------------
<4>----------------INPUT---SKB CONTENT----------------------
<4>len:59, data_len:0, mac_len:14
<4>transport_header:81d5c0f0, network_header:81d5c0f0, mac_header:81d5c0e2
<4>pkt type:0, protocol:8, local_df:0
<4>frag count:0
<4>data:
<4>    E  ;X.  @      d    0  5 '             www baidu com  
<4>      
<4>------------------------------------------------------
<4>----------------INPUT---SKB CONTENT----------------------
<4>len:118, data_len:0, mac_len:14
<4>transport_header:81d5d0f0, network_header:81d5d0f0, mac_header:81d5d0e2
<4>pkt type:0, protocol:8, local_df:0
<4>frag count:0
<4>data:
<4>    E  v  @ @  #         5   b -u            www baidu com  
<4>                    www a shifen  +       k  s  +       k
<4>      s  
<4>------------------------------------------------------
<4>----------------INPUT---SKB CONTENT----------------------
<4>len:118, data_len:0, mac_len:14
<4>transport_header:80fda0f0, network_header:80fda0f0, mac_header:80fda0e2
<4>pkt type:0, protocol:8, local_df:0
<4>frag count:0
<4>data:
<4>    E  v  @ @  #         5   b  _          www baidu com  
<4>                    www a shifen  +       k  s  +       k
<4>      s  
<4>------------------------------------------------------
<4>----------------INPUT---SKB CONTENT----------------------
<4>len:52, data_len:0, mac_len:14
<4>transport_header:81d360f0, network_header:81d360f0, mac_header:81d360e2
<4>pkt type:0, protocol:8, local_df:0
<4>frag count:0
<4>data:
<4>    E  4X/@ @  }   ds   P  I>        "v              
<4>------------------------------------------------------
<4>net_device names, in:br0, out vlan2
<4>--------------------SKB CONTENT----------------------
<4>len:52, data_len:0, mac_len:14
<4>transport_header:81d360f0, network_header:81d360f0, mac_header:81d360e2
<4>pkt type:0, protocol:8, local_df:0
<4>frag count:0
<4>data:
<4>    E  4X/@ ?  }   ds   P  I>        "v              
<4>
<4>************************************************
<4>match: type=IPT_WEBSTR_HOST
<4>get_http_info: seq=4058073406
<4>get_http_info: datalen=52
<4>----------------INPUT---SKB CONTENT----------------------
<4>len:52, data_len:0, mac_len:14
<4>transport_header:81d2f0f0, network_header:81d2f0f0, mac_header:81d2f0e2
<4>pkt type:0, protocol:8, local_df:0
<4>frag count:0
<4>data:
<4>    E  4X/@ 6   s      P     I?    8               
<4>------------------------------------------------------
<4>----------------INPUT---SKB CONTENT----------------------
<4>len:46, data_len:0, mac_len:14
<4>transport_header:81d2a0f0, network_header:81d2a0f0, mac_header:81d2a0e2
<4>pkt type:0, protocol:8, local_df:0
<4>frag count:0
<4>data:
<4>    E  (X1@ @      ds   P  I?  P            
<4>------------------------------------------------------
<4>net_device names, in:br0, out vlan2
<4>--------------------SKB CONTENT----------------------
<4>len:40, data_len:0, mac_len:14
<4>transport_header:81d2a0f0, network_header:81d2a0f0, mac_header:81d2a0e2
<4>pkt type:0, protocol:8, local_df:0
<4>frag count:0
<4>data:
<4>    E  (X1@ ?      ds   P  I?  P      
<4>
<4>************************************************
<4>match: type=IPT_WEBSTR_HOST
<4>get_http_info: seq=4058073407
<4>get_http_info: datalen=40
<4>----------------INPUT---SKB CONTENT----------------------
<4>len:66, data_len:0, mac_len:14
<4>transport_header:81d430f0, network_header:81d430f0, mac_header:81d430e2
<4>pkt type:0, protocol:8, local_df:0
<4>frag count:0
<4>data:
<4>    E  BX9  @      d    m1 5 .M |K           suggestion baid
<4>    u com     
<4>------------------------------------------------------
<4>----------------INPUT---SKB CONTENT----------------------
<4>len:82, data_len:0, mac_len:14
<4>transport_header:81d560f0, network_header:81d560f0, mac_header:81d560e2
<4>pkt type:0, protocol:8, local_df:0
<4>frag count:0
<4>data:
<4>    E  R  @ @  G         5   >v  Q           suggestion baid
<4>    u com                 s   
<4>------------------------------------------------------
<4>----------------INPUT---SKB CONTENT----------------------
<4>len:52, data_len:0, mac_len:14
<4>transport_header:81d740f0, network_header:81d740f0, mac_header:81d740e2
<4>pkt type:0, protocol:8, local_df:0
<4>frag count:0
<4>data:
<4>    E  4X @      ds     P0E           _              
<4>------------------------------------------------------
<4>net_device names, in:br0, out vlan2
<4>--------------------SKB CONTENT----------------------
<4>len:52, data_len:0, mac_len:14
<4>transport_header:81d740f0, network_header:81d740f0, mac_header:81d740e2
<4>pkt type:0, protocol:8, local_df:0
<4>frag count:0
<4>data:
<4>    E  4X ?      ds     P0E           _              
<4>
<4>************************************************
<4>match: type=IPT_WEBSTR_HOST
<4>get_http_info: seq=809871104
<4>get_http_info: datalen=52
<4>----------------INPUT---SKB CONTENT----------------------
<4>len:52, data_len:0, mac_len:14
<4>transport_header:81d590f0, network_header:81d590f0, mac_header:81d590e2
<4>pkt type:0, protocol:8, local_df:0
<4>frag count:0
<4>data:
<4>    E  4X 6   s        P     0E                     
<4>------------------------------------------------------
<4>----------------INPUT---SKB CONTENT----------------------
<4>len:64, data_len:0, mac_len:14
<4>transport_header:81d3c0f0, network_header:81d3c0f0, mac_header:81d3c0e2
<4>pkt type:0, protocol:8, local_df:0
<4>frag count:0
<4>data:
<4>    E  @X<  @      d    e  5 ,](            passport baidu
<4>    com     
<4>------------------------------------------------------
<4>----------------INPUT---SKB CONTENT----------------------
<4>len:46, data_len:0, mac_len:14
<4>transport_header:81d7a0f0, network_header:81d7a0f0, mac_header:81d7a0e2
<4>pkt type:0, protocol:8, local_df:0
<4>frag count:0
<4>data:
<4>    E  (X=@ @      ds     P0E      P            
<4>------------------------------------------------------
<4>net_device names, in:br0, out vlan2
<4>--------------------SKB CONTENT----------------------
<4>len:40, data_len:0, mac_len:14
<4>transport_header:81d7a0f0, network_header:81d7a0f0, mac_header:81d7a0e2
<4>pkt type:0, protocol:8, local_df:0
<4>frag count:0
<4>data:
<4>    E  (X=@ ?      ds     P0E      P      
<4>
<4>************************************************
<4>match: type=IPT_WEBSTR_HOST
<4>get_http_info: seq=809871105
<4>get_http_info: datalen=40
<4>----------------INPUT---SKB CONTENT----------------------
<4>len:80, data_len:0, mac_len:14
<4>transport_header:81d340f0, network_header:81d340f0, mac_header:81d340e2
<4>pkt type:0, protocol:8, local_df:0
<4>frag count:0
<4>data:
<4>    E  P  @ @  I         5   <   z           passport baidu
<4>    com              H      
<4>------------------------------------------------------
<4>----------------INPUT---SKB CONTENT----------------------
<4>len:52, data_len:0, mac_len:14
<4>transport_header:81d680f0, network_header:81d680f0, mac_header:81d680e2
<4>pkt type:0, protocol:8, local_df:0
<4>frag count:0
<4>data:
<4>    E  4X>@ @      d      P                           
<4>------------------------------------------------------
<4>net_device names, in:br0, out vlan2
<4>--------------------SKB CONTENT----------------------
<4>len:52, data_len:0, mac_len:14
<4>transport_header:81d680f0, network_header:81d680f0, mac_header:81d680e2
<4>pkt type:0, protocol:8, local_df:0
<4>frag count:0
<4>data:
<4>    E  4X>@ ?      d      P                           
<4>
<4>************************************************
<4>match: type=IPT_WEBSTR_HOST
<4>get_http_info: seq=3892489856
<4>get_http_info: datalen=52
<4>----------------INPUT---SKB CONTENT----------------------
<4>len:52, data_len:0, mac_len:14
<4>transport_header:81d4b0f0, network_header:81d4b0f0, mac_header:81d4b0e2
<4>pkt type:0, protocol:8, local_df:0
<4>frag count:0
<4>data:
<4>    E  4X>@ 6  s         P   ZN                        
<4>------------------------------------------------------
<4>----------------INPUT---SKB CONTENT----------------------
<4>len:46, data_len:0, mac_len:14
<4>transport_header:81d510f0, network_header:81d510f0, mac_header:81d510e2
<4>pkt type:0, protocol:8, local_df:0
<4>frag count:0
<4>data:
<4>    E  (XB@ @     d      P      ZOP    h        
<4>------------------------------------------------------
<4>net_device names, in:br0, out vlan2
<4>--------------------SKB CONTENT----------------------
<4>len:40, data_len:0, mac_len:14
<4>transport_header:81d510f0, network_header:81d510f0, mac_header:81d510e2
<4>pkt type:0, protocol:8, local_df:0
<4>frag count:0
<4>data:
<4>    E  (XB@ ?     d      P      ZOP    h  
<4>
<4>************************************************
<4>match: type=IPT_WEBSTR_HOST
<4>get_http_info: seq=3892489857
<4>get_http_info: datalen=40

论坛徽章:
6
金牛座
日期:2013-10-08 10:19:10技术图书徽章
日期:2013-10-14 16:24:09CU十二周年纪念徽章
日期:2013-10-24 15:41:34狮子座
日期:2013-11-24 19:26:19未羊
日期:2014-01-23 15:50:002015年亚洲杯之阿联酋
日期:2015-05-09 14:36:15
4 [报告]
发表于 2013-12-20 16:07 |只看该作者
回复 1# leaveing2012
路由器有三种上网方式pppoe,静态IP,DHCP,我移植了一个网址及字符过滤模块(解析HTTP的)到iptables中,使用pppoe上网时过滤可以起作用,在内核(ipv4>netfilter目录下)可以打印出skb->data内容(就是HTTP内容),但是用静态IP及DHCP上网时,过滤就不起作用,skb->data没有我提交HTTP相关内容。测试时间模块,三种方式下都正常。我在ip_rcv()函数开始打印skb内容,pppoe下可以看到skb包的内容(请求的内容),静态IP及DHCP上网时就没有这个包。这是哪里的问题呢,静态IP及DHCP模式下难道请求上网的包没走forward,感觉好怪啊,求指点!!!!


1。 数据包肯定走forward的。
2。 你贴出来的日志格式,估计没有谁会愿意看的。

   

论坛徽章:
1
2015元宵节徽章
日期:2015-03-06 15:52:30
5 [报告]
发表于 2013-12-20 16:13 |只看该作者
这个是我自己打印的,只是想说明下,pppoe下打印出数据包,可以看到我发的www.baidu.com请求包,但其他两种方式下,没看到这种包(http),而且长度都很小。我再发个简化的

论坛徽章:
1
2015元宵节徽章
日期:2015-03-06 15:52:30
6 [报告]
发表于 2013-12-20 16:27 |只看该作者
这个是pppoe方式下打印出的信息,我过滤的是www.baidu.com。在过滤处会解析http头部,对包里的host进行查找,实现过滤;
<4>----------------INPUT---SKB CONTENT----------------------
<4>len:631, data_len:0, mac_len:14
<4>transport_header:81ce90f0, network_header:81ce90f0, mac_header:81ce90e2
<4>pkt type:0, protocol:8, local_df:0
<4>frag count:0
<4>data:
<4>    E  wS @ @  i   ds    P    Y   P      GET / HTTP/1.1  
<4>    Accept: image/gif, image/jpeg, image/pjpeg, image/pjpeg,
<4>     application/x-shockwave-flash, application/vnd.ms-excel
<4>    , application/vnd.ms-powerpoint, application/msword, app
<4>    lication/xaml+xml, application/x-ms-xbap, application/x-
<4>    ms-application, */*  Accept-Language: zh-cn,sv-FI;q=0.5
<4>     User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows
<4>    NT 5.1; Trident/4.0; InfoPath.2; .NET4.0C; .NET4.0E; .NE
<4>    T CLR 2.0.50727)  Accept-Encoding: gzip, deflate  Host:
<4>    www.baidu.com  Connection: Keep-Alive  Cookie: BAIDUID=9
<4>    DE6709A712CD48B88ADE2F918FD2082:FG=1; H_PS_LC=130_3; BD_
<4>    TMP_CK=true   

DHCP及静态IP方式下没有看到这种信息,而且打印的数据长度一般都很小(上面发的);我也试过string模块,以及domain模块,这两种方式下都不起作用。。
三种方式都是在vlan2接口下的

论坛徽章:
6
金牛座
日期:2013-10-08 10:19:10技术图书徽章
日期:2013-10-14 16:24:09CU十二周年纪念徽章
日期:2013-10-24 15:41:34狮子座
日期:2013-11-24 19:26:19未羊
日期:2014-01-23 15:50:002015年亚洲杯之阿联酋
日期:2015-05-09 14:36:15
7 [报告]
发表于 2013-12-20 16:41 |只看该作者
回复 6# leaveing2012
我也试过string模块,以及domain模块,这两种方式下都不起作用。。
三种方式都是在vlan2接口下的

如果string模块也匹配不到话,那就比较奇怪了。
说一下你的拓扑环境,用tcpdump抓包看看,能否抓到这些数据包
   

论坛徽章:
1
2015元宵节徽章
日期:2015-03-06 15:52:30
8 [报告]
发表于 2013-12-20 17:04 |只看该作者
我在windows下可以抓到发出去的请求包,路由器上没有tcpdump.
三种上网方式wan口都是在vlan2接口下的,LAN口在vlan1下
FORWARD链规则:
pkts    bytes   target     prot opt   in    out     source               destination
10512  738K advgrp_1    all    --     *      *       192.168.1.100    0.0.0.0/0        
拓展的advgrp_1链规则(设置时间):
10512  738K    grp_1       all  --       *      *       0.0.0.0/0            0.0.0.0/0           time from 00:00:00 to 23:59:59 on Fri
拓展的grp_1链规则(设置网址):
0     0             REJECT       tcp  --      *      *       0.0.0.0/0            0.0.0.0/0           WEBSTR match host www.baidu.com<&nbsp;> reject-with tcp-reset
第三条链上没有包

论坛徽章:
6
金牛座
日期:2013-10-08 10:19:10技术图书徽章
日期:2013-10-14 16:24:09CU十二周年纪念徽章
日期:2013-10-24 15:41:34狮子座
日期:2013-11-24 19:26:19未羊
日期:2014-01-23 15:50:002015年亚洲杯之阿联酋
日期:2015-05-09 14:36:15
9 [报告]
发表于 2013-12-20 17:35 |只看该作者
回复 8# leaveing2012
用string模块试试,排除这个模块bug的影响

   

论坛徽章:
1
2015元宵节徽章
日期:2015-03-06 15:52:30
10 [报告]
发表于 2013-12-20 17:43 |只看该作者
FORWARD 第一条规则就是这个:
0     0 DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0           STRING match "www.baidu.com<&nbsp;>" ALGO name bm FROM 1 TO 600
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP