]]>[zz]L7-filter Kernel Version HOWTOhttp://www.tkk7.com/jjwwhmm/archive/2010/03/16/315578.htmlponyponyTue, 16 Mar 2010 05:09:00 GMThttp://www.tkk7.com/jjwwhmm/archive/2010/03/16/315578.htmlhttp://www.tkk7.com/jjwwhmm/comments/315578.htmlhttp://www.tkk7.com/jjwwhmm/archive/2010/03/16/315578.html#Feedback0http://www.tkk7.com/jjwwhmm/comments/commentRss/315578.htmlhttp://www.tkk7.com/jjwwhmm/services/trackbacks/315578.html【{载自http://l7-filter.sourceforge.net/HOWTO?small>
Last update 23 Aug 2008
Use the appropriate kernel patch from the "Layer 7 patches" package to patch[1] the kernel (read the README in the package to determine which patch to use). Set up your kernel as you would otherwise. Now enable the following options (these are correct for Linux 2.6.21.1, but they tend to move around a lot, so you may have to go hunting if you have a different kernel version):
"Prompt for development and/or incomplete code/drivers" (under "Code maturity level options")
"Connection tracking flow accounting" (on the same screen)
And finally, "Layer 7 match support"
Optional but highly recommended: Lots of other Netfilter options, notably "FTP support" and other matches. If you don't know what you're doing, go ahead and enable all of them.
Warning: Some users have reported kernel crashes when they using SMP with l7-filter. (Some have also reported that their SMP systems run fine.) If you have a multi-CPU machine, test carefully before putting it into production with l7-filter.
Compile and install the kernel as usual. (Our code may generate warnings about "initialization from incompatible pointer type", ignore them.) Reboot.
1How to patch a source tree
Suppose you have a patch called happy.patch. To apply it, go into the root directory of the source tree you want to patch and run "patch -p1 < happy.patch"
Iptables Setup
First read the README in the package "Layer 7 patches". Depending on your version of iptables, the instructions are different.
iptables 1.4.0 and older
Use the appropriate iptables patch to to patch[1] iptables. Compile iptables, pointing it at your patched kernel source:
Run "chmod +x extensions/.layer7-test" (information about file permissions can't be contained in the patch)
Then "make KERNEL_DIR=/path/to/patched/kernel_source" (you must have configured your kernel source before this step)
And install (as root): "make install KERNEL_DIR=/path/to/patched/kernel_source"
iptables 1.4.1
Don't use this version. There's no reason to and it's difficult to compile.
iptables 1.4.1.1 and newer
Copy libxt_layer7.c and libxt_layer7.man (from the subdirectory of the "Layer 7 patches" package that the README points you to) to the extensions/ directory of your iptables source. Then:
"./configure --with-ksource=/path/to/patched/kernel_source" (use the full path)
"make"
(as root) "make install"
Protocol Definitions (Pattern Files)
These files tell iptables and the kernel how protocol names correspond to regular expressions, e.g. "ftp" means "^220[\x09-\x0d -~]*ftp".
Uncompress the "Protocol Definitions" package and make the resulting directory /etc/l7-protocols.[2]
You should now be ready to actually do stuff.
2Notes for non-conformists
You can also install the patterns in a custom location. If you do this, you need to specify --l7dir before --l7proto when you use l7-filter:
There are three things you may be interested in doing: (1) blocking certain protocols (2) controlling bandwidth use (3) accounting. We cover each of these cases below.
First, a reminder: Just because you're using l7-filter, you don't need to do all of your packet classification using it. It's likely that what you want to accomplish can be at least partially done with less demanding classifiers, such as port matching. For instance, you can probably assume that traffic on TCP port 80 that isn't matched by any P2P patterns is HTTP; you don't need to actually use the HTTP pattern.
l7-filter uses the standard iptables extension syntax. (If you are not familiar with this, it's time to read the documentation at netfilter.org or at least "man iptables".)
The only trick is that, in order to do its classification, l7-filter must be able to see all of the relevant traffic. It only sees packets if they go through an l7-filter rule. One way of ensuring this is to use the POSTROUTING chain of the mangle table:
iptables -t mangle -A POSTROUTING -m layer7 --l7proto [etc.]
See this packet flow diagram for details. In some cases, l7-filter can sucessfully match even if it can only see one side of the connection, but in general, this won't work.
If you are using a version of l7-filter earlier than 2.7, you must manually load the ip_conntrack module kernel for l7-filter to work. Newer versions do this automatically.
1. Blocking
Don't. Here's why:
l7-filter matching isn't foolproof: there may be both false positives (one protocol can look like another) and false negatives (applications can do obscure things that we didn't count on). Patterns that are known to regularly generate false positives are marked "overmatching" on the protocols page, but others may also do so occasionally.
Almost every type of Internet traffic has legitimate uses. For instance, P2P protocols, while widely used to violate copyright, are also an efficient way to distribute open source software and legally free music.
Programs can respond to being blocked by port-hopping, switching between TCP and UDP, opening a new connection for every trivial operation, using encryption, or employing other evasion tactics. Trying to block such protocols has consequences on two levels:
In the case of port/protocol-hopping, you make it harder for yourself to identify protocols that already act this way.
You encourage programmers to include these "features" in new programs, making it harder for everyone in the future. For example: In early 2006, Bittorrent started moving towards end-to-end encryption because many networks were either blocking it or severely restricting its bandwidth.
l7-filter patterns are not generally designed with blocking in mind. We consider a protocol to be well identified if the identification is useful for controlling its bandwidth. This means, for instance, that for P2P applications, we do not focus on catching connections that are not downloads.
Blocking with l7-filter provides no security, since any reasonably determined person can easily circumvent it.
Instead of dropping packets you don't like, we recommend using Linux QoS to restrict their bandwidth usage. If you insist on using l7-filter to drop packets, make sure you have investigated other options first, such as the features of your HTTP proxy (useful for worms).
2. Bandwidth Restriction
To control the bandwidth that a protocol uses, you can use Netfilter to "mark" the packets and QoS to filter on that mark. To mark:
iptables -t mangle -A POSTROUTING -m layer7 --l7proto imap -j MARK --set-mark 3
The number "3" is arbitrary. It can be any integer. Then use tc to filter on that mark (tc is "traffic control", the userspace tool for Linux QoS, part of the iproute2 package):
tc filter add dev eth0 protocol ip parent 1:0 prio 1 handle 3 fw flowid 1:3
Did you understand that last command? You can try reading The Linux Advanced Routing and Traffic Control HOWTO for enlightenment. You should do this so that you have some idea what you're doing, but unfortunately, tc is incredibly obtuse and you're likely to wish you just had a canned script. Well, we can help:
These may need to be modified if your setup is significantly different than mine, but it should provide a much better starting point than most other things you are likely to find.
Be prudent when choosing the amount of bandwidth you allow each protocol. Restricting a protocol to an unusably low bandwidth can have similar consequences to blocking it.
3. Accouting
If you just want to keep track of what's in use on your network, simply use the above command without any -j option. For example:
iptables -t mangle -A POSTROUTING -m layer7 --l7proto imap
You can then get statistics by using iptables -L. (See "man iptables" for details.)
More Information
Dealing with FTP, IRC, etc.
Some protocols open child connections to transfer data. FTP is the most familiar example. If you have loaded the ip_conntrack_ftp or nf_conntrack_ftp kernel module, l7-filter will classify FTP and all its child connections as FTP. The same goes for IRC/IRC-DCC, etc.
If you wish to classify the children differently, use the standard iptables "helper" match. You can use "-m --helper ftp" to match ftp child connections. Of course, once you've done this, it's silly to involve l7-filter, at least for the children.
The "unset" and "unknown" matches
l7-filter marks unmatched connections that it is still trying to match as "unset". The first few packets of all TCP connections as well as those of some UDP connections will match this. Similarly, l7-filter marks connections that it has given up trying to match as "unknown". These are matched just like normal protocols:
iptables -A FORWARD -m layer7 --l7proto unset
iptables -A FORWARD -m layer7 --l7proto unknown
The "unset" match is only supported by l7-filter 2.9 and up.
Upgrading the protocol definitions
The protocol definitions are simple text files with a format described in the Pattern-HOWTO. They can be updated as a package or individually.
If you update the protocol definitions, you need to clear the relevant iptables rules and re-enter them. This is because the pattern files are only read by iptables, not directly by the kernel.
Other things to know
By default, l7-filter looks at the first 10 packets or 2kB, whichever is smaller. These limits are somewhat conservative. It is well known that some HTTP connections (those that involve large cookies), for instance, need more packets to be matched.
You can alter the number of packets at any time through /proc/net/layer7_numpackets. (i.e. "echo 16 > /proc/net/layer7_numpackets".)
In l7-filter versions 2.0 and forward, you can alter the number of bytes at module load time: "modprobe xt_layer7 maxdatalen=N" (ipt_layer7 in old versions), where N is in bytes. This should be used cautiously, since performance may decrease drastically with larger data sizes. To prevent you from accidentally bringing down your network, there is an artificial limit of 65536 imposed. If you're sure you know what you're doing, you can remove this limit by editing ipt_layer7.c or xt_layer7.c in the kernel source.
It's possible (although rare) for a connection to be matchable by more than one pattern. The patterns are tested in the order you specified with iptables. After a match is made, l7-filter does not continue testing that connection, so changing the order of your rules may change what happens.
Sometimes important messages go only to the system log, not the terminal you are working at. Such messages include notifications that regular expressions failed to compile and various things that tc generates. A useful command is "tail -f /var/log/messages".
--reject-with type
Type可以是icmp-net-unreachable、icmp-host-unreachable、icmp-port-nreachable、icmp-proto-unreachable?nbsp;icmp-net-prohibited 或?nbsp;icmp-host-prohibitedQ该cd会返回相应的ICMP错误信息Q默认是port-unreachableQ。选项 echo-reply也是允许的;它只能用于指定ICMP ping包的规则中,生成ping的回应。最后,选项tcp-reset可以用于在INPUT链中,或自INPUT链调用的规则Q只匚wTCP协议Q将回应一个TCP RST包?br />
TOS
用来讄IP包的首部八位tos。只能用于mangle表?br />
--set-tos tos
你可以用一个数值型的TOS |或者用iptables -j TOS -h 来查看有效TOS名列表?br />
MIRROR
q是一个试验示范目标,可用于{换IP首部字段中的源地址和目标地址Q再传送该?q只适用于INPUT、FORWARD和OUTPUT链,以及只调用它们的用户自定义链?br />
SNAT
q个目标只适用于nat表的POSTROUTING链。它规定修改包的源地址Q此q接以后所有的包都会被影响Q,停止对规则的查,它包含选项Q?br />
--to-source <ipaddr>[-<ipaddr>][:port-port]
可以指定一个单一的新的IP地址Q一个IP地址范围Q也可以附加一个端口范_只能在指?p tcp 或?p udp的规则里Q。如果未指定端口范围Q源端口?12以下的(端口Q会被安|ؓ其他?12以下的端口;512?024之间的端口会被安|ؓ1024以下的,其他端口会被安置?024或以上。如果可能,端口不会被修攏V?br />
--to-destiontion <ipaddr>[-<ipaddr>][:port-port]
可以指定一个单一的新的IP地址Q一个IP地址范围Q也可以附加一个端口范_只能在指?p tcp 或?p udp的规则里Q。如果未指定端口范围Q目标端口不会被修改?br />
MASQUERADE
只用于nat表的POSTROUTING链。只能用于动态获取IPQ拨Pq接Q如果你拥有静态IP地址Q你要用SNAT。伪装相当于l包发出时所l过接口的IP地址讄一个映像,当接口关闭连接会l止。这是因为当下一ơ拨h未必是相同的接口地址Q以后所有徏立的q接都将关闭Q。它有一个选项Q?br />
--to-ports <port>[-port>]
指定使用的源端口范围Q覆盖默认的SNAT源地址选择Q见上面Q。这个选项只适用于指定了-p tcp或?p udp的规则?br />
REDIRECT
只适用于nat表的PREROUTING和OUTPUT链,和只调用它们的用戯定义链。它修改包的目标IP地址来发送包到机器自w(本地生成的包被安|ؓ地址127.0.0.1Q。它包含一个选项Q?br />
--to-ports <port>[<port>]
指定使用的目的端口或端口范围Q不指定的话Q目标端口不会被修改。只能用于指定了-p tcp ?nbsp;-p udp的规则?br />
DIAGNOSTICS
诊断
不同的错误信息会打印成标准错误:退?a class="UBBWordLink" target="_blank">代码0表示正确。类g不对的或者滥用的命o行参数错误会q回错误代码2Q其他错误返?a class="UBBWordLink" target="_blank">代码??br />
BUGS
臭虫
Check is not implemented (yet).
查还未完成?br />
COMPATIBILITY WITH IPCHAINS
与ipchains的兼Ҏ?br />
iptables和Rusty Russell的ipchains非常怼。主要区别是INPUT 铑֏用于q入本地L的包,而OUTPUT只用于自本地L生成的包。因此每个包只经q三个链的一个;以前转发的包会经q所有三个链。其他主要区别是 -i 引用q入接口Q?o引用输出接口Q两者都适用于进入FORWARD铄包。当和可选扩展模块一起用默认过滤器表时Qiptables是一个纯_的包过滤器。这能大大减以前对IP伪装和包qol合使用的淆,所以以下选项作了不同的处理:
-j MASQ
-M -S
-M -L
在iptables中有几个不同的链?br />
SEE ALSO
参见
iptables-HOWTO有详l的iptables用法,对netfilter-hacking-HOWTO也有详细的本质说明?br />
AUTHORS
作?br />
Rusty Russell wrote iptables, in early consultation with Michael Neuling.
Marc Boucher made Rusty abandon ipnatctl by lobbying for a generic packet selection framework in iptables, then wrote the mangle table, the owner match, the mark stuff, and ranaround doing cool stuff everywhere.
James Morris wrote the TOS target, and tos match.
Jozsef Kadlecsik wrote the REJECT target.
The Netfilter Core Team is: Marc Boucher, Rusty Russell.
]]>耉cas单点dpȝ的php客户端用注意事?/title>http://www.tkk7.com/jjwwhmm/archive/2008/05/07/198897.htmlponyponyWed, 07 May 2008 06:00:00 GMThttp://www.tkk7.com/jjwwhmm/archive/2008/05/07/198897.htmlhttp://www.tkk7.com/jjwwhmm/comments/198897.htmlhttp://www.tkk7.com/jjwwhmm/archive/2008/05/07/198897.html#Feedback3http://www.tkk7.com/jjwwhmm/comments/commentRss/198897.htmlhttp://www.tkk7.com/jjwwhmm/services/trackbacks/198897.html
在集成phpCAS的时?pȝ报出一些错? Warning: include_once(DB.php) [function.include-once]: failed to open stream: No such file or directory in /opt/httproot/phpMyAdmin/cas/PGTStorage/pgt-db.php on line 11
Warning: include_once() [function.include]: Failed opening 'DB.php' for inclusion (include_path='.:/usr/local/php-5.2.5/lib/php') in /opt/httproot/phpMyAdmin/cas/PGTStorage/pgt-db.php on line 11
Warning: session_start() [function.session-start]:
Cannot send session cookie - headers already sent by (output started at
/opt/httproot/phpMyAdmin/cas/PGTStorage/pgt-db.php:11) in /opt/httproot/phpMyAdmin/cas/client.php on line 489
Warning: session_start() [function.session-start]:
Cannot send session cache limiter - headers already sent (output
started at /opt/httproot/phpMyAdmin/cas/PGTStorage/pgt-db.php:11) in /opt/httproot/phpMyAdmin/cas/client.php on line 489
Warning: Cannot modify header information - headers already sent
by (output started at
/opt/httproot/phpMyAdmin/cas/PGTStorage/pgt-db.php:11) in /opt/httproot/phpMyAdmin/cas/client.php on line 880
查了些资?重新安装了php后问题解?
1.在编译php的时?要加?-with-curl, --with-openssl, --with-dom, --with-zlibq些选项
如果pȝ中还没有安装curl?
wget http://curl.haxx.se/download/curl-7.18.1.tar.gz
tar -zxvf curl-7.18.1.tar.gz
./configure --prefix=/usr/local/curl
make
sudo make install
~译安装phpQ?br />
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-mysql=/usr/local/mysql/ --with-libxml-dir=/usr/local/libxml-2.6.30/ --with-gd=/usr/local/gd-2.0.35/ --with-curl=/usr/local/curl/ --with-openssl --with-zlib --with-pear=/usr/local/php_pear
make
make test
sudo make install
注意Q有可能pear安装不成功,要看你下载的php包,安装完后到php源代码目录下的pear下看看是有有错,否则Q要C载一个pear的安装包Q?br />
wget http://pear.php.net/install-pear.phar
再执行makeQmake install
核心提示Q安装了一台服务器Q只开放了httpsQ没有开放http
把启动命?usr/local/bin/apachectl startssl写到/etc/rc.local里,重启服务器?
发现apacheq没有自动运行?手动q行 [root@localhost]# /usr/local/bin/apachectl
restart httpd not running, trying to start Apach.....
安装了一台服务器Q只开放了httpsQ没有开放http
把启动命?usr/local/bin/apachectl startssl写到/etc/rc.local里,重启服务器?br />
发现apacheq没有自动运行?br />
手动q行
[root@localhost]# /usr/local/bin/apachectl restart
httpd not running, trying to start
Apache/2.2.0 mod_ssl/2.2.0 (PassPhraseDialog)
Some of your private key files are encrypted for security reasons.
In order to read them you have to provide the pass phrases.
]]>安装apache的错误问题解? error,APR with the bundled APR-utilq错误解决http://www.tkk7.com/jjwwhmm/archive/2008/02/25/181888.htmlponyponyMon, 25 Feb 2008 01:42:00 GMThttp://www.tkk7.com/jjwwhmm/archive/2008/02/25/181888.htmlhttp://www.tkk7.com/jjwwhmm/comments/181888.htmlhttp://www.tkk7.com/jjwwhmm/archive/2008/02/25/181888.html#Feedback6http://www.tkk7.com/jjwwhmm/comments/commentRss/181888.htmlhttp://www.tkk7.com/jjwwhmm/services/trackbacks/181888.htmlconfigure: error,APR with the bundled APR-utilq错误解决