Skip to content

Commit 12b8fcf

Browse files
committed
target addresses of listening ports and add control for troubleshooting
1 parent e17486c commit 12b8fcf

File tree

3 files changed

+71
-35
lines changed

3 files changed

+71
-35
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
Gemfile.lock
2+
inspec.lock
23
Berksfile.lock
34
.vagrant/

controls/ssl_test.rb

Lines changed: 69 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -18,96 +18,131 @@
1818

1919
# Valid protocols are: ssl2, ssl3, tls1.0, tls1.1, tls1.2
2020

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+
2130
# Find all TCP ports on the system, IPv4 and IPv6
2231
# 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|
2433
entry['port']
2534
end
2635

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']
3139
end
3240

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
3649

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 }
4465
end
4566
end
4667

4768
control 'ssl2' do
48-
title 'Disable SSL2 from all exposed SSL ports.'
69+
title 'Disable SSL 2 from all exposed SSL ports.'
4970
impact 1.0
5071

51-
sslports.each do |socket|
72+
sslports.each do |sslport|
5273
# 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
5576
it(proc_desc) { should_not be_enabled }
5677
it { should_not be_enabled }
5778
end
5879
end
5980
end
6081

6182
control 'ssl3' do
62-
title 'Disable SSL3 from all exposed SSL ports.'
83+
title 'Disable SSL 3 from all exposed SSL ports.'
6384
impact 1.0
6485

65-
sslports.each do |socket|
86+
sslports.each do |sslport|
6687
# 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
6990
it(proc_desc) { should_not be_enabled }
7091
it { should_not be_enabled }
7192
end
7293
end
7394
end
7495

7596
control 'tls1.0' do
76-
title 'Disable tls1.0 from all exposed ports.'
97+
title 'Disable TLS 1.0 on exposed ports.'
7798
impact 0.5
7899

79-
sslports.each do |socket|
100+
sslports.each do |sslport|
80101
# 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
83104
it(proc_desc) { should_not be_enabled }
84105
it { should_not be_enabled }
85106
end
86107
end
87108
end
88109

89110
control 'tls1.1' do
90-
title 'Disable tls1.1 from all exposed ports.'
111+
title 'Disable TLS 1.1 on exposed ports.'
91112
impact 0.5
92113

93-
sslports.each do |socket|
114+
sslports.each do |sslport|
94115
# 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
97118
it(proc_desc) { should_not be_enabled }
98119
it { should_not be_enabled }
99120
end
100121
end
101122
end
102123

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+
103138
control 'rc4' do
104139
title 'Disable RC4 ciphers from all exposed SSL/TLS ports and versions.'
105140
impact 0.5
106141

107-
sslports.each do |socket|
142+
sslports.each do |sslport|
108143
# 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
111146
it(proc_desc) { should_not be_enabled }
112147
it { should_not be_enabled }
113148
end

inspec.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ copyright: Hardening Framework Team, Chef Software Inc.
55
copyright_email: hello@dev-sec.io
66
license: Apache 2 license
77
summary: Demonstrates the use of InSpec's SSL resource
8-
version: 1.1.1
8+
version: 1.1.3
99
supports:
1010
- inspec: '>= 0.33.2'

0 commit comments

Comments
 (0)