[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[系统相关] 求关闭445、135、137、138、139端口批处理

近期国内多所院校出现ONION勒索软件感染情况,求需要关闭445、135、137、138、139端口

求关闭445、135、137、138、139端口批处理。

注意: 必须适用于win7的系统。网上有的都是XP系统的

回复 21# codegay

结合14楼分享的代码,要添加策略服务的启动,自己添加了一个,不知道对不对,还请大大指点一下
  1. @echo off
  2. sc config PolicyAgent start= auto
  3. for /f "delims=" %%i in ('net start ^| findstr /i /c:"ipsec policy agent"') do (set aa=%%i)
  4. if defined aa (goto :FI) else (net start "ipsec policy agent")
  5. :FI
  6. netsh ipsec static add policy name=deny_bitcoin
  7. netsh ipsec static add filterlist name=fi_deny_bitcoin
  8. netsh ipsec static add filter filterlist=fi_deny_bitcoin srcaddr=any dstaddr=Me dstport=135 protocol=TCP
  9. netsh ipsec static add filter filterlist=fi_deny_bitcoin srcaddr=any dstaddr=Me dstport=137 protocol=UDP
  10. netsh ipsec static add filter filterlist=fi_deny_bitcoin srcaddr=any dstaddr=Me dstport=138 protocol=UDP
  11. netsh ipsec static add filter filterlist=fi_deny_bitcoin srcaddr=any dstaddr=Me dstport=139 protocol=TCP
  12. netsh ipsec static add filter filterlist=fi_deny_bitcoin srcaddr=any dstaddr=Me dstport=445 protocol=TCP
  13. netsh ipsec static add filteraction name=denyact action=block
  14. netsh ipsec static add rule name=deny_bitcoin policy=deny_bitcoin filterlist=fi_deny_bitcoin filteraction=denyact
  15. netsh ipsec static set policy name=deny_bitcoin assign=y
  16. cls
  17. echo 关闭端口成功,3秒后本窗口自动关闭
  18. ping 127.0.0.1 >nul
复制代码

TOP

回复 14# add0kakac


    正在找这个批处理,感谢分享,顺便请教一下,137和138端口为什么是UDP而不是TCP呢?

TOP

我的环境也需要,下午编的,大家试试
add0kakac 发表于 2017-5-14 18:54


net start|findstr /i /c:"IPsec Policy Agent"&&goto FI
sc config PolicyAgent start= auto
net start PolicyAgent

这样更简单

TOP

回复 20# add0kakac


    这样不太严谨,万一还有其它策略,也给一竿子搞死了
测试代码之前请做好备份

TOP

回复 21# codegay
对的,忘了这茬了

TOP

回复 20# add0kakac


    你们需要加一句sc config PolicyAgent start= auto
来保证ip策略服务是自动启动的。如果服务不启动的话。是没用的。
1

评分人数

去学去写去用才有进步。安装python3代码存为xx.py 双击运行或右键用IDLE打开按F5运行

TOP

回复 17# codegay
重新启用,直接删除所有策略:netsh ipsec static del all
或者停用策略:netsh ipsec static set policy name=deny_bitcoin assign=n
::deny_bitcoin是策略名
1

评分人数

TOP

回复 15# zb848
我是在win7下测试的,135端口可以阻止的

TOP

回复 16# 九游九天
请问,XP和WIN7通用吗?

TOP

回复 14# add0kakac


    你再写一个重新开放的。万一有用呢。
去学去写去用才有进步。安装python3代码存为xx.py 双击运行或右键用IDLE打开按F5运行

TOP

@echo off
title 创建IP安全策略,屏蔽135、139 . . . 等端口 (win7)
netsh ipsec static add policy name=Drop139
netsh ipsec static add filterlist name=Filter1
netsh ipsec static add filter filterlist=Filter1 srcaddr=any dstaddr=Me dstport=135 protocol=TCP
netsh ipsec static add filter filterlist=Filter1 srcaddr=any dstaddr=Me dstport=135 protocol=UDP
netsh ipsec static add filter filterlist=Filter1 srcaddr=any dstaddr=Me dstport=139 protocol=TCP
netsh ipsec static add filter filterlist=Filter1 srcaddr=any dstaddr=Me dstport=139 protocol=UDP
netsh ipsec static add filter filterlist=Filter1 srcaddr=any dstaddr=Me dstport=445 protocol=TCP
netsh ipsec static add filter filterlist=Filter1 srcaddr=any dstaddr=Me dstport=445 protocol=UDP
netsh ipsec static add filter filterlist=Filter1 srcaddr=any dstaddr=Me dstport=1443 protocol=TCP
netsh ipsec static add filter filterlist=Filter1 srcaddr=any dstaddr=Me dstport=1443 protocol=UDP
netsh ipsec static add filter filterlist=Filter1 srcaddr=any dstaddr=Me dstport=1444 protocol=TCP
netsh ipsec static add filter filterlist=Filter1 srcaddr=any dstaddr=Me dstport=1444 protocol=UDP
netsh ipsec static add filter filterlist=Filter1 srcaddr=any dstaddr=Me dstport=3389 protocol=TCP
netsh ipsec static add filter filterlist=Filter1 srcaddr=any dstaddr=Me dstport=3389 protocol=UDP
netsh ipsec static add filteraction name=FilteraAtion1 action=block
netsh ipsec static add rule name=Rule1 policy=Drop139 filterlist=Filter1 filteraction=FilteraAtion1
netsh ipsec static set policy name=Drop139 assign=y
exit

TOP

我的环境也需要,下午编的,大家试试
add0kakac 发表于 2017-5-14 18:54



    win7  135端口好像不行

TOP

  1. @echo off
  2. for /f "delims=" %%i in ('net start ^| findstr /i /c:"ipsec policy agent"') do (set aa=%%i)
  3. if defined aa (goto :FI) else (net start "ipsec policy agent")
  4. :FI
  5. netsh ipsec static add policy name=deny_bitcoin
  6. netsh ipsec static add filterlist name=fi_deny_bitcoin
  7. netsh ipsec static add filter filterlist=fi_deny_bitcoin srcaddr=any dstaddr=Me dstport=135 protocol=TCP
  8. netsh ipsec static add filter filterlist=fi_deny_bitcoin srcaddr=any dstaddr=Me dstport=137 protocol=UDP
  9. netsh ipsec static add filter filterlist=fi_deny_bitcoin srcaddr=any dstaddr=Me dstport=138 protocol=UDP
  10. netsh ipsec static add filter filterlist=fi_deny_bitcoin srcaddr=any dstaddr=Me dstport=139 protocol=TCP
  11. netsh ipsec static add filter filterlist=fi_deny_bitcoin srcaddr=any dstaddr=Me dstport=445 protocol=TCP
  12. netsh ipsec static add filteraction name=denyact action=block
  13. netsh ipsec static add rule name=deny_bitcoin policy=deny_bitcoin filterlist=fi_deny_bitcoin filteraction=denyact
  14. netsh ipsec static set policy name=deny_bitcoin assign=y
  15. cls
  16. echo 关闭端口成功,3秒后本窗口自动关闭
  17. ping 127.0.0.1 >nul
复制代码
我的环境也需要,下午编的,大家试试

TOP

支持LZ,本人也正需要此代码。

TOP

返回列表