|
18 | 18 |
|
19 | 19 | # Valid protocols are: ssl2, ssl3, tls1.0, tls1.1, tls1.2 |
20 | 20 |
|
| 21 | +invalid_targets = %w{ |
| 22 | + 127.0.0.1 |
| 23 | + 0.0.0.0 |
| 24 | + ::1 |
| 25 | + :: |
| 26 | +} |
| 27 | + |
| 28 | +target_hostname = command('hostname').stdout.strip |
| 29 | + |
21 | 30 | # Find all TCP ports on the system, IPv4 and IPv6 |
22 | 31 | # Eliminate duplicate ports for cleaner reporting and faster scans |
23 | | -sslports = port.protocols(/tcp/).entries.uniq do |entry| |
| 32 | +tcpports = port.protocols(/tcp/).entries.uniq do |entry| |
24 | 33 | entry['port'] |
25 | 34 | end |
26 | 35 |
|
27 | | -# Filter out ports that don't respond to any version of SSL |
28 | | -sslports = sslports.find_all do |socket| |
29 | | - ssl(port: socket.port).enabled? |
30 | | - # ssl(port: tcp_port, timeout: 8, retries: 1).enabled? |
| 36 | +# Sort the array by port number |
| 37 | +tcpports = tcpports.sort_by do |entry| |
| 38 | + entry['port'] |
31 | 39 | end |
32 | 40 |
|
33 | | -control 'tls1.2' do |
34 | | - title 'Run TLS 1.2 whenever SSL is active on a port' |
35 | | - impact 0.5 |
| 41 | +# Make tcpports an array of hashes to be passed to the ssl resource |
| 42 | +tcpports = tcpports.map do |socket| |
| 43 | + params = { port: socket.port } |
| 44 | + # Add a host param if the listening address of the port is a valid/non-localhost IP |
| 45 | + params[:host] = socket.address unless invalid_targets.include?(socket.address) |
| 46 | + params[:socket] = socket |
| 47 | + params |
| 48 | +end |
36 | 49 |
|
37 | | - sslports.each do |socket| |
38 | | - # create a description |
39 | | - proc_desc = "on node == #{command('hostname').stdout.strip} running #{socket.process.inspect} (#{socket.pid})" |
40 | | - describe ssl(port: socket.port).protocols('tls1.2') do |
41 | | - it(proc_desc) { should be_enabled } |
42 | | - it { should be_enabled } |
43 | | - end |
| 50 | +# Filter out ports that don't respond to any version of SSL |
| 51 | +sslports = tcpports.find_all do |tcpport| |
| 52 | + ssl(tcpport).enabled? |
| 53 | +end |
| 54 | + |
| 55 | +# Troubleshooting control to show InSpec version and list |
| 56 | +# discovered tcp ports and the ssl enabled ones. Always succeeds |
| 57 | +control 'debugging' do |
| 58 | + title "Inspec::Version=#{Inspec::VERSION}" |
| 59 | + impact 0.0 |
| 60 | + describe "tcpports=\n#{tcpports.join("\n")}" do |
| 61 | + it { should_not eq nil } |
| 62 | + end |
| 63 | + describe "sslports=\n#{sslports.join("\n")}" do |
| 64 | + it { should_not eq nil } |
44 | 65 | end |
45 | 66 | end |
46 | 67 |
|
47 | 68 | control 'ssl2' do |
48 | | - title 'Disable SSL2 from all exposed SSL ports.' |
| 69 | + title 'Disable SSL 2 from all exposed SSL ports.' |
49 | 70 | impact 1.0 |
50 | 71 |
|
51 | | - sslports.each do |socket| |
| 72 | + sslports.each do |sslport| |
52 | 73 | # create a description |
53 | | - proc_desc = "on node == #{command('hostname').stdout.strip} running #{socket.process.inspect} (#{socket.pid})" |
54 | | - describe ssl(port: socket.port).protocols('ssl2') do |
| 74 | + proc_desc = "on node == #{target_hostname} running #{sslport[:socket].process.inspect} (#{sslport[:socket].pid})" |
| 75 | + describe ssl(sslport).protocols('ssl2') do |
55 | 76 | it(proc_desc) { should_not be_enabled } |
56 | 77 | it { should_not be_enabled } |
57 | 78 | end |
58 | 79 | end |
59 | 80 | end |
60 | 81 |
|
61 | 82 | control 'ssl3' do |
62 | | - title 'Disable SSL3 from all exposed SSL ports.' |
| 83 | + title 'Disable SSL 3 from all exposed SSL ports.' |
63 | 84 | impact 1.0 |
64 | 85 |
|
65 | | - sslports.each do |socket| |
| 86 | + sslports.each do |sslport| |
66 | 87 | # create a description |
67 | | - proc_desc = "on node == #{command('hostname').stdout.strip} running #{socket.process.inspect} (#{socket.pid})" |
68 | | - describe ssl(port: socket.port).protocols('ssl3') do |
| 88 | + proc_desc = "on node == #{target_hostname} running #{sslport[:socket].process.inspect} (#{sslport[:socket].pid})" |
| 89 | + describe ssl(sslport).protocols('ssl3') do |
69 | 90 | it(proc_desc) { should_not be_enabled } |
70 | 91 | it { should_not be_enabled } |
71 | 92 | end |
72 | 93 | end |
73 | 94 | end |
74 | 95 |
|
75 | 96 | control 'tls1.0' do |
76 | | - title 'Disable tls1.0 from all exposed ports.' |
| 97 | + title 'Disable TLS 1.0 on exposed ports.' |
77 | 98 | impact 0.5 |
78 | 99 |
|
79 | | - sslports.each do |socket| |
| 100 | + sslports.each do |sslport| |
80 | 101 | # create a description |
81 | | - proc_desc = "on node == #{command('hostname').stdout.strip} running #{socket.process.inspect} (#{socket.pid})" |
82 | | - describe ssl(port: socket.port).protocols('tls1.0') do |
| 102 | + proc_desc = "on node == #{target_hostname} running #{sslport[:socket].process.inspect} (#{sslport[:socket].pid})" |
| 103 | + describe ssl(sslport).protocols('tls1.0') do |
83 | 104 | it(proc_desc) { should_not be_enabled } |
84 | 105 | it { should_not be_enabled } |
85 | 106 | end |
86 | 107 | end |
87 | 108 | end |
88 | 109 |
|
89 | 110 | control 'tls1.1' do |
90 | | - title 'Disable tls1.1 from all exposed ports.' |
| 111 | + title 'Disable TLS 1.1 on exposed ports.' |
91 | 112 | impact 0.5 |
92 | 113 |
|
93 | | - sslports.each do |socket| |
| 114 | + sslports.each do |sslport| |
94 | 115 | # create a description |
95 | | - proc_desc = "on node == #{command('hostname').stdout.strip} running #{socket.process.inspect} (#{socket.pid})" |
96 | | - describe ssl(port: socket.port).protocols('tls1.1') do |
| 116 | + proc_desc = "on node == #{target_hostname} running #{sslport[:socket].process.inspect} (#{sslport[:socket].pid})" |
| 117 | + describe ssl(sslport).protocols('tls1.1') do |
97 | 118 | it(proc_desc) { should_not be_enabled } |
98 | 119 | it { should_not be_enabled } |
99 | 120 | end |
100 | 121 | end |
101 | 122 | end |
102 | 123 |
|
| 124 | +control 'tls1.2' do |
| 125 | + title 'Enable TLS 1.2 on exposed ports.' |
| 126 | + impact 0.5 |
| 127 | + |
| 128 | + sslports.each do |sslport| |
| 129 | + # create a description |
| 130 | + proc_desc = "on node == #{target_hostname} running #{sslport[:socket].process.inspect} (#{sslport[:socket].pid})" |
| 131 | + describe ssl(sslport).protocols('tls1.2') do |
| 132 | + it(proc_desc) { should be_enabled } |
| 133 | + it { should be_enabled } |
| 134 | + end |
| 135 | + end |
| 136 | +end |
| 137 | + |
103 | 138 | control 'rc4' do |
104 | 139 | title 'Disable RC4 ciphers from all exposed SSL/TLS ports and versions.' |
105 | 140 | impact 0.5 |
106 | 141 |
|
107 | | - sslports.each do |socket| |
| 142 | + sslports.each do |sslport| |
108 | 143 | # create a description |
109 | | - proc_desc = "on node == #{command('hostname').stdout.strip} running #{socket.process.inspect} (#{socket.pid})" |
110 | | - describe ssl(port: socket.port).ciphers(/rc4/i) do |
| 144 | + proc_desc = "on node == #{target_hostname} running #{sslport[:socket].process.inspect} (#{sslport[:socket].pid})" |
| 145 | + describe ssl(sslport).ciphers(/rc4/i) do |
111 | 146 | it(proc_desc) { should_not be_enabled } |
112 | 147 | it { should_not be_enabled } |
113 | 148 | end |
|
0 commit comments