/
log4j-cve-2021-44228.yml
67 lines (59 loc) · 1.91 KB
/
log4j-cve-2021-44228.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
---
- hosts: all
vars:
responsible_class: JndiLookup.class
pre_tasks:
- name: Check if filename has been provided
ansible.builtin.fail:
msg: "Provide filename to save result in local_file var"
any_errors_fatal: yes
when: local_file is undefined
run_once: yes
- name: Create CSV line and header
ansible.builtin.lineinfile:
path: "{{ local_file }}"
line: "hostname,vulnerable_file"
insertbefore: BOF
create: yes
delegate_to: localhost
run_once: yes
tasks:
- name: Find vulnerable files in remote system
block:
- name: Find directories where the search is to be performed
ansible.builtin.find:
file_type: directory
paths:
- "/"
recurse: no
excludes:
- "proc"
- "dev"
- "boot"
register: root_dirs
- debug:
var: root_dirs.files
- name: Find .jar files
ansible.builtin.find:
file_type: file
paths: "{{ root_dirs.files | map(attribute='path') }}"
recurse: yes
patterns:
- "*.jar"
register: jar_files
- name: Search JndiLookup.class in .jar files
ansible.builtin.shell:
cmd: "grep -i {{ responsible_class }} {{ jar_files.files | map(attribute='path') | join(' ') }}"
register: grep_result
failed_when: grep_result.rc == 2
when: jar_files.matched > 0
become: yes
post_tasks:
- name: Write CSV line with affected values
ansible.builtin.lineinfile:
path: "{{ local_file }}"
line: "{{ inventory_hostname }},{{ item | regex_search('/.*\\.jar') }}"
insertafter: EOF
loop: "{{ grep_result.stdout_lines }}"
when: grep_result.rc is defined and grep_result.rc == 0
delegate_to: localhost