| 1 |
- name: create test directory |
| 2 |
ansible.windows.win_file: |
| 3 |
path: '{{ win_unzip_dir }}\output' |
| 4 |
state: directory |
| 5 |
|
| 6 |
- name: create local zip file with non-ascii chars |
| 7 |
script: create_zip.py {{ output_dir + '/win_unzip.zip' | quote }} |
| 8 |
delegate_to: localhost |
| 9 |
|
| 10 |
- name: copy across zip to Windows host |
| 11 |
ansible.windows.win_copy: |
| 12 |
src: '{{ output_dir }}/win_unzip.zip' |
| 13 |
dest: '{{ win_unzip_dir }}\win_unzip.zip' |
| 14 |
|
| 15 |
- name: unarchive zip (check) |
| 16 |
win_unzip: |
| 17 |
src: '{{ win_unzip_dir }}\win_unzip.zip' |
| 18 |
dest: '{{ win_unzip_dir }}\output' |
| 19 |
register: unzip_check |
| 20 |
check_mode: yes |
| 21 |
|
| 22 |
- name: get result of unarchive zip (check) |
| 23 |
ansible.windows.win_stat: |
| 24 |
path: '{{ win_unzip_dir }}\output\café.txt' |
| 25 |
register: unzip_actual_check |
| 26 |
|
| 27 |
- name: assert result of unarchive zip (check) |
| 28 |
assert: |
| 29 |
that: |
| 30 |
- unzip_check is changed |
| 31 |
- not unzip_check.removed |
| 32 |
- not unzip_actual_check.stat.exists |
| 33 |
|
| 34 |
- name: unarchive zip |
| 35 |
win_unzip: |
| 36 |
src: '{{ win_unzip_dir }}\win_unzip.zip' |
| 37 |
dest: '{{ win_unzip_dir }}\output' |
| 38 |
register: unzip |
| 39 |
|
| 40 |
- name: get result of unarchive zip |
| 41 |
ansible.windows.slurp: |
| 42 |
path: '{{ win_unzip_dir }}\output\café.txt' |
| 43 |
register: unzip_actual |
| 44 |
|
| 45 |
- name: assert result of unarchive zip |
| 46 |
assert: |
| 47 |
that: |
| 48 |
- unzip is changed |
| 49 |
- not unzip.removed |
| 50 |
- unzip_actual.content | b64decode == 'café.txt' |
| 51 |
|
| 52 |
# Module is not idempotent, will always change without creates |
| 53 |
- name: unarchive zip again without creates |
| 54 |
win_unzip: |
| 55 |
src: '{{ win_unzip_dir }}\win_unzip.zip' |
| 56 |
dest: '{{ win_unzip_dir }}\output' |
| 57 |
register: unzip_again |
| 58 |
|
| 59 |
- name: assert unarchive zip again without creates |
| 60 |
assert: |
| 61 |
that: |
| 62 |
- unzip_again is changed |
| 63 |
- not unzip_again.removed |
| 64 |
|
| 65 |
- name: unarchive zip with creates |
| 66 |
win_unzip: |
| 67 |
src: '{{ win_unzip_dir }}\win_unzip.zip' |
| 68 |
dest: '{{ win_unzip_dir }}\outout' |
| 69 |
creates: '{{ win_unzip_dir }}\output\café.txt' |
| 70 |
register: unzip_again_creates |
| 71 |
|
| 72 |
- name: assert unarchive zip with creates |
| 73 |
assert: |
| 74 |
that: |
| 75 |
- not unzip_again_creates is changed |
| 76 |
- not unzip_again_creates.removed |
| 77 |
|
| 78 |
- name: unarchive zip with delete (check) |
| 79 |
win_unzip: |
| 80 |
src: '{{ win_unzip_dir }}\win_unzip.zip' |
| 81 |
dest: '{{ win_unzip_dir }}\output' |
| 82 |
delete_archive: yes |
| 83 |
register: unzip_delete_check |
| 84 |
check_mode: yes |
| 85 |
|
| 86 |
- name: get result of unarchive zip with delete (check) |
| 87 |
ansible.windows.win_stat: |
| 88 |
path: '{{ win_unzip_dir }}\win_unzip.zip' |
| 89 |
register: unzip_delete_actual_check |
| 90 |
|
| 91 |
- name: assert unarchive zip with delete (check) |
| 92 |
assert: |
| 93 |
that: |
| 94 |
- unzip_delete_check is changed |
| 95 |
- unzip_delete_check.removed |
| 96 |
- unzip_delete_actual_check.stat.exists |
| 97 |
|
| 98 |
- name: unarchive zip with delete |
| 99 |
win_unzip: |
| 100 |
src: '{{ win_unzip_dir }}\win_unzip.zip' |
| 101 |
dest: '{{ win_unzip_dir }}\output' |
| 102 |
delete_archive: yes |
| 103 |
register: unzip_delete |
| 104 |
|
| 105 |
- name: get result of unarchive zip with delete |
| 106 |
ansible.windows.win_stat: |
| 107 |
path: '{{ win_unzip_dir }}\win_unzip.zip' |
| 108 |
register: unzip_delete_actual |
| 109 |
|
| 110 |
- name: assert unarchive zip with delete |
| 111 |
assert: |
| 112 |
that: |
| 113 |
- unzip_delete is changed |
| 114 |
- unzip_delete.removed |
| 115 |
- not unzip_delete_actual.stat.exists |
| 116 |
|
| 117 |
# Path traversal tests (CVE-2020-1737) |
| 118 |
- name: Create zip files |
| 119 |
script: create_crafty_zip_files.py {{ output_dir }} |
| 120 |
delegate_to: localhost |
| 121 |
|
| 122 |
- name: Copy zip files to Windows host |
| 123 |
ansible.windows.win_copy: |
| 124 |
src: "{{ output_dir }}/{{ item }}.zip" |
| 125 |
dest: "{{ win_unzip_dir }}/" |
| 126 |
loop: |
| 127 |
- hat1 |
| 128 |
- hat2 |
| 129 |
- handcuffs |
| 130 |
- prison |
| 131 |
|
| 132 |
- name: Perform first trick |
| 133 |
win_unzip: |
| 134 |
src: '{{ win_unzip_dir }}\hat1.zip' |
| 135 |
dest: '{{ win_unzip_dir }}\output' |
| 136 |
register: hat_trick1 |
| 137 |
|
| 138 |
- name: Check for file |
| 139 |
ansible.windows.win_stat: |
| 140 |
path: '{{ win_unzip_dir }}\output\rabbit.txt' |
| 141 |
register: rabbit |
| 142 |
|
| 143 |
- name: Perform next tricks (which should all fail) |
| 144 |
win_unzip: |
| 145 |
src: '{{ win_unzip_dir }}\{{ item }}.zip' |
| 146 |
dest: '{{ win_unzip_dir }}\output' |
| 147 |
ignore_errors: yes |
| 148 |
register: escape |
| 149 |
loop: |
| 150 |
- hat2 |
| 151 |
- handcuffs |
| 152 |
- prison |
| 153 |
|
| 154 |
- name: Search for files |
| 155 |
ansible.windows.win_find: |
| 156 |
recurse: yes |
| 157 |
paths: |
| 158 |
- '{{ win_unzip_dir }}' |
| 159 |
patterns: |
| 160 |
- '*houdini.txt' |
| 161 |
- '*rabbit.txt' |
| 162 |
register: files |
| 163 |
|
| 164 |
- name: Check results |
| 165 |
assert: |
| 166 |
that: |
| 167 |
- rabbit.stat.exists |
| 168 |
- hat_trick1 is success |
| 169 |
- escape.results | map(attribute='failed') | unique | list == [True] |
| 170 |
- files.matched == 1 |
| 171 |
- files.files[0]['filename'] == 'rabbit.txt' |