开源入侵防御系统CrowdSec---web防护

发布于:2025-07-13 ⋅ 阅读:(18) ⋅ 点赞:(0)

上一次讲了tcp防护-------开源入侵防御系统——CrowdSec-CSDN博客

对于web防护也是很强的---这里以NGINX为例

1、安装openresty

#####添加 OpenResty YUM 源
rpm --import https://openresty.org/package/pubkey.gpg

#######编辑 /etc/yum.repos.d/openresty.repo 
[openresty]
name=OpenResty
baseurl=https://openresty.org/package/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://openresty.org/package/pubkey.gpg
module_hotfixes=true


####刷新 YUM 缓存并尝试安装
yum clean all
yum makecache
yum install openresty

2、安装防护插件

yum install -y crowdsec-openresty-bouncer
collections install crowdsecurity/nginx
cscli parsers install crowdsecurity/nginx-logs
cscli collections install crowdsecurity/base-http-scenarios

#####查看
cscli parsers list
cscli scenarios list
cscli collections list

3、配置

####加入NGINX日志
cat /etc/crowdsec/acquis.yaml 
#Generated acquisition file - wizard.sh (service: sshd) / files : /var/log/secure
filenames:
  - /var/log/secure
labels:
  type: syslog
---
#Generated acquisition file - wizard.sh (service: linux) / files : /var/log/messages
filenames:
  - /var/log/messages
labels:
  type: syslog
---
#nginx
filenames: 
  - /usr/local/openresty/nginx/logs/access.log 
labels:
  type: nginx
---




#####NGINX配置,开启这些配置
cat /usr/local/openresty/nginx/conf/nginx.conf


    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log   logs/access.log  main;

    include  /usr/local/openresty/nginx/conf/conf.d/crowdsec_openresty.conf;
 



####重启服务
systemctl restart crowdsec
/usr/local/openresty/nginx/sbin/nginx -s reload

4、测试

在开一台机器测试:

curl -I http://your.host/../../etc/passwd
curl -I http://your.host/../../../etc/passwd
curl -I http://your.host/../../../../etc/passwd
curl -I http://your.host/../../../../../etc/passwd
curl -I http://your.host/../../../../../../etc/passwd
 

####触发web防护


cscli decisions list
╭───────┬──────────┬───────────────────┬───────────────────────────────────────────┬────────┬─────────┬────┬────────┬────────────┬──────────╮
│   ID  │  Source  │    Scope:Value    │                   Reason                  │ Action │ Country │ AS │ Events │ expiration │ Alert ID │
├───────┼──────────┼───────────────────┼───────────────────────────────────────────┼────────┼─────────┼────┼────────┼────────────┼──────────┤
│ 75007 │ crowdsec │ Ip:192.168.00.000 │ crowdsecurity/http-path-traversal-probing │ ban    │         │    │ 4      │ 3h59m44s   │ 12       │
╰───────┴──────────┴───────────────────┴───────────────────────────────────────────┴────────┴─────────┴────┴────────┴────────────┴──────────╯


root@test:/etc/crowdsec# cscli alerts list
╭────┬───────────────────┬───────────────────────────────────────────┬─────────┬────┬───────────┬─────────────────────────────────────────╮
│ ID │       value       │                   reason                  │ country │ as │ decisions │                created_at               │
├────┼───────────────────┼───────────────────────────────────────────┼─────────┼────┼───────────┼─────────────────────────────────────────┤
│ 12 │ Ip:192.168.00.000 │ crowdsecurity/http-path-traversal-probing │         │    │ ban:1     │ 2025-07-10 09:31:37.945188867 +0000 UTC │
╰────┴───────────────────┴───────────────────────────────────────────┴─────────┴────┴───────────┴─────────────────────────────────────────╯


