|
1
|
|
|
#!/usr/bin/env python2 |
|
2
|
|
|
from __future__ import print_function |
|
3
|
|
|
|
|
4
|
|
|
import logging |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
import ssg_test_suite.oscap |
|
8
|
|
|
from ssg_test_suite.rule import get_viable_profiles |
|
9
|
|
|
|
|
10
|
|
|
logging.getLogger(__name__).addHandler(logging.NullHandler()) |
|
11
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
class ProfileChecker(ssg_test_suite.oscap.Checker): |
|
14
|
|
|
""" |
|
15
|
|
|
Iterate over profiles in datastream and perform scanning of unaltered system |
|
16
|
|
|
using every profile according to input. Also perform remediation run. |
|
17
|
|
|
Return value not defined, textual output and generated reports is the result. |
|
18
|
|
|
""" |
|
19
|
|
|
def _test_target(self, target): |
|
20
|
|
|
profiles = get_viable_profiles( |
|
21
|
|
|
target, self.datastream, self.benchmark_id) |
|
22
|
|
|
self.run_test_for_all_profiles(profiles) |
|
23
|
|
|
|
|
24
|
|
|
def _run_test(self, profile, test_data): |
|
25
|
|
|
self.executed_tests += 1 |
|
26
|
|
|
|
|
27
|
|
|
runner_cls = ssg_test_suite.oscap.REMEDIATION_PROFILE_RUNNERS[self.remediate_using] |
|
28
|
|
|
runner = runner_cls( |
|
29
|
|
|
self.test_env, profile, self.datastream, self.benchmark_id) |
|
30
|
|
|
|
|
31
|
|
|
for stage in ("initial", "remediation", "final"): |
|
32
|
|
|
result = runner.run_stage(stage) |
|
33
|
|
|
if result: |
|
34
|
|
|
logging.info("Evaluation of the profile has passed: {0} ({1} stage).".format(profile, stage)) |
|
35
|
|
|
else: |
|
36
|
|
|
logging.error("Evaluation of the profile has failed: {0} ({1} stage).".format(profile, stage)) |
|
37
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
def perform_profile_check(options): |
|
40
|
|
|
checker = ProfileChecker(options.test_env) |
|
41
|
|
|
|
|
42
|
|
|
checker.datastream = options.datastream |
|
43
|
|
|
checker.benchmark_id = options.benchmark_id |
|
44
|
|
|
checker.remediate_using = options.remediate_using |
|
45
|
|
|
|
|
46
|
|
|
checker.test_target(options.target) |
|
47
|
|
|
|