近两年来,勒索病毒不断肆虐全球网络,通过漏洞发起的攻击占攻击总数的87.7%,135 137 138 139 445端口给我们带来便利的同时,同样也给了黑客可乘之机 , 关闭这些危险端口意味着黑客想攻破你的电脑,难度高了很多 。
【cmd关闭445端口命令 如何关闭139和445端口策略 - 秒懂生活 www.miaodongshenghuo.com】
上个月广州移动的安全检查行动中,有一项就是要给移动员工的电脑关闭这个危险端口,一幢办公楼里面约有四五千名员工,人手1台电脑 , 有些人甚至2台,由于没有使用域环境,手动去给每台电脑关闭这些端口 , 工作量不言而喻 。关闭这些端口步骤做成批处理文件 , 群发给移动员工在自己电脑上一键运行的方式 , 显得非常有必要 。
端口简介
- TCP端口135
- UDP端口137、138
138端口的主要作用就是提供NetBIOS环境下的计算机名浏览功能 。
- TCP端口139、445
关闭危险端口后对电脑有什么影响?
关闭135 137 138 139 445端口及对应服务后,依赖这些端口和服务的应用或服务都会受到影响,引起的故障现象多种多样 , 这里不做描述,主要说明以下2种:- 影响文件共享服务 。
建议改用更为安全的ftp共享作为文件共享的代替方案 。
- 影响打印机共享服务 。
如果你的电脑是通过老式的COM、现在流行的USB数据线直接连接到打印机,或者是通过打印机的ip直接连接,那你的电脑将不会受到影响,打印机服务依然可以正常使用 。
关闭方法
- 方式:windows批处理脚本
- 运行环境:win7系统、win10系统
- 步骤演示(以win7系统为例,演示图片请放大查看?。?/li>
- 查询135 137 138 139 445端口的状态
在命令行窗口输入netstat –an 并回车,即可看到所有开启的端口及对应的协议、外部地址和状态 。
- 创建并运行批处理文件
复制下面的代码粘贴到记事本中,点击“文件” >> 点击“另存为”
@echo offcolor 0A echo.echo 》》获取管理员权限...%1 mshta vbscript:CreateObject("Shell.Application").ShellExecute("cmd.exe","/c %~s0 ::","","runas",1)(window.close)&&exit@echo off color 0A title 一键屏蔽危险端口和服务echo.echo 》》开启Windows防火墙服务echo.net start MpsSvcecho 》》设置Windows防火墙为自启动echo.sc config MpsSvc start= autoecho.echo 》》启用防火墙echo.netsh advfirewall set allprofiles state onecho ------------------echo -------------------------------------------------echo.echo 》》正在屏蔽135端口 请稍候… netsh advfirewall firewall delete rule name = "Disable port 135 - TCP"netsh advfirewall firewall add rule name = "Disable port 135 - TCP" dir = in action = block protocol = TCP localport = 135 netsh advfirewall firewall delete rule name = "Disable port 135 - UDP"netsh advfirewall firewall add rule name = "Disable port 135 - UDP" dir = in action = block protocol = UDP localport = 135:修改注册表reg add "hklm\SOFTWARE\Microsoft\Ole" /v "EnableDCOM" /t reg_sz /d "N" /freg add "hklm\SOFTWARE\Microsoft\Rpc" /v "DCOM Protocols" /t reg_multi_sz /d "" /freg add "hklm\SOFTWARE\Microsoft\Rpc\internet" /t reg_sz /fecho.echo ------------------echo -------------------------------------------------echo.echo 》》正在屏蔽137端口 请稍候… echo.netsh advfirewall firewall delete rule name = "Disable port 137 - TCP"netsh advfirewall firewall add rule name = "Disable port 137 - TCP" dir = in action = block protocol = TCP localport = 137netsh advfirewall firewall delete rule name = "Disable port 137 - UDP"netsh advfirewall firewall add rule name = "Disable port 137 - UDP" dir = in action = block protocol = UDP localport = 137echo ------------------echo -------------------------------------------------echo.echo 》》正在屏蔽138端口 请稍候… netsh advfirewall firewall delete rule name = "Disable port 138 - TCP"netsh advfirewall firewall add rule name = "Disable port 138 - TCP" dir = in action = block protocol = TCP localport = 138netsh advfirewall firewall delete rule name = "Disable port 138 - UDP"netsh advfirewall firewall add rule name = "Disable port 138 - UDP" dir = in action = block protocol = UDP localport = 138echo ------------------echo -------------------------------------------------echo.echo 》》正在屏蔽139端口 请稍候… netsh advfirewall firewall delete rule name = "Disable port 139 - TCP"netsh advfirewall firewall add rule name = "Disable port 139 - TCP" dir = in action = block protocol = TCP localport = 139netsh advfirewall firewall delete rule name = "Disable port 139 - UDP"netsh advfirewall firewall add rule name = "Disable port 139 - UDP" dir = in action = block protocol = UDP localport = 139echo.echo 》》关闭TCP/IP NetBIOS Helper(lmhosts)共享服务echo.sc stop lmhostssc config lmhosts start= disabledecho.echo ------------------echo -------------------------------------------------echo.echo 》》正在关闭445端口 请稍候… netsh advfirewall firewall delete rule name = "Disable port 445 - TCP"netsh advfirewall firewall add rule name = "Disable port 445 - TCP" dir = in action = block protocol = TCP localport = 445netsh advfirewall firewall delete rule name = "Disable port 445 - UDP"netsh advfirewall firewall add rule name = "Disable port 445 - UDP" dir = in action = block protocol = UDP localport = 445echo.echo 》》关闭Server(LanmanServer)服务echo.sc stop LanmanServersc config LanmanServer start= disabledecho.echo 》》关闭NetBT服务echo.sc stop NetBTsc config NetBT start= disabled:修改注册表reg add "hklm\System\CurrentControlSet\Services\NetBT\Parameters" /v "SMBDeviceEnabled" /t reg_dword /d "0" /fecho.echo ------------------echo -------------------------------------------------echo.echo 》》关闭Workstation(LanmanWorkstation)服务echo.sc stop LanmanWorkstationsc config LanmanWorkstation start= disabledecho.echo ------------------echo -------------------------------------------------echo.echo 》》关闭Distributed Transaction Coordinator(MSDTC)共享服务echo.sc stop MSDTCsc config MSDTC start= disabledecho.echo ------------------echo -------------------------------------------------echo.echo 》》危险端口已经关闭,请重新启动电脑后用netstat -an命令查看本地端口echo.echo 》》请按任意键退出!echo.pause>nul
输入文件名“关闭135_137_138_139_445危险端口.bat” >>保存类型选择“所有文件”>>编码选择“ANSI” >> 点击“保存”双击运行刚刚另存为的bat文件
运行完成后的状态如下图所示
- 手动重启电脑
- 再次查询135 137 138 139 445端口的状态
在命令行窗口输入netstat –an,回车 。
可以看到135 137 138 139 445端口已经关闭 。