
Ansible role and Python script that detect OpenSSH regreSSHion (CVE-2024-6387) exposure, upgrade openssh-server, and apply the LoginGraceTime 0 workaround with backups and validation.
This Ansible role deploys a Python script that detects whether a host's OpenSSH server is vulnerable to regreSSHion (CVE-2024-6387), the signal-handler race in sshd disclosed by Qualys on 2024-07-01, and mitigates it where a fixed package is not yet installed.
The role upgrades openssh-server first. Only if the host is still vulnerable afterwards does it apply the vendor-documented workaround, LoginGraceTime 0 in sshd_config.
It is designed to be run via Ansible, but you can also execute the script manually if you wish.
Read more about the regreSSHion vulnerability here:
sshd -V, falling back to ssh -Vopenssh-server package version from dpkg or rpmopenssh-server (apt or dnf) when the host is vulnerable, before
any workaroundLoginGraceTime 0 only if the host is still vulnerable after thatsshd_config before any change, mirroring its full path under
the backup directory, with a timestampsshd -t before putting it in place, checks
again afterwards, and restores the backup if that fails--apply changes the filePyYAML, only for a run that reads a YAML config file (the installed
apply). The role installs it from the distribution (python3-yaml,
py3-yaml or python3-pyyaml), never from PyPI. The detection entry
needs only the standard library: its config goes in as JSON on stdinsshd present on the target for --apply: the script will not change a
file it cannot validateThe script is configured via a YAML file, templated automatically by the role.
Example regresshion_config.yaml:
sshd_binary: /usr/sbin/sshd
ssh_binary: /usr/bin/ssh
sshd_config: /etc/ssh/sshd_config
backup_directory: /var/backups/regresshion
log_file: /var/log/regresshion_mitigation.log
treat_unknown_as_vulnerable: false
fixed_versions:
"ubuntu:noble": "1:9.6p1-3ubuntu13.3"
"ubuntu:mantic": "1:9.3p1-1ubuntu3.6"
"ubuntu:jammy": "1:8.9p1-3ubuntu0.10"
"debian:bookworm": "1:9.2p1-2+deb12u3"
"rhel:9": "8.7p1-38.el9_4.1"
sshd_binary, ssh_binary: where to read the version from, and the sshd used for sshd -tsshd_config: the server configuration to changebackup_directory: where to store the original sshd_config backupslog_file: path to a log file for operation trackingtreat_unknown_as_vulnerable: apply the workaround to hosts whose status is unknownfixed_versions: first fixed openssh-server package per release, keyed
<os-release ID>:<VERSION_CODENAME> on dpkg systems and
<os-release ID>:<major VERSION_ID> on rpm systemsThe fixed versions above are those in USN-6859-1, DSA-5724-1 and RHSA-2024:4312. Ubuntu 20.04, Debian 11 and RHEL 8 ship OpenSSH older than 8.5p1 and are not affected, so they need no entry. Add entries for any other distribution from its own advisory. Red Hat's EUS streams carry their own builds; give them their own key if you run them.
Add this role to your playbook:
- name: Mitigate regreSSHion CVE-2024-6387
hosts: all
become: true
roles:
- regresshion_mitigation
The role runs the script once to detect, upgrades openssh-server if the host
is vulnerable, then runs it again with --apply. With regresshion_restart: true an upgrade restarts sshd and the workaround reloads it; by default
neither happens, because either is the operator's to schedule, and the
running sshd keeps its old binary or setting until then. Set regresshion_upgrade_package: false or
regresshion_apply_workaround: false to skip either step.
If you wish to run the script manually, you can do so:
Copy the script and the shared library beside it to your target machine:
files/regresshion_mitigator.py
files/samp_common.py
Create your own regresshion_config.yaml in the same directory.
Run it:
python3 regresshion_mitigator.py # report only
python3 regresshion_mitigator.py --apply # change sshd_config if vulnerable
python3 regresshion_mitigator.py --config /path/to/regresshion_config.yaml
After --apply reports workaround_applied=1, reload sshd yourself:
systemctl reload ssh (Debian, Ubuntu) or systemctl reload sshd (Red Hat).
vulnerable=N fixed=N not_affected=N unknown=N workaround_applied=N would_apply=N workaround_in_effect=N failed=N
to stdout. Warnings go to stderr and the role shows them.unknown=1 means the host needs checking against its vendor's advisory by
hand; the log says whysshd -T | grep logingracetime as root to confirm the value sshd is using/var/log/regresshion_mitigation.log)sshd has been restartedLoginGraceTime 0 trades the RCE for a denial-of-service risk. In
Qualys's words, it "makes sshd vulnerable to a denial of service (the
exhaustion of all MaxStartups connections)". Unauthenticated connections are
no longer timed out, so an attacker can hold every slot open. Red Hat
recommends pairing it with fail2ban and a firewallopenssh-server as the fix, then remove
the lines the script added at the top of sshd_config. Installing the
updated package does not remove themsshd_config. sshd keeps the first
LoginGraceTime it reads, and Ubuntu 22.04 onwards includes
sshd_config.d/*.conf at the start of the file, so a line appended at the
end would be ignoredOpenSSH_9.6p1 Ubuntu-3ubuntu13.3 is
fixed; OpenSSH_9.6p1 Ubuntu-3ubuntu13 is not; the upstream version is the
sameThis repository is a SAMP: the Microcelium Substrate imports it from this exact URL, pins it by commit, verifies the release tag's signature, scans it, and has a human approve it before it runs anywhere.

منصة XDR و SIEM مفتوحة المصدر لكشف التهديدات وتحليل السجلات ومراقبة سلامة الملفات وتقييم الثغرات وإدارة الامتثال عبر نقاط النهاية وأعباء العمل السحابية.

محرك شبكة مفتوح المصدر لأنظمة IDS/IPS/NSM لفحص حركة المرور في الوقت الفعلي، واكتشاف ومنع التسلل، وتحليل البروتوكولات، ومطاردة التهديدات المبنية على القواعد.

Zeek هو إطار تحليل شبكات قوي يختلف كثيرًا عن نظام IDS التقليدي الذي قد تعرفه.