📌 Tổng Quan
Trong môi trường doanh nghiệp hoặc cơ quan có yêu cầu bảo mật dữ liệu cao, việc giám sát và kiểm soát upload dữ liệu từ người dùng đầu cuối là rất quan trọng. Một giải pháp đơn giản nhưng mạnh mẽ, sử dụng mã nguồn mở hoàn toàn, là kết hợp giữa Squid (Proxy) và E2Guardian (Web Filter) để:
- Chặn upload file nhạy cảm như
.pdf
,.zip
,.dwg
, … - Chặn truy cập hoặc đồng bộ dữ liệu với các dịch vụ Cloud: Google Drive, Dropbox, OneDrive, GitHub…
- Có thể ghi log đầy đủ để truy vết hành vi.
🧱 Kiến Trúc Hoạt Động
[Client]
│
▼
┌────────────────┐
│ Squid │ ← HTTP Proxy + SSL Bump
└────────────────┘
│
▼
┌───────────────────┐
│ E2Guardian │ ← Lọc nội dung (file, URL, từ khóa)
└───────────────────┘
│
▼
Internet
- Squid đóng vai trò Intercepting Proxy: chặn và giải mã HTTPS (SSL Bump)
- E2Guardian nhận dữ liệu đã giải mã từ Squid để thực hiện phân tích nội dung chi tiết
⚙️ Cài Đặt & Cấu Hình Chi Tiết
🧩 Cài Squid và E2Guardian
apt update
apt install squid e2guardian -y
📄 Cấu hình squid.conf
✅ Mục tiêu:
- Bật SSL Bump
- Chuyển tiếp traffic đến E2Guardian
- Chặn domain nhạy cảm
- Ghi log JSON
📦 File: /etc/squid/squid.conf
http_port 3128 ssl-bump generate-host-certificates=on dynamic_cert_mem_cache_size=16MB \
cert=/etc/squid/ssl_cert/myCA.pem key=/etc/squid/ssl_cert/myCA.key
cache_peer 127.0.0.1 parent 8080 0 no-query default
never_direct allow all
acl step1 at_step SslBump1
acl step2 at_step SslBump2
acl step3 at_step SslBump3
ssl_bump peek step1
ssl_bump stare step2
ssl_bump bump step3
sslproxy_cert_error allow all
acl bad_sites url_regex -i sex tiktok dropbox onedrive github
http_access deny bad_sites
http_access allow all
logformat custom_json {"ts":"%tl","client":"%>a","code":"%>Hs","status":"%Ss","bytes":%<st,"method":"%rm","url":"%ru","hier":"%Sh/%<a","content_type":"%mt"}
access_log /var/log/squid/access.json custom_json
cache_mem 1024 MB
max_filedescriptors 65535
cache_dir ufs /var/spool/squid 1000 16 256
maximum_object_size 20 MB
dns_nameservers 8.8.8.8 8.8.4.4
pipeline_prefetch 5
refresh_pattern . 0 20% 4320
coredump_dir /var/spool/squid
📄 Cấu hình e2guardian.conf
✅ Mục tiêu:
- Lọc nội dung file và header
- Bật HTTPS filter
- Chặn domain cloud
- Chặn upload file
.pdf
,.zip
,.rar
,.dwg
,…
📦 File: /etc/e2guardian/e2guardian.conf
filterip = 127.0.0.1
filterports = 8080
enablessl = on
scancontents = on
cacertificatepath = '/etc/squid/ssl_cert/myCA.pem'
caprivatekeypath = '/etc/squid/ssl_cert/myCA.key'
certprivatekeypath = '/etc/squid/ssl_cert/myCA.key'
generatedcertpath = '/var/lib/e2guardian/generatedcerts'
contentregexplist = '/etc/e2guardian/lists/contentregexplist'
urllist = 'name=cloudblocklist,messageno=601,path=/etc/e2guardian/lists/cloudurllist'
logfile = '/var/log/e2guardian/e2guardian.log'
logfileformat = 6
httpworkers = 500
📄 Cấu hình lọc nội dung file
📦 /etc/e2guardian/lists/contentregexplist
.*\.pdf$>banned
.*\.zip$>banned
.*\.rar$>banned
.*\.dwg$>banned
Content-Disposition:.*\.pdf> banned
Content-Disposition:.*\.zip> banned
Content-Type:.*application/pdf> banned
Content-Type:.*application/zip> banned
Content-Type:.*application/x-rar-compressed> banned
📄 Cấu hình domain Cloud bị chặn
📦 /etc/e2guardian/lists/cloudurllist
.dropbox.com>
.onedrive.com>
.github.com>
drive.google.com>
api.dropboxapi.com>
api.onedrive.com>
api.github.com>
▶️ 6. Khởi động lại dịch vụ
squid -k parse && squid -k reconfigure
systemctl restart squid
systemctl restart e2guardian
📌 Ví Dụ Thực Tế
- Truy cập vào https://drive.google.com và thử upload
.zip
→ bị block - Truy cập
https://github.com
→ bị chặn ngay lập tức - Upload
.pdf
qua form HTML → bị từ chối
✅ Ưu Điểm
- ✅ Miễn phí & Mã nguồn mở
- ✅ Tùy biến cao, log chi tiết
- ✅ Dễ tích hợp với hạ tầng sẵn có
- ✅ Có thể mở rộng lọc nâng cao
❌ Nhược Điểm
- ❌ Không phát hiện dữ liệu bị ẩn trong file (no deep content inspection)
- ❌ Không chặn được upload từ ứng dụng riêng (VD: Zalo app, OneDrive app)
- ❌ Cần cài chứng chỉ CA thủ công nếu client là HTTPS strict
🔍 So Sánh Với Giải Pháp Khác
Tính năng | Squid + E2Guardian | FortiGate DLP | Zscaler Cloud DLP |
---|---|---|---|
Miễn phí | ✅ | ❌ | ❌ |
Phân tích nội dung nâng cao | ❌ | ✅ | ✅ |
Quản lý tập trung | ⚠️ (phải tự xây) | ✅ | ✅ |
Interface quản lý | ❌ (text file) | ✅ | ✅ |
💡 Lời Khuyên
- Hệ thống này rất phù hợp với SMB, trường học, trung tâm đào tạo muốn chặn đơn giản.
- Nếu cần quét sâu nội dung hoặc chặn Zalo/Telegram thì cần kết hợp thêm Firewall Layer 7 hoặc DLP chuyên dụng như FortiDLP, Symantec DLP…
- Có thể sử dụng thêm
iptables
để redirect toàn bộ traffic về Squid (chế độ transparent).
🏁 Kết Luận
Kết hợp Squid + E2Guardian là một giải pháp mã nguồn mở hiệu quả để:
- Chặn upload file nhạy cảm
- Chặn truy cập dịch vụ cloud lưu trữ
- Log hành vi duyệt web
- Tăng cường bảo mật dữ liệu nội bộ
Bạn có thể mở rộng giải pháp này với IDS, SIEM hoặc DLP nâng cao để xây dựng hệ thống bảo mật toàn diện hơn trong tương lai.