iptables 标签文章 - 李海鑫个人博客

(2012-3-8)windows防arp病毒的批处理脚本

编辑文章

winxp绑定

本文HTML永久地址doc

下面是我自己用的脚本,由于我的宽带网络与其他邻居共享使用,为了防止邻居非法访问电脑,所以在【开始】---【程序】---【启动】里添加Anti-arp.bat批处理文件,内容如下:

@echo off 
:清空arp
arp -d
:禁止其他ip访问本地,C8-3A-35-C6-E8-3B为本地网卡MAC
for /l %%i in (2,1,254) do arp -s 192.168.3.%%i C8-3A-35-C6-E8-3B >nul 2>nul 
:排除其他服务器,192.168.3.2为我局域网内另外一台路由器,192.168.3.1为路由器ip
arp -s 192.168.3.2 B0-48-7A-62-4D-4A
arp -s 192.168.3.1 00-0e-a6-3f-d8-50
exit 

运行后,这样后本地电脑只能ping通网关和192.168.3.2那台路由器,同理,局域网的邻居也ping不通我的电脑,达到简易防火墙和反arp病毒功能。

windows 7绑定

由于windows 7不能使用arp -s绑定默认网关,会提示:ARP 项添加失败: 请求的操作需要提升。 (英文版提示:The ARP entry addition failed: Access is denied. ) 需要通过netsh命令绑定

第一步:检查自己的网卡接口序号

首先点击开始-运行,输入CMD回车,进入DOS模式。然后输入:netsh interface ipv4 show neighbors 查看一下地址的属性,如图所示

“192.168.1.1 f4-ec-38-72-35-b0” 也就是网关的IP地址,后面的类型是“可以访问”,这代表着此地 址还没有绑定。上面的接口是:25。(记住这个25,每台机器的接口号都不太一样,大家可以自己查一下)

第二步:使用命令绑定地址

netsh interface ipv4 set neighbors 25 "192.168.1.1" "f4-ec-38-72-35-b0" store=active
netsh interface ipv4 set neighbors 25 "192.168.1.1" "f4-ec-38-72-35-b0" store=persistent

“store=active”代表命令当前有效,重启后失效。“store=persistent”代表永久有效,想要恢复为动态时,使 用"arp -d"删除arp缓存信息即可。

第三步:检查效果

在命令行下输入arp -a,然后回车。显示如图中所示“192.168.10.1 f4-ec-38-72-35-b0 静态”。表示已经生效,IP 地址与MAC地址成功绑定了!

bat批处理文件

arp -d
for /l %%i in (2,1,254) do netsh interface ipv4 set neighbors 11 "192.168.3.%%i" "84-4B-F5-B8-7C-D7" store=persistent >nul 2>nul 
netsh interface ipv4 set neighbors 11 "192.168.3.1" "10-6f-3f-38-38-65" store=persistent
netsh interface ipv4 set neighbors 11 "192.168.3.2" "78-44-76-25-47-2d" store=persistent
netsh interface ipv4 set neighbors 11 "192.168.3.3" "00-1f-33-37-2f-84" store=persistent
netsh interface ipv4 set neighbors 11 "192.168.3.82" "24-db-ac-df-0a-82" store=persistent
netsh interface ipv4 set neighbors 11 "192.168.3.12" "70-72-3c-d5-3f-d4" store=persistent
exit 

windows7 相关命令

  • 查看网卡ID netsh interface ipv4 show neighbors
  • 清空永久还原(需要重启电脑生效)netsh i i reset
  • 清空临时还原(不需要电脑重启)arp -d
  • 查看当前的arp列表 arp -a

(2011-2-27)iptables的数据包长度匹配模块

编辑文章 没有评论 :

记录一下linux下防火墙iptables xt_length,ko(MTU值)的匹配

本文HTML永久地址doc

