SSH parser: incomplete handling of IPv4-mapped IPv6 addresses and SSH authentication log formats

Đang mở
#2,015 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
48/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
backend, security

Hướng nghiên cứu

Start by reviewing the SSH parser expressions named in the issue: SSHD_AUTH_FAIL, SSHD_INVALID_USER, SSHD_INVALID_USER_ALT, SSHD_AUTH_TIMEOUT, and SSHD_BAD_VERSION. Compare the supplied reproduction messages and proposed patterns, then check how source addresses are extracted and whether normalization belongs in this parser or another stage. Done means the relevant valid SSH messages parse complete addresses, invalid inputs remain rejected, and regression coverage confirms the behavior.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Summary

During an investigation of SSH log parsing on a Proxmox VE host, we identified several inconsistencies in the CrowdSec SSH parser.

The issues primarily concern:

Recognition of IPv4-mapped IPv6 addresses, including uppercase ::FFFF: notation.

Missing end-of-address boundaries in selected parser expressions.

Parsing of SSH messages reporting invalid protocol version identification.

These issues can cause valid SSH security events to be missed or incorrectly parsed, potentially affecting brute-force detection.

We developed a local parser correction (V1.2) and evaluated it against regression and extended coverage datasets.

Environment

CrowdSec security engine running on Proxmox VE

OpenSSH server (sshd)

Central CrowdSec LAPI hosted on OPNsense

Distributed CrowdSec firewall bouncers

SSH parser: crowdsecurity/sshd-logs

Local parser correction: V1.2

  1. IPv4-mapped IPv6 addresses

Problem

The original parser defines the following address pattern:

IP_WORKAROUND: (?:%{IPV6}|%{IPv4_WORKAROUND})

This does not reliably handle every IPv4-mapped IPv6 representation encountered in our test cases.

For example:

::FFFF:198.51.100.151

Proposed correction

IP_WORKAROUND: (?:(?i:::ffff:)%{IPv4_WORKAROUND}|%{IPV6}|%{IPv4_WORKAROUND})

The additional alternative explicitly recognizes IPv4-mapped IPv6 addresses, including case variations.

Example log entry:

2026-11-16T20:37:38+01:00 testhost sshd[50033]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=::FFFF:198.51.100.151

The address should be recognized completely rather than partially matched or rejected.

For detection purposes, equivalent IPv4 and IPv4-mapped IPv6 representations should also be normalized consistently.

Note: Address extraction and address normalization are separate concerns. Our functional verification used both the corrected SSH parser and a local normalization stage. The attached parser patch addresses extraction; it is not, by itself, a complete normalization implementation.

  1. Missing address boundaries

Problem

Several existing SSH parser expressions do not explicitly require an appropriate boundary after a captured source address.

Depending on the surrounding input, this can permit partial matches or otherwise incorrect extraction.

Proposed correction

We added:

(?:[[:space:]]|$)

to selected expressions.

The affected patterns include:

SSHD_AUTH_FAIL

SSHD_INVALID_USER

SSHD_INVALID_USER_ALT

SSHD_AUTH_TIMEOUT

This requires the captured address to be followed by whitespace or the end of the message.

  1. Invalid SSH protocol version messages

Problem

We identified a parsing issue involving messages such as:

Bad protocol version identification 'TEST-PROTOCOL' from 198.51.100.151

and:

Bad protocol version identification 'TEST-PROTOCOL' from ::FFFF:198.51.100.151

Proposed correction

Our local candidate introduces the following expression:

SSHD_BAD_VERSION_LOCAL: "Bad protocol version identification '%{GREEDYDATA}' from %{IP_WORKAROUND:sshd_client_ip}(?:[[:space:]]|$)"

The corresponding grok node uses SSHD_BAD_VERSION_LOCAL instead of SSHD_BAD_VERSION.

This allows the tested message variants to be parsed using the corrected address expression.

We recognize that the maintainers may prefer to modify the existing shared pattern rather than introduce a local replacement.

  1. Regression testing

We compared the original parser against the locally corrected V1.2 candidate.

Test suite

Original parser

Corrected V1.2

Regression tests

125/158

158/158

Extended coverage

770/900

900/900

The extended test suite covered 18 groups.

Results for the corrected candidate:

540/540 expected valid events accepted.

360/360 expected invalid events rejected.

No failures in the recorded regression dataset.

These results describe our local test corpus, not an exhaustive validation of every SSH log format supported by CrowdSec.

  1. Functional detection test

We also performed an isolated functional test using six SSH authentication failures.

The test alternated between the following representations of the same source:

192.0.2.239
::ffff:192.0.2.239

With the corrected parser and local address normalization, CrowdSec associated the events with one source and generated a single crowdsecurity/ssh-bf alert.

The test was conducted in an isolated environment without modifying production firewall decisions.

  1. Expected behavior

We expect the SSH parsing pipeline to:

Recognize valid IPv4, IPv6 and IPv4-mapped IPv6 source addresses completely.

Avoid partial address matches.

Recognize supported SSH authentication and protocol-error messages.

Normalize equivalent source addresses consistently before detection aggregation.

Continue rejecting invalid input.

  1. Proposed fix and supporting evidence

We have prepared a sanitized review package containing:

The original SSH parser.

The locally corrected V1.2 parser.

A unified diff.

Synthetic reproduction examples.

A summary of the regression and functional test results.

The package excludes credentials, private infrastructure details, full system logs and firewall snapshots.

The patch is offered as a starting point for review rather than a claim that the proposed implementation is the only appropriate upstream solution.

We would appreciate feedback on whether these changes should be implemented in the SSH parser itself, shared grok patterns, or the address-normalization stage.

  1. Related issues

We identified several potentially related reports:

crowdsecurity/hub#1458 — SSH parser missing pattern.

crowdsecurity/hub#1880 — Missing OpenSSH patterns.

crowdsecurity/hub#1952 — Duplicate SSH events.

crowdsecurity/crowdsec#938 — IP grok pattern.

Our report focuses specifically on IPv4-mappe

crowdsec-github-review.zip

d IPv6 handling, address boundaries and the tested SSH protocol-error formats.

  1. Disclosure

This investigation was conducted collaboratively by a homelab administrator and an AI assistant.

The AI assistant supported the analysis, test development, interpretation of results and documentation.

The reported test results originate from actual executions in the test environment.

We are happy to provide further sanitized reproduction cases or adapt the patch to the project's contribution guidelines.

Thank you for maintaining CrowdSec and for considering this report.

Ngôn ngữ chính
Python
Star
257
Fork
235
Merge trung bình
2 ngày 10 giờ
Pull request đã merge (30 ngày)
26

Chuẩn bị môi trường

  • Không có Dockerfile hay tệp Docker Compose
  • Có mẫu pull request
  • Không có hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của crowdsecurity/hub

Tất cả issue của crowdsecurity/hub

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.