
log4j mitigation work
This Ansible role deploys a Python-based script to programmatically mitigate the Log4Shell vulnerability (CVE-2021-44228) by removing the vulnerable JndiLookup class from affected Log4j JAR files.
It is designed to be run via Ansible, but you can also execute the script manually if you wish.
Read more about the Log4Shell vulnerability here:
JndiLookup.class is presentJndiLookup.class from the JARzip and zipinfo installed on the target systemsPyYAML installed on the target systems (pip install pyyaml)The script is configured via a YAML file, templated automatically by the role.
Example config.yaml:
app_directories:
- /opt/apps
backup_directory: /opt/backups
log_file: /var/log/log4j_mitigation.log
app_directories: list of directories to scan for JAR filesbackup_directory: where to store the original JAR backupslog_file: path to a log file for operation trackingAdd this role to your playbook:
- name: Mitigate Log4Shell CVE-2021-44228
hosts: all
become: true
roles:
- log4shell_mitigation
If you wish to run the script manually, you can do so:
Copy the script to your target machine:
files/log4shell_mitigator.py
Create your own config.yaml in the same directory.
Run it:
python3 log4shell_mitigator.py
/var/log/log4j_mitigation.log) to see which JARs were patchedMIT
PRs and improvements welcome -> please fork and submit a merge request.
This software and accompanying Ansible role are provided “as is” and without warranties of any kind, express or implied. You are solely responsible for evaluating and testing the suitability, safety, and effectiveness of this code before applying it to any environment. AxisOps Ltd (GB08681761) expressly disclaims any liability for damages, data loss, service interruption, or other harm resulting from the use or misuse of this code.
Use at your own risk. Always audit, test, and validate the code in a controlled environment before deployment to production.
SysOps Team @ AxisOps