iptables -A INPUT -p icmp --icmp-type 8 -m length --length 92 -j ACCEPT  --匹配MTU值刚好为92Bytes的封包
iptables -A INPUT -p icmp --icmp-type 8 -m length ! --length 92 -j ACCEPT  --匹配MTU值刚好不是92Bytes的封包
iptables -A INPUT -p icmp --icmp-type 8 -m length --length 92: -j ACCEPT   --匹配MTU值刚好大于等于92Bytes的封包
iptables -A INPUT -p icmp --icmp-type 8 -m length --length :92 -j ACCEPT   --匹配MTU值刚好小于等于92Bytes的封包
iptables -A INPUT -p icmp --icmp-type 8 -m length --length 50:92 -j ACCEPT    --匹配MTU值介于50~92Bytes的封包

MTU值=IP包头(20字节)+ICMP包头(8字节)+DATA 所以防火墙下面语句

iptables -A INPUT -p icmp --icmp-type 8 -m length --length 88 -j ACCEPT
iptables -A INPUT -p icmp --icmp-type 8 DROP

使用默认的ping是不能ping通的,只有使用下面方法

windows下:

ping -l 60 ipaddress

linux下:

ping -s 60 ipaddress

(2011-2-25)linux 防DDOS防火墙脚本

编辑文章 没有评论 :
vi /usr/src/iptables-ddos.sh
echo "/bin/sh /usr/src/iptables-ddos.sh" >> /etc/rc.local
脚本如下:
#!/bin/bash
modprobe ipt_recent ip_list_hash_size=0 ip_list_tot=16384 ip_pkt_list_tot=200
iptables -F SYN_FLOODING
iptables -X SYN_FLOODING
iptables -N SYN_FLOODING
iptables -t filter -F

iptables -A INPUT -i eth0 -m state --state INVALID -j DROP
iptables -A INPUT -p all -m state --state ESTABLISHE,RELATED -j ACCEPT

iptables -A INPUT -i eth0 -p tcp --syn -m multiport --dports 80,443 -m limit --limit 1/m --limit-burst 300 -j ACCEPT
iptables -A INPUT -i eth0 -p tcp --syn -m multiport --dports 80,443 -j SYN_FLOODING
iptables -A SYN_FLOODING -i eth0 -p tcp --syn -m multiport --dports 80,443 -m recent --name SYN_FLOOD --update --second 120 --hitcount 1 -j  ACCEPT
iptables -A SYN_FLOODING -i eth0 -p tcp --syn -m multiport --dports 80,443 -m recent --name SYN_FLOOD --set
iptables -A SYN_FLOODING -i eth0 -p tcp --syn -m multiport --dports 80,443 -j DROP

#linux DDOS

echo 2 > /proc/sys/net/ipv4/tcp_syn_retries
echo 2 > /proc/sys/net/ipv4/tcp_synack_retries
echo 2048 > /proc/sys/net/ipv4/tcp_max_syn_backlog
echo 1 > /proc/sys/net/ipv4/tcp_syncookies

#禁止连续ping
iptables -A INPUT -p icmp --icmp-type 8 -m recent --name icmp_db --update --second 60 --hitcount 6 -j DROP
iptables -A INPUT -p icmp --icmp-type 8 -m recent --name icmp_db --set 

#防止扫描端口(包含过滤连续ping功能,所以禁止ping要放在前面)
iptables -A INPUT -p all -m state --state NEW -m recent --name port_scan --update --seconds 1800 --hitcount 10 -j DROP
iptables -A INPUT -p tcp --syn -m state --state NEW -m multiport --dports 22122,80,7777,1723 -j ACCEPT
iptables -A INPUT -p all -m recent --name port_scan --set

# ip 欺骗防护

iptables -A INPUT -i ! lo -s 127.0.0.0/8 -j DROP
iptables -A INPUT -p all -s 10.254.0.0/24 -j ACCEPT
iptables -A INPUT -p all -s 10.0.0.0/8 -j DROP
iptables -A INPUT -p all -s 172.16.0.0/12 -j DROP
iptables -A INPUT -p all -s 192.168.0.0/16 -j DROP
iptables -A INPUT -p ! udp -s 224.0.0.0/4 -j DROP

for i in /proc/sys/net/ipv4/conf/*/rp_filter; do
    echo 1 > $i
done