| 1 |
#!/usr/bin/python |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
# |
| 4 |
# Ansible module to manage Check Point Firewall (c) 2019 |
| 5 |
# |
| 6 |
# Ansible is free software: you can redistribute it and/or modify |
| 7 |
# it under the terms of the GNU General Public License as published by |
| 8 |
# the Free Software Foundation, either version 3 of the License, or |
| 9 |
# (at your option) any later version. |
| 10 |
# |
| 11 |
# Ansible is distributed in the hope that it will be useful, |
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
# GNU General Public License for more details. |
| 15 |
# |
| 16 |
# You should have received a copy of the GNU General Public License |
| 17 |
# along with Ansible. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
# |
| 19 |
|
| 20 |
from __future__ import absolute_import, division, print_function |
| 21 |
|
| 22 |
__metaclass__ = type |
| 23 |
|
| 24 |
ANSIBLE_METADATA = { |
| 25 |
"metadata_version": "1.1", |
| 26 |
"status": ["preview"], |
| 27 |
"supported_by": "community", |
| 28 |
} |
| 29 |
|
| 30 |
DOCUMENTATION = """ |
| 31 |
--- |
| 32 |
module: cp_mgmt_threat_profile |
| 33 |
short_description: Manages threat-profile objects on Check Point over Web Services API |
| 34 |
description: |
| 35 |
- Manages threat-profile objects on Check Point devices including creating, updating and removing objects. |
| 36 |
- All operations are performed over Web Services API. |
| 37 |
- Available from R80 management version. |
| 38 |
version_added: "1.0.0" |
| 39 |
author: "Or Soffer (@chkp-orso)" |
| 40 |
options: |
| 41 |
name: |
| 42 |
description: |
| 43 |
- Object name. |
| 44 |
type: str |
| 45 |
required: True |
| 46 |
active_protections_performance_impact: |
| 47 |
description: |
| 48 |
- Protections with this performance impact only will be activated in the profile. |
| 49 |
type: str |
| 50 |
choices: ['high', 'medium', 'low', 'very_low'] |
| 51 |
active_protections_severity: |
| 52 |
description: |
| 53 |
- Protections with this severity only will be activated in the profile. |
| 54 |
type: str |
| 55 |
choices: ['Critical', 'High', 'Medium or above', 'Low or above'] |
| 56 |
advanced_dns_settings: |
| 57 |
description: |
| 58 |
- Advanced DNS Settings. |
| 59 |
type: dict |
| 60 |
suboptions: |
| 61 |
dga_detection: |
| 62 |
description: |
| 63 |
- Enable/Disable DGA based domains detection. |
| 64 |
type: str |
| 65 |
choices: ['true', 'false'] |
| 66 |
dns_domain_tunneling: |
| 67 |
description: |
| 68 |
- Enable/Disable DNS Tunneling based on domains detection. |
| 69 |
type: str |
| 70 |
choices: ['true', 'false'] |
| 71 |
dns_over_https: |
| 72 |
description: |
| 73 |
- Enable/Disable parsing of DNS over HTTPS protocol. |
| 74 |
type: str |
| 75 |
choices: ['true', 'false'] |
| 76 |
nxns_attack_detection: |
| 77 |
description: |
| 78 |
- Enable/Disable NXNS attack detection. |
| 79 |
type: str |
| 80 |
choices: ['true', 'false'] |
| 81 |
confidence_level_high: |
| 82 |
description: |
| 83 |
- Action for protections with high confidence level. |
| 84 |
type: str |
| 85 |
choices: ['Inactive', 'Ask', 'Prevent', 'Detect'] |
| 86 |
confidence_level_low: |
| 87 |
description: |
| 88 |
- Action for protections with low confidence level. |
| 89 |
type: str |
| 90 |
choices: ['Inactive', 'Ask', 'Prevent', 'Detect'] |
| 91 |
confidence_level_medium: |
| 92 |
description: |
| 93 |
- Action for protections with medium confidence level. |
| 94 |
type: str |
| 95 |
choices: ['Inactive', 'Ask', 'Prevent', 'Detect'] |
| 96 |
indicator_overrides: |
| 97 |
description: |
| 98 |
- Indicators whose action will be overridden in this profile. |
| 99 |
type: list |
| 100 |
elements: dict |
| 101 |
suboptions: |
| 102 |
action: |
| 103 |
description: |
| 104 |
- The indicator's action in this profile. |
| 105 |
type: str |
| 106 |
choices: ['Inactive', 'Ask', 'Prevent', 'Detect'] |
| 107 |
indicator: |
| 108 |
description: |
| 109 |
- The indicator whose action is to be overridden. |
| 110 |
type: str |
| 111 |
ips_settings: |
| 112 |
description: |
| 113 |
- IPS blade settings. |
| 114 |
type: dict |
| 115 |
suboptions: |
| 116 |
exclude_protection_with_performance_impact: |
| 117 |
description: |
| 118 |
- Whether to exclude protections depending on their level of performance impact. |
| 119 |
type: bool |
| 120 |
exclude_protection_with_performance_impact_mode: |
| 121 |
description: |
| 122 |
- Exclude protections with this level of performance impact. |
| 123 |
type: str |
| 124 |
choices: ['very low', 'low or lower', 'medium or lower', 'high or lower'] |
| 125 |
exclude_protection_with_severity: |
| 126 |
description: |
| 127 |
- Whether to exclude protections depending on their level of severity. |
| 128 |
type: bool |
| 129 |
exclude_protection_with_severity_mode: |
| 130 |
description: |
| 131 |
- Exclude protections with this level of severity. |
| 132 |
type: str |
| 133 |
choices: ['low or above', 'medium or above', 'high or above', 'critical'] |
| 134 |
newly_updated_protections: |
| 135 |
description: |
| 136 |
- Activation of newly updated protections. |
| 137 |
type: str |
| 138 |
choices: ['active', 'inactive', 'staging'] |
| 139 |
malicious_mail_policy_settings: |
| 140 |
description: |
| 141 |
- Malicious Mail Policy for MTA Gateways. |
| 142 |
- Available from R80.20.M1 management version. |
| 143 |
type: dict |
| 144 |
suboptions: |
| 145 |
add_customized_text_to_email_body: |
| 146 |
description: |
| 147 |
- Add customized text to the malicious email body. |
| 148 |
type: bool |
| 149 |
add_email_subject_prefix: |
| 150 |
description: |
| 151 |
- Add a prefix to the malicious email subject. |
| 152 |
type: bool |
| 153 |
add_x_header_to_email: |
| 154 |
description: |
| 155 |
- Add an X-Header to the malicious email. |
| 156 |
type: bool |
| 157 |
email_action: |
| 158 |
description: |
| 159 |
- Block - block the entire malicious email<br>Allow - pass the malicious email and apply email changes (like, remove attachments and |
| 160 |
links, add x-header, etc...). |
| 161 |
type: str |
| 162 |
choices: ['allow', 'block'] |
| 163 |
email_body_customized_text: |
| 164 |
description: |
| 165 |
- Customized text for the malicious email body.<br> Available predefined fields,<br> $verdicts$ - the malicious/error attachments/links verdict. |
| 166 |
type: str |
| 167 |
email_subject_prefix_text: |
| 168 |
description: |
| 169 |
- Prefix for the malicious email subject. |
| 170 |
type: str |
| 171 |
failed_to_scan_attachments_text: |
| 172 |
description: |
| 173 |
- Replace attachments that failed to be scanned with this text.<br> Available predefined fields,<br> $filename$ - the malicious file |
| 174 |
name.<br> $md5$ - MD5 of the malicious file. |
| 175 |
type: str |
| 176 |
malicious_attachments_text: |
| 177 |
description: |
| 178 |
- Replace malicious attachments with this text.<br> Available predefined fields,<br> $filename$ - the malicious file name.<br> $md5$ - |
| 179 |
MD5 of the malicious file. |
| 180 |
type: str |
| 181 |
malicious_links_text: |
| 182 |
description: |
| 183 |
- Replace malicious links with this text.<br> Available predefined fields,<br> $neutralized_url$ - neutralized malicious link. |
| 184 |
type: str |
| 185 |
remove_attachments_and_links: |
| 186 |
description: |
| 187 |
- Remove attachments and links from the malicious email. |
| 188 |
type: bool |
| 189 |
send_copy: |
| 190 |
description: |
| 191 |
- Send a copy of the malicious email to the recipient list. |
| 192 |
type: bool |
| 193 |
send_copy_list: |
| 194 |
description: |
| 195 |
- Recipient list to send a copy of the malicious email. |
| 196 |
type: list |
| 197 |
elements: str |
| 198 |
overrides: |
| 199 |
description: |
| 200 |
- Overrides per profile for this protection. |
| 201 |
type: list |
| 202 |
elements: dict |
| 203 |
suboptions: |
| 204 |
action: |
| 205 |
description: |
| 206 |
- Protection action. |
| 207 |
type: str |
| 208 |
choices: ['Threat Cloud: Inactive', 'Detect', 'Prevent <br> Core: Drop', 'Inactive', 'Accept'] |
| 209 |
protection: |
| 210 |
description: |
| 211 |
- IPS protection identified by name or UID. |
| 212 |
type: str |
| 213 |
capture_packets: |
| 214 |
description: |
| 215 |
- Capture packets. |
| 216 |
type: bool |
| 217 |
track: |
| 218 |
description: |
| 219 |
- Tracking method for protection. |
| 220 |
type: str |
| 221 |
choices: ['none', 'log', 'alert', 'mail', 'snmp trap', 'user alert', 'user alert 1', 'user alert 2'] |
| 222 |
scan_malicious_links: |
| 223 |
description: |
| 224 |
- Scans malicious links (URLs) inside email messages. |
| 225 |
type: dict |
| 226 |
suboptions: |
| 227 |
max_bytes: |
| 228 |
description: |
| 229 |
- Scan links in the first bytes of the mail body. |
| 230 |
type: int |
| 231 |
max_links: |
| 232 |
description: |
| 233 |
- Maximum links to scan in mail body. |
| 234 |
type: int |
| 235 |
tags: |
| 236 |
description: |
| 237 |
- Collection of tag identifiers. |
| 238 |
type: list |
| 239 |
elements: str |
| 240 |
use_indicators: |
| 241 |
description: |
| 242 |
- Indicates whether the profile should make use of indicators. |
| 243 |
type: bool |
| 244 |
anti_bot: |
| 245 |
description: |
| 246 |
- Is Anti-Bot blade activated. |
| 247 |
type: bool |
| 248 |
anti_virus: |
| 249 |
description: |
| 250 |
- Is Anti-Virus blade activated. |
| 251 |
type: bool |
| 252 |
ips: |
| 253 |
description: |
| 254 |
- Is IPS blade activated. |
| 255 |
type: bool |
| 256 |
threat_emulation: |
| 257 |
description: |
| 258 |
- Is Threat Emulation blade activated. |
| 259 |
type: bool |
| 260 |
threat_extraction: |
| 261 |
description: |
| 262 |
- Is Threat Extraction blade activated. |
| 263 |
type: bool |
| 264 |
zero_phishing: |
| 265 |
description: |
| 266 |
- Is Zero Phishing blade activated. |
| 267 |
type: bool |
| 268 |
activate_protections_by_extended_attributes: |
| 269 |
description: |
| 270 |
- Activate protections by these extended attributes. |
| 271 |
type: list |
| 272 |
elements: dict |
| 273 |
suboptions: |
| 274 |
name: |
| 275 |
description: |
| 276 |
- IPS tag name. |
| 277 |
type: str |
| 278 |
category: |
| 279 |
description: |
| 280 |
- IPS tag category name. |
| 281 |
type: str |
| 282 |
deactivate_protections_by_extended_attributes: |
| 283 |
description: |
| 284 |
- Deactivate protections by these extended attributes. |
| 285 |
type: list |
| 286 |
elements: dict |
| 287 |
suboptions: |
| 288 |
name: |
| 289 |
description: |
| 290 |
- IPS tag name. |
| 291 |
type: str |
| 292 |
category: |
| 293 |
description: |
| 294 |
- IPS tag category name. |
| 295 |
type: str |
| 296 |
use_extended_attributes: |
| 297 |
description: |
| 298 |
- Whether to activate/deactivate IPS protections according to the extended attributes. |
| 299 |
type: bool |
| 300 |
color: |
| 301 |
description: |
| 302 |
- Color of the object. Should be one of existing colors. |
| 303 |
type: str |
| 304 |
choices: ['aquamarine', 'black', 'blue', 'crete blue', 'burlywood', 'cyan', 'dark green', 'khaki', 'orchid', 'dark orange', 'dark sea green', |
| 305 |
'pink', 'turquoise', 'dark blue', 'firebrick', 'brown', 'forest green', 'gold', 'dark gold', 'gray', 'dark gray', 'light green', 'lemon chiffon', |
| 306 |
'coral', 'sea green', 'sky blue', 'magenta', 'purple', 'slate blue', 'violet red', 'navy blue', 'olive', 'orange', 'red', 'sienna', 'yellow'] |
| 307 |
comments: |
| 308 |
description: |
| 309 |
- Comments string. |
| 310 |
type: str |
| 311 |
details_level: |
| 312 |
description: |
| 313 |
- The level of detail for some of the fields in the response can vary from showing only the UID value of the object to a fully detailed |
| 314 |
representation of the object. |
| 315 |
type: str |
| 316 |
choices: ['uid', 'standard', 'full'] |
| 317 |
ignore_warnings: |
| 318 |
description: |
| 319 |
- Apply changes ignoring warnings. |
| 320 |
type: bool |
| 321 |
ignore_errors: |
| 322 |
description: |
| 323 |
- Apply changes ignoring errors. You won't be able to publish such a changes. If ignore-warnings flag was omitted - warnings will also be ignored. |
| 324 |
type: bool |
| 325 |
extends_documentation_fragment: check_point.mgmt.checkpoint_objects |
| 326 |
""" |
| 327 |
|
| 328 |
EXAMPLES = """ |
| 329 |
- name: add-threat-profile |
| 330 |
cp_mgmt_threat_profile: |
| 331 |
active_protections_performance_impact: low |
| 332 |
active_protections_severity: low or above |
| 333 |
anti_bot: true |
| 334 |
anti_virus: true |
| 335 |
confidence_level_high: prevent |
| 336 |
confidence_level_medium: prevent |
| 337 |
ips: true |
| 338 |
ips_settings: |
| 339 |
exclude_protection_with_performance_impact: true |
| 340 |
exclude_protection_with_performance_impact_mode: high or lower |
| 341 |
newly_updated_protections: staging |
| 342 |
name: New Profile 1 |
| 343 |
state: present |
| 344 |
threat_emulation: true |
| 345 |
|
| 346 |
- name: set-threat-profile |
| 347 |
cp_mgmt_threat_profile: |
| 348 |
active_protections_performance_impact: low |
| 349 |
active_protections_severity: low or above |
| 350 |
anti_bot: true |
| 351 |
anti_virus: false |
| 352 |
comments: update recommended profile |
| 353 |
confidence_level_high: prevent |
| 354 |
confidence_level_low: prevent |
| 355 |
confidence_level_medium: prevent |
| 356 |
ips: false |
| 357 |
ips_settings: |
| 358 |
exclude_protection_with_performance_impact: true |
| 359 |
exclude_protection_with_performance_impact_mode: high or lower |
| 360 |
newly_updated_protections: active |
| 361 |
name: New Profile 1 |
| 362 |
state: present |
| 363 |
threat_emulation: true |
| 364 |
|
| 365 |
- name: delete-threat-profile |
| 366 |
cp_mgmt_threat_profile: |
| 367 |
name: New Profile 1 |
| 368 |
state: absent |
| 369 |
""" |
| 370 |
|
| 371 |
RETURN = """ |
| 372 |
cp_mgmt_threat_profile: |
| 373 |
description: The checkpoint object created or updated. |
| 374 |
returned: always, except when deleting the object. |
| 375 |
type: dict |
| 376 |
""" |
| 377 |
|
| 378 |
from ansible.module_utils.basic import AnsibleModule |
| 379 |
from ansible_collections.check_point.mgmt.plugins.module_utils.checkpoint import ( |
| 380 |
checkpoint_argument_spec_for_objects, |
| 381 |
api_call, |
| 382 |
) |
| 383 |
|
| 384 |
|
| 385 |
def main(): |
| 386 |
argument_spec = dict( |
| 387 |
name=dict(type="str", required=True), |
| 388 |
active_protections_performance_impact=dict( |
| 389 |
type="str", choices=["high", "medium", "low", "very_low"] |
| 390 |
), |
| 391 |
active_protections_severity=dict( |
| 392 |
type="str", |
| 393 |
choices=["Critical", "High", "Medium or above", "Low or above"], |
| 394 |
), |
| 395 |
advanced_dns_settings=dict( |
| 396 |
type='dict', |
| 397 |
options=dict( |
| 398 |
dga_detection=dict(type='str', choices=['true', 'false']), |
| 399 |
dns_domain_tunneling=dict(type='str', choices=['true', 'false']), |
| 400 |
dns_over_https=dict(type='str', choices=['true', 'false']), |
| 401 |
nxns_attack_detection=dict(type='str', choices=['true', 'false']) |
| 402 |
) |
| 403 |
), |
| 404 |
confidence_level_high=dict( |
| 405 |
type="str", choices=["Inactive", "Ask", "Prevent", "Detect"] |
| 406 |
), |
| 407 |
confidence_level_low=dict( |
| 408 |
type="str", choices=["Inactive", "Ask", "Prevent", "Detect"] |
| 409 |
), |
| 410 |
confidence_level_medium=dict( |
| 411 |
type="str", choices=["Inactive", "Ask", "Prevent", "Detect"] |
| 412 |
), |
| 413 |
indicator_overrides=dict( |
| 414 |
type="list", |
| 415 |
elements="dict", |
| 416 |
options=dict( |
| 417 |
action=dict( |
| 418 |
type="str", |
| 419 |
choices=["Inactive", "Ask", "Prevent", "Detect"], |
| 420 |
), |
| 421 |
indicator=dict(type="str"), |
| 422 |
), |
| 423 |
), |
| 424 |
ips_settings=dict( |
| 425 |
type="dict", |
| 426 |
options=dict( |
| 427 |
exclude_protection_with_performance_impact=dict(type="bool"), |
| 428 |
exclude_protection_with_performance_impact_mode=dict( |
| 429 |
type="str", |
| 430 |
choices=[ |
| 431 |
"very low", |
| 432 |
"low or lower", |
| 433 |
"medium or lower", |
| 434 |
"high or lower", |
| 435 |
], |
| 436 |
), |
| 437 |
exclude_protection_with_severity=dict(type="bool"), |
| 438 |
exclude_protection_with_severity_mode=dict( |
| 439 |
type="str", |
| 440 |
choices=[ |
| 441 |
"low or above", |
| 442 |
"medium or above", |
| 443 |
"high or above", |
| 444 |
"critical", |
| 445 |
], |
| 446 |
), |
| 447 |
newly_updated_protections=dict( |
| 448 |
type="str", choices=["active", "inactive", "staging"] |
| 449 |
), |
| 450 |
), |
| 451 |
), |
| 452 |
malicious_mail_policy_settings=dict( |
| 453 |
type="dict", |
| 454 |
options=dict( |
| 455 |
add_customized_text_to_email_body=dict(type="bool"), |
| 456 |
add_email_subject_prefix=dict(type="bool"), |
| 457 |
add_x_header_to_email=dict(type="bool"), |
| 458 |
email_action=dict(type="str", choices=["allow", "block"]), |
| 459 |
email_body_customized_text=dict(type="str"), |
| 460 |
email_subject_prefix_text=dict(type="str"), |
| 461 |
failed_to_scan_attachments_text=dict(type="str"), |
| 462 |
malicious_attachments_text=dict(type="str"), |
| 463 |
malicious_links_text=dict(type="str"), |
| 464 |
remove_attachments_and_links=dict(type="bool"), |
| 465 |
send_copy=dict(type="bool"), |
| 466 |
send_copy_list=dict(type="list", elements="str"), |
| 467 |
), |
| 468 |
), |
| 469 |
overrides=dict( |
| 470 |
type="list", |
| 471 |
elements="dict", |
| 472 |
options=dict( |
| 473 |
action=dict( |
| 474 |
type="str", |
| 475 |
choices=[ |
| 476 |
"Threat Cloud: Inactive", |
| 477 |
"Detect", |
| 478 |
"Prevent <br> Core: Drop", |
| 479 |
"Inactive", |
| 480 |
"Accept", |
| 481 |
], |
| 482 |
), |
| 483 |
protection=dict(type="str"), |
| 484 |
capture_packets=dict(type="bool"), |
| 485 |
track=dict( |
| 486 |
type="str", |
| 487 |
choices=[ |
| 488 |
"none", |
| 489 |
"log", |
| 490 |
"alert", |
| 491 |
"mail", |
| 492 |
"snmp trap", |
| 493 |
"user alert", |
| 494 |
"user alert 1", |
| 495 |
"user alert 2", |
| 496 |
], |
| 497 |
), |
| 498 |
), |
| 499 |
), |
| 500 |
scan_malicious_links=dict(type='dict', options=dict( |
| 501 |
max_bytes=dict(type='int'), |
| 502 |
max_links=dict(type='int') |
| 503 |
)), |
| 504 |
tags=dict(type="list", elements="str"), |
| 505 |
use_indicators=dict(type="bool"), |
| 506 |
anti_bot=dict(type="bool"), |
| 507 |
anti_virus=dict(type="bool"), |
| 508 |
ips=dict(type="bool"), |
| 509 |
threat_emulation=dict(type="bool"), |
| 510 |
threat_extraction=dict(type='bool'), |
| 511 |
zero_phishing=dict(type='bool'), |
| 512 |
activate_protections_by_extended_attributes=dict( |
| 513 |
type="list", |
| 514 |
elements="dict", |
| 515 |
options=dict(name=dict(type="str"), category=dict(type="str")), |
| 516 |
), |
| 517 |
deactivate_protections_by_extended_attributes=dict( |
| 518 |
type="list", |
| 519 |
elements="dict", |
| 520 |
options=dict(name=dict(type="str"), category=dict(type="str")), |
| 521 |
), |
| 522 |
use_extended_attributes=dict(type="bool"), |
| 523 |
color=dict( |
| 524 |
type="str", |
| 525 |
choices=[ |
| 526 |
"aquamarine", |
| 527 |
"black", |
| 528 |
"blue", |
| 529 |
"crete blue", |
| 530 |
"burlywood", |
| 531 |
"cyan", |
| 532 |
"dark green", |
| 533 |
"khaki", |
| 534 |
"orchid", |
| 535 |
"dark orange", |
| 536 |
"dark sea green", |
| 537 |
"pink", |
| 538 |
"turquoise", |
| 539 |
"dark blue", |
| 540 |
"firebrick", |
| 541 |
"brown", |
| 542 |
"forest green", |
| 543 |
"gold", |
| 544 |
"dark gold", |
| 545 |
"gray", |
| 546 |
"dark gray", |
| 547 |
"light green", |
| 548 |
"lemon chiffon", |
| 549 |
"coral", |
| 550 |
"sea green", |
| 551 |
"sky blue", |
| 552 |
"magenta", |
| 553 |
"purple", |
| 554 |
"slate blue", |
| 555 |
"violet red", |
| 556 |
"navy blue", |
| 557 |
"olive", |
| 558 |
"orange", |
| 559 |
"red", |
| 560 |
"sienna", |
| 561 |
"yellow", |
| 562 |
], |
| 563 |
), |
| 564 |
comments=dict(type="str"), |
| 565 |
details_level=dict(type="str", choices=["uid", "standard", "full"]), |
| 566 |
ignore_warnings=dict(type="bool"), |
| 567 |
ignore_errors=dict(type="bool"), |
| 568 |
) |
| 569 |
argument_spec.update(checkpoint_argument_spec_for_objects) |
| 570 |
|
| 571 |
module = AnsibleModule( |
| 572 |
argument_spec=argument_spec, supports_check_mode=True |
| 573 |
) |
| 574 |
api_call_object = "threat-profile" |
| 575 |
|
| 576 |
result = api_call(module, api_call_object) |
| 577 |
module.exit_json(**result) |
| 578 |
|
| 579 |
|
| 580 |
if __name__ == "__main__": |
| 581 |
main() |