root@test:/etc/crowdsec# cscli metrics
╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Acquisition Metrics                                                                                                                            │
├─────────────────────────────────────────────────┬────────────┬──────────────┬────────────────┬────────────────────────┬───────────────────┤
│ Source                                          │ Lines read │ Lines parsed │ Lines unparsed │ Lines poured to bucket │ Lines whitelisted │
├─────────────────────────────────────────────────┼────────────┼──────────────┼────────────────┼────────────────────────┼───────────────────┤
│ file:/usr/local/openresty/nginx/logs/access.log │ 5          │ 5            │ -              │ 11                     │ -                 │
│ file:/var/log/messages                          │ 3          │ -            │ 3              │ -                      │ -                 │
╰─────────────────────────────────────────────────┴────────────┴──────────────┴────────────────┴────────────────────────┴───────────────────╯
╭────────────────────────────────────────────────────╮
│ Local API Alerts                                   │
├───────────────────────────────────────────┬───────┤
│ Reason                                    │ Count │
├───────────────────────────────────────────┼───────┤
│ crowdsecurity/http-path-traversal-probing │ 1     │
╰───────────────────────────────────────────┴───────╯
╭─────────────────────╮
│ Bouncer Metrics (cr │
│ owdsec-openresty-bo │
│ uncer-1752135046) s │
│ ince 2025-07-10 08: │
│ 53:49 +0000 UTC     │
├────────┬───────────┤
│ Origin │ processed │
│        │  request  │
├────────┼───────────┤
│  Total │       210 │
╰────────┴───────────╯
╭────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Bouncer Metrics (cs-firewall-bouncer-1752116174) since 2025-07-10 03:11:20 +0000 UTC           │
├────────────────────────────┬──────────────────┬───────────────────┬───────────────────────┤
│ Origin                     │ active_decisions │       dropped      │        processed       │
│                            │        IPs       │  bytes  │ packets │   bytes   │  packets  │
├────────────────────────────┼──────────────────┼─────────┼─────────┼───────────┼───────────┤
│ CAPI (community blocklist) │                0 │       0 │       0 │         - │         - │
│ crowdsec (security engine) │                0 │   2.68k │      29 │         - │         - │
├────────────────────────────┼──────────────────┼─────────┼─────────┼───────────┼───────────┤
│                      Total │                0 │   2.68k │      29 │   162.84M │   577.15k │
╰────────────────────────────┴──────────────────┴─────────┴─────────┴───────────┴───────────╯
╭──────────────────────────────────────────────────────────────────────────╮
│ Local API Decisions                                                      │
├───────────────────────────────────────────┬──────────┬────────┬───────┤
│ Reason                                    │ Origin   │ Action │ Count │
├───────────────────────────────────────────┼──────────┼────────┼───────┤
│ ssh:bruteforce                            │ CAPI     │ ban    │ 15002 │
│ crowdsecurity/http-path-traversal-probing │ crowdsec │ ban    │ 1     │
╰───────────────────────────────────────────┴──────────┴────────┴───────╯
╭────────────────────────────────────────╮
│ Local API Metrics                      │
├──────────────────────┬────────┬──────┤
│ Route                │ Method │ Hits │
├──────────────────────┼────────┼──────┤
│ /v1/alerts           │ GET    │ 2    │
│ /v1/alerts           │ POST   │ 1    │
│ /v1/decisions/stream │ GET    │ 13   │
│ /v1/heartbeat        │ GET    │ 2    │
│ /v1/usage-metrics    │ POST   │ 1    │
│ /v1/watchers/login   │ POST   │ 3    │
╰──────────────────────┴────────┴──────╯
╭──────────────────────────────────────────────────────────────────────────╮
│ Local API Bouncers Metrics                                               │
├────────────────────────────────┬──────────────────────┬────────┬──────┤
│ Bouncer                        │ Route                │ Method │ Hits │
├────────────────────────────────┼──────────────────────┼────────┼──────┤
│ cs-firewall-bouncer-1752116174 │ /v1/decisions/stream │ GET    │ 13   │
╰────────────────────────────────┴──────────────────────┴────────┴──────╯
╭─────────────────────────────────────────────────────────────────────────────────────╮
│ Local API Machines Metrics                                                          │
├──────────────────────────────────────────────────┬───────────────┬────────┬──────┤
│ Machine                                          │ Route         │ Method │ Hits │
├──────────────────────────────────────────────────┼───────────────┼────────┼──────┤
│ dd2bb318ae379c408892924592b37d97AJnzSsojiaCqXNKQ │ /v1/alerts    │ GET    │ 2    │
│ dd2bb318ae379c408892924592b37d97AJnzSsojiaCqXNKQ │ /v1/alerts    │ POST   │ 1    │
│ dd2bb318ae379c408892924592b37d97AJnzSsojiaCqXNKQ │ /v1/heartbeat │ GET    │ 2    │
╰──────────────────────────────────────────────────┴───────────────┴────────┴──────╯
╭───────────────────────────────────────────────────────────────╮
│ Parser Metrics                                                │
├─────────────────────────────────┬──────┬────────┬──────────┤
│ Parsers                         │ Hits │ Parsed │ Unparsed │
├─────────────────────────────────┼──────┼────────┼──────────┤
│ child-crowdsecurity/http-logs   │ 15   │ 10     │ 5        │
│ child-crowdsecurity/nginx-logs  │ 5    │ 5      │ -        │
│ child-crowdsecurity/syslog-logs │ 3    │ 3      │ -        │
│ crowdsecurity/http-logs         │ 5    │ 5      │ -        │
│ crowdsecurity/nginx-logs        │ 5    │ 5      │ -        │
│ crowdsecurity/non-syslog        │ 5    │ 5      │ -        │
│ crowdsecurity/syslog-logs       │ 3    │ 3      │ -        │
│ crowdsecurity/whitelists        │ 5    │ 5      │ -        │
╰─────────────────────────────────┴──────┴────────┴──────────╯
╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Scenario Metrics                                                                                             │
├───────────────────────────────────────────┬───────────────┬───────────┬──────────────┬────────┬─────────┤
│ Scenario                                  │ Current Count │ Overflows │ Instantiated │ Poured │ Expired │
├───────────────────────────────────────────┼───────────────┼───────────┼──────────────┼────────┼─────────┤
│ crowdsecurity/http-crawl-non_statics      │ -             │ -         │ 1            │ 1      │ 1       │
│ crowdsecurity/http-path-traversal-probing │ -             │ 1         │ 2            │ 5      │ 1       │
│ crowdsecurity/http-probing                │ 1             │ -         │ 1            │ 5      │ -       │
╰───────────────────────────────────────────┴───────────────┴───────────┴──────────────┴────────┴─────────╯
╭────────────────────────────────────────────────────────────────────────────────╮
│ Whitelist Metrics                                                              │
├──────────────────────────┬─────────────────────────────┬──────┬─────────────┤
│ Whitelist                │ Reason                      │ Hits │ Whitelisted │
├──────────────────────────┼─────────────────────────────┼──────┼─────────────┤
│ crowdsecurity/whitelists │ private ipv4/ipv6 ip/ranges │ 5    │ -           │
╰──────────────────────────┴─────────────────────────────┴──────┴─────────────╯


网站公告

今日签到

点亮在社区的每一天
去签到