欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Win2003设置IP安全策略批处理脚本

程序员文章站 2022-04-10 10:55:24
复制代码 代码如下:rem =================开始================ netsh ipsec static ^ add policy name...
复制代码 代码如下:

rem =================开始================
netsh ipsec static ^
add policy name=bim
rem 添加2个动作,block和permit
netsh ipsec static ^
add filteraction name=permit action=permit
netsh ipsec static ^
add filteraction name=block action=block
rem 首先禁止所有访问
netsh ipsec static ^
add filterlist name=allaccess
netsh ipsec static ^
add filter filterlist=allaccess srcaddr=me dstaddr=any
netsh ipsec static ^
add rule name=blockallaccess policy=bim filterlist=allaccess filteraction=block
rem 开放某些ip无限制访问
netsh ipsec static ^
add filterlist name=unlimitedip
netsh ipsec static ^
add filter filterlist=unlimitedip srcaddr=61.128.128.67 dstaddr=me
netsh ipsec static ^
add rule name=allowunlimitedip policy=bim filterlist=unlimitedip filteraction=permit
rem 开放某些端口
netsh ipsec static ^
add filterlist name=opensomeport
netsh ipsec static ^
add filter filterlist=opensomeport srcaddr=any dstaddr=me dstport=20 protocol=tcp
netsh ipsec static ^
add filter filterlist=opensomeport srcaddr=any dstaddr=me dstport=21 protocol=tcp
netsh ipsec static ^
add filter filterlist=opensomeport srcaddr=any dstaddr=me dstport=80 protocol=tcp
netsh ipsec static ^
add filter filterlist=opensomeport srcaddr=any dstaddr=me dstport=3389 protocol=tcp
netsh ipsec static ^
add rule name=allowopensomeport policy=bim filterlist=opensomeport filteraction=permit
rem 开放某些ip可以访问某些端口
netsh ipsec static ^
add filterlist name=someipsomeport
netsh ipsec static ^
add filter filterlist=someipsomeport srcaddr=me dstaddr=any dstport=80 protocol=tcp
netsh ipsec static ^
add filter filterlist=someipsomeport srcaddr=61.128.128.68 dstaddr=me dstport=1433 protocol=tcp
netsh ipsec static ^
add rule name=allowsomeipsomeport policy=bim filterlist=someipsomeport filteraction=permit

"netsh"是windows 2000/xp/2003操作系统自身提供的命令行脚本实用工具,它允许用户在本地或远程显示或修改当前正在运行的计算机的网络配置。

netsh ipsec,听闻只有windows2003才能运行。在2003下测试的。
ip安全策略,我自身的理解就是:一个安全策略由一条条规则组成,而这些规则是由2部分组成的。首先要建立一个ip筛选器(用来指定那些地址)。然后呢是筛选器操作(用来指定对这些ip的操作,就是动作)一个安全策略编写完成了,首先要激活,才能使用,那就是指派。

下面用实例来说明,然后附带一些常用的。这个例子就是不允许ip为192.168.1.2的机器访问我的3389端口。'后面是注析

'建立一个名字叫xblue的安全策略先
netsh ipsec static add policy name=xblue
'建立一个ip筛选器,指定192.168.1.2
netsh ipsec static add filterlist name=denyip
netsh ipsec static add filter filterlist=denyip srcaddr=192.168.1.2 dstaddr=me dstport=3389 protocol=tcp
'建立一个筛选器操作
netsh ipsec static add filteraction name=denyact action=block
'加入规则到安全策略xblue
netsh ipsec static add rule name=kill3389 policy=xblue filterlist=denyip filteraction=denyact
'激活这个策略
netsh ipsec static set policy name=xblue assign=y

把安全策略导出
netsh ipsec static exportpolicy d:\ip.ipsec
删除所有安全策略
netsh ipsec static del all
把安全策略导入
netsh ipsec static importpolicy d:\ip.ipsec
激活这个策略
netsh ipsec static set policy name=策略名称 assign=y
入侵灵活运用
得到了61.90.227.136的sa权限。不过有策略限制,访问不到他的3389。我想用他的3389。
netsh ipsec static add filterlist name=welcomexblue
netsh ipsec static add filter filterlist=welcomexblue srcaddr=220.207.31.249 dstaddr=me dstport=7892 protocol=tcp
netsh ipsec static add rule name=letxblue policy=connrest filterlist=welcomexblue filteraction=permit
访问结果
可以访问了。
netsh ipsec static del rule name=letxblue policy=connrest
更改
netsh ipsec static set filter filterlist=welcomexblue srcaddr=220.207.31.249 dstaddr=me dstport=3389 protocol=tcp
删除
netsh ipsec static del rule name=letxblue policy=connrest
netsh ipsec static del filterlist name=welcomexblue