HTTP蜜罐是一种安全防御技术,通过在服务器上部署看似真实但实际为陷阱的服务,诱捕恶意攻击者或自动化扫描工具。当攻击者尝试利用已知漏洞时,蜜罐会记录攻击行为并收集攻击者信息。
# 蜜罐虚拟主机配置
server {
listen 80;
server_name honeypot.example.com;
# 记录完整请求信息
access_log /var/log/nginx/honeypot.access.log full;
# 返回看似正常的响应
location / {
return 200 "Welcome to our system!";
}
# 针对常见漏洞路径设置陷阱
location ~* (wp-admin|phpmyadmin|\.git|\.env) {
# 记录攻击尝试
access_log /var/log/nginx/honeypot_attack.log;
# 延迟响应增加攻击者停留时间
proxy_read_timeout 300s;
proxy_send_timeout 300s;
# 返回看似成功的响应但实际是蜜罐
return 200 "Login successful!";
}
}
location /admin {
# 伪装SQL注入漏洞
if ($args ~* "union.*select") {
access_log /var/log/nginx/sql_injection.log;
return 200 "Database query executed successfully!";
}
# 伪装XSS漏洞
if ($args ~* "<script>") {
access_log /var/log/nginx/xss_attempt.log;
return 200 "XSS payload received!";
}
}
location /vulnerable_endpoint {
# 故意延迟响应以延长攻击者会话
proxy_read_timeout 600s;
proxy_send_timeout 600s;
# 使用Lua脚本实现更复杂的交互
content_by_lua_block {
ngx.sleep(10) -- 延迟10秒响应
ngx.say("Processing your request...")
}
}
location /fingerprint {
# 记录详细客户端信息
set $fingerprint "$remote_addr - $http_user_agent - $time_local";
# 使用Lua收集更多信息
content_by_lua_block {
local headers = ngx.req.get_headers()
local fingerprint = "IP: " .. ngx.var.remote_addr ..
"\nUA: " .. ngx.var.http_user_agent ..
"\nHeaders: " .. require("cjson").encode(headers)
ngx.log(ngx.INFO, "Collected fingerprint: ", fingerprint)
ngx.say("Thank you for your visit!")
}
}
通过合理配置Nginx,可以构建一个有效的HTTP蜜罐系统,帮助识别和收集针对Web应用的攻击行为,为安全团队提供宝贵的威胁情报。