Discuz!官方免费开源建站系统

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索

拒绝sql蠕虫,骚扰....

 关闭 [复制链接]
iamok 发表于 2003-5-6 20:53:41 | 显示全部楼层 |阅读模式
sorry ..搞错了...

[ Last edited by iamok on 2003-5-7 at 12:03 AM ]
szboy 发表于 2003-5-6 21:39:30 | 显示全部楼层
最好详细点.
回复

使用道具 举报

 楼主| iamok 发表于 2003-5-6 23:15:06 | 显示全部楼层


  1. #!/bin/sh
  2. #
  3. # Generated iptables firewall script for the Linux 2.4 kernel
  4. # Script generated by Easy Firewall Generator for IPTables
  5. # copyright 2002 Timothy Scott Morizot
  6. #
  7. # Redhat chkconfig comments - firewall applied early,
  8. #                             removed late
  9. # chkconfig: 2345 08 92
  10. # description: This script applies or removes iptables firewall rules
  11. #
  12. # This generator is primarily designed for RedHat installations,
  13. # although it should be adaptable for others.
  14. #
  15. # It can be executed with the typical start and stop arguments.
  16. # If used with stop, it will stop after flushing the firewall.
  17. # The save and restore arguments will save or restore the rules
  18. # from the /etc/sysconfig/iptables file.

  19. # Redhat installation instructions
  20. #
  21. # 1. Ensure that ipchains will not automatically start.
  22. #    chkconfig --level 0123456 ipchains off
  23. #    This will make sure that the ipchains init.d script
  24. #    is not linked to an S file in any of the rc directories.
  25. #
  26. # 2. Stop ipchains if it's running.
  27. #    service ipchains stop
  28. #
  29. # 3. Execute lsmod to see if the ipchains kernel module is still loaded.
  30. #    If it is, use rmmod to unload it. -- rmmod ipchains
  31. #
  32. # 4. Have the system link the iptables init.d startup script into run states
  33. #    2, 3, and 5.
  34. #    chkconfig --level 235 iptables on
  35. #
  36. # 5. Save this script and execute it to load the ruleset from this file.
  37. #    You may need to run the dos2unix command on it to remove carraige returns.
  38. #
  39. # 6. Save the ruleset to /etc/sysconfig/iptables.  This can be done two ways.
  40. #    service iptables save
  41. #    iptables-save > /etc/sysconfig/iptables
  42. #
  43. # 7. The ruleset will be restored by the /etc/init.d/iptables script on boot.
  44. #
  45. # 8. Alternatively, save the /etc/init.d/iptables script and copy this script
  46. #    to /etc/init.d/iptables.  It accepts stop, start, save, and restore
  47. #    arguments.
  48. #
  49. # NOTE: The /etc/init.d/iptables script can be modified to run this script
  50. # instead.  If you do so, save a copy so you can reapply your modifications
  51. # after upgrading the iptables package.  The advantage of using this script for
  52. # the ongoing operation of the firewall is it gives you greater control over
  53. # the modules and rulesets used.  The above is simpler, however.

  54. ###############################################################################
  55. #
  56. # Local Settings
  57. #

  58. # sysctl location.  If set, it will use sysctl to adjust the kernel parameters.
  59. # If this is set to the empty string (or is unset), the use of sysctl
  60. # is disabled.

  61. SYSCTL="/sbin/sysctl -w"

  62. # To echo the value directly to the /proc file instead
  63. # SYSCTL=""

  64. # IPTables Location - adjust if needed

  65. IPT="/sbin/iptables"
  66. IPTS="/sbin/iptables-save"
  67. IPTR="/sbin/iptables-restore"

  68. # Internet Interface
  69. INET_IFACE="eth0"
  70. #INET_ADDRESS="192.168.2.150"

  71. # Localhost Interface

  72. LO_IFACE="lo"
  73. LO_IP="127.0.0.1"



  74. ###############################################################################
  75. #
  76. # Load Modules
  77. #

  78. echo "Loading kernel modules ..."

  79. # You should uncomment the line below and run it the first time just to
  80. # ensure all kernel module dependencies are OK.  There is no need to run
  81. # every time, however.

  82. # /sbin/depmod -a

  83. # Unless you have kernel module auto-loading disabled, you should not
  84. # need to manually load each of these modules.  Other than ip_tables,
  85. # ip_conntrack, and some of the optional modules, I've left these
  86. # commented by default.  Uncomment if you have any problems or if
  87. # you have disabled module autoload.  Note that some modules must
  88. # be loaded by another kernel module.

  89. # core netfilter module
  90. /sbin/modprobe ip_tables

  91. # the stateful connection tracking module
  92. /sbin/modprobe ip_conntrack

  93. # filter table module
  94. /sbin/modprobe iptable_filter

  95. # mangle table module
  96. # /sbin/modprobe iptable_mangle

  97. # nat table module
  98. # /sbin/modprobe iptable_nat

  99. # LOG target module
  100. /sbin/modprobe ipt_LOG

  101. # This is used to limit the number of packets per sec/min/hr
  102. /sbin/modprobe ipt_limit

  103. # masquerade target module
  104. # /sbin/modprobe ipt_MASQUERADE

  105. # filter using owner as part of the match
  106. # /sbin/modprobe ipt_owner

  107. # REJECT target drops the packet and returns an ICMP response.
  108. # The response is configurable.  By default, connection refused.
  109. # /sbin/modprobe ipt_REJECT

  110. # This target allows packets to be marked in the mangle table
  111. # /sbin/modprobe ipt_mark

  112. # This target affects the TCP MSS
  113. # /sbin/modprobe ipt_tcpmss

  114. # This match allows multiple ports instead of a single port or range
  115. # /sbin/modprobe multiport

  116. # This match checks against the TCP flags
  117. /sbin/modprobe ipt_state

  118. # This match catches packets with invalid flags
  119. /sbin/modprobe ipt_unclean

  120. # The ftp nat module is required for non-PASV ftp support
  121. #/sbin/modprobe ip_nat_ftp

  122. # the module for full ftp connection tracking
  123. #/sbin/modprobe ip_conntrack_ftp

  124. # the module for full irc connection tracking
  125. #/sbin/modprobe ip_conntrack_irc


  126. ###############################################################################
  127. #
  128. # Kernel Parameter Configuration
  129. #

  130. # Required to enable IPv4 forwarding.
  131. # Redhat users can try setting FORWARD_IPV4 in /etc/sysconfig/network to true
  132. #if [ "$SYSCTL" = "" ]
  133. #then
  134. #    echo "1" > /proc/sys/net/ipv4/ip_forward
  135. #else
  136. #    $SYSCTL net.ipv4.ip_forward="1"
  137. #fi

  138. # This enables dynamic address hacking.
  139. # This may help if you have a dynamic IP address \(e.g. slip, ppp, dhcp\).
  140. if [ "$SYSCTL" = "" ]
  141. then
  142.     echo "1" > /proc/sys/net/ipv4/ip_dynaddr
  143. else
  144.     $SYSCTL net.ipv4.ip_dynaddr="1"
  145. fi

  146. # This enables source validation by reversed path according to RFC1812.
  147. # In other words, did the response packet originate from the same interface
  148. # through which the source packet was sent?  It's recommended for single-homed
  149. # systems and routers on stub networks.  Since those are the configurations
  150. # this firewall is designed to support, I turn it on by default.
  151. # Turn it off if you use multiple NICs connected to the same network.
  152. if [ "$SYSCTL" = "" ]
  153. then
  154.     echo "1" > /proc/sys/net/ipv4/conf/all/rp_filter
  155. else
  156.     $SYSCTL net.ipv4.conf.all.rp_filter="1"
  157. fi

  158. # This option allows a subnet to be firewalled with a single IP address.
  159. # It's used to build a DMZ.  Since that's not a focus of this firewall
  160. # script, it's not enabled by default, but is included for reference.
  161. # See: [url]http://www.sjdjweis.com/linux/proxyarp/[/url]
  162. #if [ "$SYSCTL" = "" ]
  163. #then
  164. #    echo "1" > /proc/sys/net/ipv4/conf/all/proxy_arp
  165. #else
  166. #    $SYSCTL net.ipv4.conf.all.proxy_arp="1"
  167. #fi


  168. ###############################################################################
  169. #
  170. # Flush Any Existing Rules or Chains
  171. #

  172. echo "Flushing Tables ..."

  173. # Reset Default Policies
  174. $IPT -P INPUT ACCEPT
  175. $IPT -P FORWARD ACCEPT
  176. $IPT -P OUTPUT ACCEPT
  177. $IPT -t nat -P PREROUTING ACCEPT
  178. $IPT -t nat -P POSTROUTING ACCEPT
  179. $IPT -t nat -P OUTPUT ACCEPT
  180. $IPT -t mangle -P PREROUTING ACCEPT
  181. $IPT -t mangle -P OUTPUT ACCEPT

  182. # Flush all rules
  183. $IPT -F
  184. $IPT -t nat -F
  185. $IPT -t mangle -F

  186. # Erase all non-default chains
  187. $IPT -X
  188. $IPT -t nat -X
  189. $IPT -t mangle -X

  190. ###############################################################################
  191. #
  192. # Rules Configuration
  193. #

  194. ###############################################################################
  195. #
  196. # Filter Table
  197. #
  198. ###############################################################################

  199. # Set Policies

  200. $IPT -P INPUT DROP
  201. $IPT -P OUTPUT DROP
  202. $IPT -P FORWARD DROP

  203. ###############################################################################
  204. #
  205. # User-Specified Chains
  206. #
  207. # Create user chains to reduce the number of rules each packet
  208. # must traverse.

  209. echo "Create and populate custom rule chains ..."

  210. # Create a chain to filter INVALID packets

  211. $IPT -N bad_packets

  212. # Create another chain to filter bad tcp packets

  213. $IPT -N bad_tcp_packets

  214. # Create separate chains for icmp, tcp (incoming and outgoing),
  215. # and incoming udp packets.

  216. $IPT -N icmp_packets

  217. # Used for UDP packets inbound from the Internet
  218. $IPT -N udp_inbound

  219. # Used to block outbound UDP services from internal network
  220. # Default to allow all
  221. $IPT -N udp_outbound

  222. # Used to allow inbound services if desired
  223. # Default fail except for established sessions
  224. $IPT -N tcp_inbound

  225. # Used to block outbound services from internal network
  226. # Default to allow all
  227. $IPT -N tcp_outbound

  228. ###############################################################################
  229. #
  230. # Populate User Chains
  231. #

  232. # bad_packets chain
  233. #
  234. # Drop INVALID packets immediately

  235. $IPT -A bad_packets -p ALL -m state --state INVALID -j LOG \
  236.     --log-prefix "Invalid packet:"
  237. $IPT -A bad_packets -p ALL -m state --state INVALID -j DROP

  238. # Then check the tcp packets for additional problems
  239. $IPT -A bad_packets -p tcp -j bad_tcp_packets

  240. # All good, so return
  241. $IPT -A bad_packets -p ALL -j RETURN

  242. # bad_tcp_packets chain
  243. #
  244. # All tcp packets will traverse this chain.
  245. # Every new connection attempt should begin with
  246. # a syn packet.  If it doesn't, it is likely a
  247. # port scan.  This drops packets in state
  248. # NEW that are not flagged as syn packets.


  249. $IPT -A bad_tcp_packets -p tcp ! --syn -m state --state NEW -j LOG \
  250.     --log-prefix "New not syn:"
  251. $IPT -A bad_tcp_packets -p tcp ! --syn -m state --state NEW -j DROP

  252. # All good, so return
  253. $IPT -A bad_tcp_packets -p tcp -j RETURN

  254. # icmp_packets chain
  255. #
  256. # This chain is for inbound (from the Internet) icmp packets only.
  257. # Type 8 (Echo Request) is not accepted by default
  258. # Enable it if you want remote hosts to be able to reach you.
  259. # 11 (Time Exceeded) is the only one accepted
  260. # that would not already be covered by the established
  261. # connection rule.  Applied to INPUT on the external interface.
  262. #
  263. # See: [url]http://www.ee.siue.edu/~rwalden/networking/icmp.html[/url]
  264. # for more info on ICMP types.
  265. #
  266. # Note that the stateful settings allow replies to ICMP packets.
  267. # These rules allow new packets of the specified types.

  268. # Echo - uncomment to allow your system to be pinged.
  269. # $IPT -A icmp_packets -p ICMP -s 0/0 --icmp-type 8 -j ACCEPT

  270. # Time Exceeded
  271. #$IPT -A icmp_packets -p ICMP -s 0/0 --icmp-type 11 -j ACCEPT

  272. # Not matched, so return so it will be logged
  273. #$IPT -A icmp_packets -p ICMP -j RETURN

  274. # TCP & UDP
  275. # Identify ports at:
  276. #    [url]http://www.chebucto.ns.ca/~rakerman/port-table.html[/url]
  277. #    [url]http://www.iana.org/assignments/port-numbers[/url]

  278. # udp_inbound chain
  279. #
  280. # This chain describes the inbound UDP packets it will accept.
  281. # It's applied to INPUT on the external or Internet interface.
  282. # Note that the stateful settings allow replies.
  283. # These rules are for new requests.
  284. # It drops netbios packets (windows) immediately without logging.

  285. # Drop netbios calls
  286. # Please note that these rules do not really change the way the firewall
  287. # treats netbios connections.  Connections from the localhost and
  288. # internal interface (if one exists) are accepted by default.
  289. # Responses from the Internet to requests initiated by or through
  290. # the firewall are also accepted by default.  To get here, the
  291. # packets would have to be part of a new request received by the
  292. # Internet interface.  You would have to manually add rules to
  293. # accept these.  I added these rules because some network connections,
  294. # such as those via cable modems, tend to be filled with noise from
  295. # unprotected Windows machines.  These rules drop those packets
  296. # quickly and without logging them.  This prevents them from traversing
  297. # the whole chain and keeps the log from getting cluttered with
  298. # chatter from Windows systems.
  299. #$IPT -A udp_inbound -p UDP -s 192.168.2.0/24 --destination-port 137 -j ACCEPT
  300. #$IPT -A udp_inbound -p UDP -s 192.168.2.0/24 --destination-port 138 -j ACCEPT


  301. # Not matched, so return for logging
  302. #$IPT -A udp_inbound -p UDP -j RETURN

  303. # udp_outbound chain
  304. #
  305. # This chain is used with a private network to prevent forwarding for
  306. # UDP requests on specific protocols.  Applied to the FORWARD rule from
  307. # the internal network.  Ends with an ACCEPT


  308. # No match, so ACCEPT
  309. #$IPT -A udp_outbound -p UDP -d 0/0 -j ACCEPT

  310. # tcp_inbound chain
  311. #
  312. # This chain is used to allow inbound connections to the
  313. # system/gateway.  Use with care.  It defaults to none.
  314. # It's applied on INPUT from the external or Internet interface.

  315. # Web Server

  316. # HTTP
  317. $IPT -A tcp_inbound -p TCP -s 0/0 --destination-port 80 -j ACCEPT

  318. # HTTPS (Secure Web Server)
  319. #$IPT -A tcp_inbound -p TCP -s 0/0 --destination-port 443 -j ACCEPT

  320. # FTP Server (Control)
  321. $IPT -A tcp_inbound -p TCP -s 0/0 --destination-port 21 -j ACCEPT

  322. # FTP Client (Data Port for non-PASV transfers)
  323. $IPT -A tcp_inbound -p TCP -s 0/0 --source-port 20 -j ACCEPT

  324. # Passive FTP
  325. #
  326. # With passive FTP, the server provides a port to the client
  327. # and allows the client to initiate the connection rather
  328. # than initiating the connection with the client from the data port.
  329. # Web browsers and clients operating behind a firewall generally
  330. # use passive ftp transfers.  A general purpose FTP server
  331. # will need to support them.
  332. #
  333. # However, by default an FTP server will select a port from the entire
  334. # range of high ports.  It is not particularly safe to open all
  335. # high ports.  Fortunately, that range can be restricted.  This
  336. # firewall presumes that the range has been restricted to a specific
  337. # selected range.  That range must also be configured in the ftp server.
  338. #
  339. # Instructions for specifying the port range for the wu-ftpd server
  340. # can be found here:
  341. # [url]http://www.wu-ftpd.org/man/ftpaccess.html[/url]
  342. # (See the passive ports option.)
  343. #
  344. # Instructions for the ProFTPD server can be found here:
  345. # [url]http://proftpd.linux.co.uk/localsite/Userguide/linked/x861.html[/url]

  346. $IPT -A tcp_inbound -p TCP -s 0/0 --destination-port 58000:64000 -j ACCEPT

  347. # sshd
  348. $IPT -A tcp_inbound -p TCP -s 0/0 --destination-port 22 -j ACCEPT




  349. # mysql
  350. #$IPT -A tcp_inbound -p TCP -s 0/0 --destination-port 3306 -j ACCEPT


  351. #netbios
  352. #$IPT -A tcp_inbound -p TCP -s 192.168.2.0/24 --destination-port 139 -j ACCEPT


  353. # Not matched, so return so it will be logged
  354. $IPT -A tcp_inbound -p TCP -j RETURN

  355. # tcp_outbound chain
  356. #
  357. # This chain is used with a private network to prevent forwarding for
  358. # requests on specific protocols.  Applied to the FORWARD rule from
  359. # the internal network.  Ends with an ACCEPT


  360. # No match, so ACCEPT
  361. #$IPT -A tcp_outbound -p TCP -s 0/0 -j ACCEPT

  362. ###############################################################################
  363. #
  364. # INPUT Chain
  365. #

  366. echo "Process INPUT chain ..."

  367. # Allow all on localhost interface
  368. $IPT -A INPUT -p ALL -i lo -s 127.0.0.1 -j ACCEPT
  369. $IPT -A INPUT -p ALL -s 192.168.0.0/16 -j DROP
  370. $IPT -A INPUT -p ALL -s 10.0.0.0/8 -j DROP
  371. $IPT -A INPUT -p ALL -s 172.16.0.0/12 -j DROP
  372. $IPT -A INPUT -p ALL -s 127.0.0.0/8 -j DROP

  373. # Drop bad packets
  374. $IPT -A INPUT -p ALL -j bad_packets

  375. # DOCSIS compliant cable modems
  376. # Some DOCSIS compliant cable modems send IGMP multicasts to find
  377. # connected PCs.  The multicast packets have the destination address
  378. # 224.0.0.1.  You can accept them.  If you choose to do so,
  379. # Uncomment the rule to ACCEPT them and comment the rule to DROP
  380. # them  The firewall will drop them here by default to avoid
  381. # cluttering the log.  The firewall will drop all multicasts
  382. # to the entire subnet (224.0.0.1) by default.  To only affect
  383. # IGMP multicasts, change '-p ALL' to '-p 2'.  Of course,
  384. # if they aren't accepted elsewhere, it will only ensure that
  385. # multicasts on other protocols are logged.
  386. # Drop them without logging.

  387. # The rule to accept the packets.
  388. # $IPT -A INPUT -p ALL -d 224.0.0.1 -j ACCEPT


  389. # Inbound Internet Packet Rules

  390. # Accept Established Connections
  391. $IPT -A INPUT -p ALL -i $INET_IFACE -m state --state ESTABLISHED,RELATED \
  392.      -j ACCEPT

  393. # Route the rest to the appropriate user chain
  394. $IPT -A INPUT -p TCP -i $INET_IFACE -j tcp_inbound
  395. $IPT -A INPUT -p UDP -i $INET_IFACE -j udp_inbound
  396. #$IPT -A INPUT -p ICMP -i $INET_IFACE -j icmp_packets

  397. # Drop without logging broadcasts that get this far.
  398. # Cuts down on log clutter.
  399. # Comment this line if testing new rules that impact
  400. # broadcast protocols.
  401. #$IPT -A INPUT -p ALL -d 255.255.255.255 -j DROP

  402. # Log packets that still don't match
  403. $IPT -A INPUT -m limit --limit 1/second --limit-burst 1 -j LOG \
  404.      --log-prefix "INPUT packet died: "
  405. $IPT -A INPUT -m limit --limit 1/second --limit-burst 1 -j DROP
  406. ###############################################################################
  407. #
  408. # FORWARD Chain
  409. #

  410. echo "Process FORWARD chain ..."

  411. # Used if forwarding for a private network


  412. ###############################################################################
  413. #
  414. # OUTPUT Chain
  415. #

  416. echo "Process OUTPUT chain ..."

  417. # Generally trust the firewall on output

  418. # However, invalid icmp packets need to be dropped
  419. # to prevent a possible exploit.
  420. $IPT -A OUTPUT -m state -p icmp --state INVALID -j DROP

  421. # Localhost
  422. #$IPT -A OUTPUT -p ALL -o $LO_IFACE -s 127.0.0.1 -j ACCEPT

  423. # To internet
  424. #$IPT -A OUTPUT -p ALL -o $INET_IFACE -j ACCEPT
  425. $IPT -A OUTPUT -p ALL -j ACCEPT
  426. # Log packets that still don't match
  427. #$IPT -A OUTPUT -m limit --limit 3/minute --limit-burst 3 -j LOG \
  428. #     --log-prefix "OUTPUT packet died: "




复制代码





更多资讯查看bbs.be10.net与www.google.com

[ Last edited by iamok on 2003-5-7 at 12:04 AM ]
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|Discuz! 官方站 ( 皖ICP备16010102号 )star

GMT+8, 2024-5-17 20:26 , Processed in 0.158096 second(s), 16 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表