员工随手把图纸传上网?华为防火墙文件过滤按类型方向拦在出口
公司里有两类"顺手"事特别要命:一类是员工把设计图纸、客户名单随手传到网盘或者私人邮箱——机密就这么出了门;另一类是从网上随手下载个"破解版"工具——病毒跟着进了内网。事后追责来不及,事前喊话没人听,出口上把一道按文件类型管控的闸才是硬办法。华为防火墙的文件过滤功能干的就是这个:按文件类型(文档、代码、压缩包、可执行、音视频)加传输方向(上传、下载)组规则,命中就阻断,而且三个场景可以分三套配置文件各管各的——员工上网一套、员工传内网服务器一套、外网用户往服务器上传一套。官方文档有一套完整的命令行举例,从三个过滤配置文件到三条安全策略到引擎提交,本篇按这套示例把全套命令走一遍,配置脚本一并附上。
本文的组网需求、配置思路与命令步骤,整理自华为官方发布的典型配置案例,参数可直接参考使用。
组网需求
某公司在网络边界处部署了 Device 作为安全网关,公司希望在保证网络能够正常使用的同时实现以下需求:
- 为了防止公司机密文件的泄露,禁止员工上传常见文档文件、开发文件(C、CPP、JAVA)以及压缩文件到内网服务器和 Internet。
- 为了降低病毒进入公司内部的风险,禁止员工从 Internet 下载可执行文件以及 Internet 用户上传可执行文件到内网服务器。
- 为了保证员工的工作效率,禁止员工从 Internet 下载视频类文件。
本例中 interface1、interface2、interface3 分别代表 GE0/0/1、GE0/0/2、GE0/0/3。
翻译成白话:防火墙三接口三区域——内网用户在 trust(GE0/0/3)、内网服务器区在 dmz(GE0/0/2)、外网在 untrust(GE0/0/1)。三条管控诉求对应三套过滤口径:员工无论去外网还是去内网服务器,文档/代码/压缩包一律禁上传;可执行文件两头堵——员工不许从外网下载、外网用户也不许往内网服务器传;视频文件禁下载,上班时间别拿来刷剧。
配置思路
本例的配置分三步走:
- 配置接口 IP 地址和安全区域,完成网络基本参数配置。
- 新建文件过滤配置文件——本例一共三个:profile_file_user1 管员工上网、profile_file_user2 管员工传内网服务器、profile_file_internet 管外网用户上传。
- 配置安全策略,保证网络可达的同时引用文件过滤配置文件,实现文件过滤,并提交内容安全配置文件使其生效。
核心逻辑一句话:配置文件定"拦什么类型、拦哪个方向",安全策略定"哪股流量套哪套口径",上传下载两个方向分开写,员工和外部用户分而治之。
操作步骤
一、配置接口IP地址和安全区域,完成网络基本参数配置
<HUAWEI> system-view
[HUAWEI] sysname DeviceA
[DeviceA] interface ge 0/0/1
[DeviceA-GE0/0/1] ip address 1.1.1.1 24
[DeviceA-GE0/0/1] quit
[DeviceA] interface ge 0/0/2
[DeviceA-GE0/0/2] ip address 10.2.0.1 255.255.255.0
[DeviceA-GE0/0/2] quit
[DeviceA] interface ge 0/0/3
[DeviceA-GE0/0/3] ip address 10.3.0.1 255.255.255.0
[DeviceA-GE0/0/3] quit
[DeviceA] firewall zone untrust
[DeviceA-zone-untrust] add interface ge 0/0/1
[DeviceA-zone-untrust] quit
[DeviceA] firewall zone dmz
[DeviceA-zone-dmz] add interface ge 0/0/2
[DeviceA-zone-dmz] quit
[DeviceA] firewall zone trust
[DeviceA-zone-trust] add interface ge 0/0/3
[DeviceA-zone-trust] quit
GE0/0/1(1.1.1.1/24)朝外归 untrust,GE0/0/2(10.2.0.1/24)接服务器区归 dmz,GE0/0/3(10.3.0.1/24)接内网用户归 trust——后面三条安全策略的区域对就从这里取。
二、新建配置文件profile_file_user1
新建配置文件 profile_file_user1,禁止上传文档文件、开发文件和压缩文件,以及从 Internet 下载可执行文件和音视频文件:
[DeviceA] profile type file-block name profile_file_user1
[DeviceA-profile-file-block-profile_file_user1] rule name rule1
[DeviceA-profile-file-block-profile_file_user1-rule-rule1] application all
[DeviceA-profile-file-block-profile_file_user1-rule-rule1] undo file-type pre-defined all
Warning: Cancel all the file types. Continue? [Y/N]:y
[DeviceA-profile-file-block-profile_file_user1-rule-rule1] file-type pre-defined name DOC PPT XLS MSOFFICE DOCX PPTX XLSX PDF VSD MPP
[DeviceA-profile-file-block-profile_file_user1-rule-rule1] file-type pre-defined name ODS ODT ODP EML UOF RAR TAR ZIP GZIP CAB
[DeviceA-profile-file-block-profile_file_user1-rule-rule1] file-type pre-defined name BZ2 Z 7ZIP JAR C CPP JAVA VBS
[DeviceA-profile-file-block-profile_file_user1-rule-rule1] direction upload
[DeviceA-profile-file-block-profile_file_user1-rule-rule1] action block
[DeviceA-profile-file-block-profile_file_user1-rule-rule1] quit
[DeviceA-profile-file-block-profile_file_user1] rule name rule2
[DeviceA-profile-file-block-profile_file_user1-rule-rule2] application all
[DeviceA-profile-file-block-profile_file_user1-rule-rule2] undo file-type pre-defined all
Warning: Cancel all the file types. Continue? [Y/N]:y
[DeviceA-profile-file-block-profile_file_user1-rule-rule2] file-type pre-defined name EXE MSI RPM OCX A ELF DLL PE SYS MDI
[DeviceA-profile-file-block-profile_file_user1-rule-rule2] file-type pre-defined name MOV MPEG AVI RMVB ASF SWF MP3 MP4 MIDI
[DeviceA-profile-file-block-profile_file_user1-rule-rule2] direction download
[DeviceA-profile-file-block-profile_file_user1-rule-rule2] action block
[DeviceA-profile-file-block-profile_file_user1-rule-rule2] quit
[DeviceA-profile-file-block-profile_file_user1] quit
这套给"员工上网"用,两条规则分两个方向:rule1 管上传——Office 全家、PDF、Visio、Project 文档,ODS/ODT 等开源格式,RAR/ZIP/7Z 等压缩包,C/CPP/JAVA/JAR/VBS 等代码文件,全部 block;rule2 管下载——EXE/MSI/DLL 等可执行文件加 MOV/MP4/MP3 等音视频,一样 block。undo file-type pre-defined all 先把预置类型清空再按需点名,两条 warning 的 y 是交互确认,原样输入即可。
三、新建配置文件profile_file_user2
新建配置文件 profile_file_user2,禁止上传文档文件、开发文件和压缩文件:
[DeviceA] profile type file-block name profile_file_user2
[DeviceA-profile-file-block-profile_file_user2] rule name rule1
[DeviceA-profile-file-block-profile_file_user2-rule-rule1] application all
[DeviceA-profile-file-block-profile_file_user2-rule-rule1] undo file-type pre-defined all
Warning: Cancel all the file types. Continue? [Y/N]:y
[DeviceA-profile-file-block-profile_file_user2-rule-rule1] file-type pre-defined name DOC PPT XLS MSOFFICE DOCX PPTX XLSX PDF VSD MPP
[DeviceA-profile-file-block-profile_file_user2-rule-rule1] file-type pre-defined name ODS ODT ODP EML UOF RAR TAR ZIP GZIP CAB
[DeviceA-profile-file-block-profile_file_user2-rule-rule1] file-type pre-defined name BZ2 Z 7ZIP JAR C CPP JAVA VBS
[DeviceA-profile-file-block-profile_file_user2-rule-rule1] direction upload
[DeviceA-profile-file-block-profile_file_user2-rule-rule1] action block
[DeviceA-profile-file-block-profile_file_user2-rule-rule1] quit
[DeviceA-profile-file-block-profile_file_user2] quit
这套给"员工传内网服务器"用,只留一条上传方向的规则:文档、代码、压缩包禁传,跟 rule1 的类型清单一致——服务器区的管控重点是防机密落错地方,下载方向不管。
四、新建配置文件profile_file_internet
新建配置文件 profile_file_internet,禁止上传可执行文件:
[DeviceA] profile type file-block name profile_file_internet
[DeviceA-profile-file-block-profile_file_internet] rule name rule1
[DeviceA-profile-file-block-profile_file_internet-rule-rule1] application all
[DeviceA-profile-file-block-profile_file_user2-rule-rule1] undo file-type pre-defined all
Warning: Cancel all the file types. Continue? [Y/N]:y
[DeviceA-profile-file-block-profile_file_internet-rule-rule1] file-type pre-defined name EXE MSI RPM OCX A ELF DLL PE SYS
[DeviceA-profile-file-block-profile_file_internet-rule-rule1] direction upload
[DeviceA-profile-file-block-profile_file_internet-rule-rule1] action block
[DeviceA-profile-file-block-profile_file_internet-rule-rule1] quit
[DeviceA-profile-file-block-profile_file_internet] quit
这套给"外网用户访问内网服务器"用:只拦一个方向一个类型——上传可执行文件。对外发布的服务器就怕别人往里塞带毒的程序,EXE/MSI/RPM/DLL/ELF 一类全部挡在门外。(注:第四行命令的提示符仍显示为 profile_file_user2,官方举例中即是这样,原样输入即可。)
五、配置安全策略并引用文件过滤配置文件
配置 trust 到 untrust 的安全策略 policy_sec_user1,并引用配置文件 profile_file_user1,允许内网用户访问外网:
[DeviceA] security-policy
[DeviceA-policy-security] rule name policy_sec_user1
[DeviceA-policy-security-rule-policy_sec_user1] source-zone trust
[DeviceA-policy-security-rule-policy_sec_user1] destination-zone untrust
[DeviceA-policy-security-rule-policy_sec_user1] source-address 10.3.0.0 24
[DeviceA-policy-security-rule-policy_sec_user1] profile file-block profile_file_user1
[DeviceA-policy-security-rule-policy_sec_user1] action permit
[DeviceA-policy-security-rule-policy_sec_user1] quit
员工上网这股流量套 profile_file_user1:放行上网,但上传文档代码压缩包、下载可执行和视频都会被文件过滤拦下。
配置 trust 到 dmz 的安全策略 policy_sec_user2,并引用配置文件 profile_file_user2,允许内网用户访问服务器:
[DeviceA-policy-security] rule name policy_sec_user2
[DeviceA-policy-security-rule-policy_sec_user2] source-zone trust
[DeviceA-policy-security-rule-policy_sec_user2] destination-zone dmz
[DeviceA-policy-security-rule-policy_sec_user2] source-address 10.3.0.0 24
[DeviceA-policy-security-rule-policy_sec_user2] destination-address 10.2.0.5 24
[DeviceA-policy-security-rule-policy_sec_user2] profile file-block profile_file_user2
[DeviceA-policy-security-rule-policy_sec_user2] action permit
[DeviceA-policy-security-rule-policy_sec_user2] quit
员工访问内网服务器这股流量套 profile_file_user2,管住上传方向。这里目的地址写的是单台服务器 10.2.0.5,换环境按自己的服务器地址改。
配置 untrust 到 dmz 的安全策略 policy_sec_internet,并引用配置文件 profile_file_internet,允许外网用户访问内网服务器:
[DeviceA-policy-security] rule name policy_sec_internet
[DeviceA-policy-security-rule-policy_sec_internet] source-zone untrust
[DeviceA-policy-security-rule-policy_sec_internet] destination-zone dmz
[DeviceA-policy-security-rule-policy_sec_internet] destination-address 10.2.0.5 24
[DeviceA-policy-security-rule-policy_sec_internet] profile file-block profile_file_internet
[DeviceA-policy-security-rule-policy_sec_internet] action permit
[DeviceA-policy-security-rule-policy_sec_internet] quit
外网用户进服务器这股流量套 profile_file_internet:服务照常对外提供,但可执行文件传不进来。
六、提交内容安全配置文件
[DeviceA] engine configuration commit
Info: The operation may last several minutes, please wait. Try "display engine information" for detail.
[DeviceA]
Info: FB submitted configurations successfully.
Info: Engine configuration is compiled successfully.
文件过滤配置改完必须执行 engine configuration commit 提交给内容安全引擎才生效,官方回显提示这一步可能持续几分钟,属正常现象,等编译成功的 Info 出来再收工。
检查配置结果
配置生效后按官方给出的口径验证:
- 公司员工在内网的 PC 上能够正常访问 Internet 和内网服务器,但是上传文档文件、压缩文件、代码文件失败,从 Internet 下载可执行文件和视频文件失败。
- 在 Internet 的 PC 上能够正常访问内网服务器,但是不能上传可执行文件到内网服务器。
也就是"该通的通、该拦的拦"两头都要试:找一台内网 PC 分别传一个 DOC、下载一个 EXE 验证拦截,再正常浏览网页确认业务无感。
配置脚本
DeviceA 的配置脚本(脚本中 file-type 名单为命令回显口径,与操作步骤中的清单表现不同属正常现象):
#
sysname DeviceA
#
profile type file-block name profile_file_user1
rule name rule1
undo file-type pre-defined name A ACCDB APK ASF AVI BAT BMP_UPLOAD CAP CAT CHM CKPT CMD CRT DLL DOC_ENC DSM DWG EDIF ELF EXE FLV FON GBS GGUF GIF_UPLOAD H5 HTML ICO ILK INF ISO JAR_ENC JPEG_UPLOAD JS LNK LZH MDB MDI MIDI MKV MOV MP3 MP4 MPEG MSI NSF OBJ OCX ODB ODG ONNX OPC_ENC PCAP PDB PDF_ENC PE PGP PIF PKL PL PNG_UPLOAD PPT_ENC PSD PTH RAR_ENC REG RES RMVB RPM RTF SAFETENSORS SEGD SEGY SH SLN SWF SYS TDB TIF_UPLOAD TORRENT TTF VCPROJ VDS WMF_UPLOAD WSF XLS_ENC ZIP_ENC
action block
rule name rule2
direction download
undo file-type pre-defined name 7ZIP ACCDB APK BAT BMP_UPLOAD BZ2 C CAB CAP CAT CHM CKPT CMD CPP CRT DOC DOCX DOC_ENC DSM DWG EDIF EML FLV FON GBS GGUF GIF_UPLOAD GZIP H5 HTML ICO ILK INF ISO JAR JAR_ENC JAVA JPEG_UPLOAD JS LNK LZH MDB MIDI MKV MPP MSOFFICE NSF OBJ ODB ODG ODP ODS ODT ONNX OPC_ENC PCAP PDB PDF PDF_ENC PGP PIF PKL PL PNG_UPLOAD PPT PPTX PPT_ENC PSD PTH RAR RAR_ENC REG RES RTF SAFETENSORS SEGD SEGY SH SLN TAR TDB TIF_UPLOAD TORRENT TTF UOF VBS VCPROJ VDS VSD WMF_UPLOAD WSF XLS XLSX XLS_ENC Z ZIP ZIP_ENC
action block
profile type file-block name profile_file_user2
rule name rule1
undo file-type pre-defined name A ACCDB APK ASF AVI BAT BMP_UPLOAD CAP CAT CHM CKPT CMD CRT DLL DOC_ENC DSM DWG EDIF ELF EXE FLV FON GBS GGUF GIF_UPLOAD H5 HTML ICO ILK INF ISO JAR_ENC JPEG_UPLOAD JS LNK LZH MDB MDI MIDI MKV MOV MP3 MP4 MPEG MSI NSF OBJ OCX ODB ODG ONNX OPC_ENC PCAP PDB PDF_ENC PE PGP PIF PKL PL PNG_UPLOAD PPT_ENC PSD PTH RAR_ENC REG RES RMVB RPM RTF SAFETENSORS SEGD SEGY SH SLN SWF SYS TDB TIF_UPLOAD TORRENT TTF VCPROJ VDS WMF_UPLOAD WSF XLS_ENC ZIP_ENC
action block
profile type file-block name profile_file_internet
rule name rule1
undo file-type pre-defined name 7ZIP ACCDB APK ASF AVI BAT BMP_UPLOAD BZ2 C CAB CAP CAT CHM CKPT CMD CPP CRT DOC DOCX DOC_ENC DSM DWG EDIF EML FLV FON GBS GGUF GIF_UPLOAD GZIP H5 HTML ICO ILK INF ISO JAR JAR_ENC JAVA JPEG_UPLOAD JS LNK LZH MDB MDI MIDI MKV MOV MP3 MP4 MPEG MPP MSOFFICE NSF OBJ ODB ODG ODP ODS ODT ONNX OPC_ENC PCAP PDB PDF PDF_ENC PGP PIF PKL PL PNG_UPLOAD PPT PPTX PPT_ENC PSD PTH RAR RAR_ENC REG RES RMVB RTF SAFETENSORS SEGD SEGY SH SLN SWF TAR TDB TIF_UPLOAD TORRENT TTF UOF VBS VCPROJ VDS VSD WMF_UPLOAD WSF XLS XLSX XLS_ENC Z ZIP ZIP_ENC
action block
#
interface GE0/0/1
ip address 1.1.1.1 255.255.255.0
#
interface GE0/0/2
ip address 10.2.0.1 255.255.255.0
#
interface GE0/0/3
ip address 10.3.0.1 255.255.255.0
#
firewall zone trust
set priority 85
add interface GE0/0/3
#
firewall zone dmz
set priority 50
add interface GE0/0/2
#
firewall zone untrust
set priority 5
add interface GE0/0/1
#
security-policy
rule name policy_sec_user1
source-zone trust
destination-zone untrust
source-address 10.3.0.0 mask 255.255.255.0
profile file-block profile_file_user1
action permit
rule name policy_sec_user2
source-zone trust
destination-zone dmz
source-address 10.3.0.0 mask 255.255.255.0
destination-address 10.2.0.0 mask 255.255.255.0
profile file-block profile_file_user2
action permit
rule name policy_sec_internet
source-zone untrust
destination-zone dmz
destination-address 10.2.0.0 mask 255.255.255.0
profile file-block profile_file_internet
action permit
#
return
注意事项
- 本举例出自华为 USG 系列防火墙的官方典型配置案例,落到具体设备前,请核对你的设备型号与软件版本对文件过滤功能的支持情况。
- 配置后必须提交:文件过滤属于内容安全引擎功能,改完配置要执行 engine configuration commit 才生效,提交耗时几分钟属官方口径的正常现象。
- 方向概念要站稳:direction 指的是文件传输方向(upload/download),同一套配置文件里上传下载分规则写,员工侧和外部用户侧分配置文件写,别把三套口径搅在一起。
- 文件类型按需取舍:本例的类型清单是官方示例口径,真实环境如有正当业务(如软件分发要下载 EXE、设计院要传 DWG),在规则里把对应类型摘出去或单独拆一条放行策略,别整段放开。
- 一刀切容易被投诉顶回来:上班禁视频、全量禁压缩包这类口径先跟业务部门打招呼再上,策略生效后盯几天文件过滤日志,误拦多的场景及时调清单。
- 接口地址与服务器地址(本例 10.2.0.5、10.2.0.0/24)均为官方示例值,换环境替换成自己的地址规划。
哪些文件类型该禁、禁到哪个方向,建议请诚鑫致达科技先到各部门把日常传文件的真实习惯摸一遍再定清单——一刀切禁到底,往往撑不过一周就会被业务投诉顶回来。各厂商设备的命令与默认参数存在差异,操作前请核对你的设备型号与软件版本。
源:华为USG防火墙官方文档