-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathIdentify_exposed_SSH_keys_nodes_(3.x).xml
138 lines (119 loc) · 4.99 KB
/
Identify_exposed_SSH_keys_nodes_(3.x).xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<joblist>
<job>
<defaultTab>nodes</defaultTab>
<description>Identifies whether a host includes any of the exposed SSH keys in the `authorized_keys*` files.</description>
<dispatch>
<excludePrecedence>true</excludePrecedence>
<keepgoing>true</keepgoing>
<rankOrder>ascending</rankOrder>
<successOnEmptyNodeFilter>false</successOnEmptyNodeFilter>
<threadcount>1</threadcount>
</dispatch>
<executionEnabled>true</executionEnabled>
<id>6a94b275-056b-440e-8449-2a3da33bba92</id>
<loglevel>INFO</loglevel>
<name>Identify exposed SSH keys nodes (3.x)</name>
<nodeFilterEditable>false</nodeFilterEditable>
<nodefilters>
<filter>.*</filter>
</nodefilters>
<nodesSelectedByDefault>true</nodesSelectedByDefault>
<plugins />
<scheduleEnabled>true</scheduleEnabled>
<schedules />
<sequence keepgoing='false' strategy='node-first'>
<command>
<description>Test authorized_keys files for bad keys</description>
<errorhandler keepgoingOnSuccess='true'>
<node-step-plugin type='stub-node-step'>
<configuration>
<entry key='data' value='failed=true reason=${result.reason}' />
<entry key='format' value='properties' />
</configuration>
</node-step-plugin>
</errorhandler>
<plugins>
<LogFilter type='key-value-data'>
<config>
<invalidKeyPattern>\s|\$|\{|\}|\\</invalidKeyPattern>
<logData>true</logData>
<name>found</name>
<regex>^Files: (.+)$</regex>
</config>
</LogFilter>
<LogFilter type='key-value-data'>
<config>
<invalidKeyPattern>\s|\$|\{|\}|\\</invalidKeyPattern>
<logData>true</logData>
<name>count</name>
<regex>^Result: Found (\d+) files with bad keys$</regex>
</config>
</LogFilter>
</plugins>
<script><![CDATA[#!/bin/bash
# Sorry I assume you have bash, because otherwise this is a lot harder.
# set -eux
set -eu
# 2048 SHA256:h7njOUArdygRFZN8R8JRysZ5Vje57TDoszOFqW+mEtY rundeck@435cc7c0ec97 (RSA)
# 2048 SHA256:HyLeewdJH/1WAAQKixUs613XsRXbFQd6nxU6ikdmcn0 rundeck@a9408cab34cf (RSA)
# 2048 SHA256:fm4RAHs48DTFFwBTgL95wdGMeZcp7fIF5WjN015/3CA rundeck@d39a9897de35 (RSA)
# 2048 SHA256:kVLnHhPWC2vgTvOcPx+DhRL0mkhpIJloKmKQuLAOBfA rundeck@553322682a1d (RSA)
# 2048 SHA256:9NEpWJV6CD3gVnxu+SGx8kt+YO/jLi1ri6EtdRDQnMU rundeck@7ff0495cadf8 (RSA)
# 2048 SHA256:mQT8HYdan/qSNallrKhBOC6B2SJZ8NESAPR7t27rBkA rundeck@0a88c2cee02f (RSA)
# 2048 SHA256:tt14aHFVv7BKc4FABzPBrKEDYeTh9IftfrBolZ1PtrI rundeck@6ce6a554d02b (RSA)
# 3072 SHA256:096YEqlFSQn9ppaVGg5sfpt6R2Nn+eJi5k1Pb3QiIF4 rundeck@buildkitsandbox (RSA)
declare -a bad_keys
bad_keys=(SHA256:h7njOUArdygRFZN8R8JRysZ5Vje57TDoszOFqW+mEtY SHA256:HyLeewdJH/1WAAQKixUs613XsRXbFQd6nxU6ikdmcn0 SHA256:fm4RAHs48DTFFwBTgL95wdGMeZcp7fIF5WjN015/3CA SHA256:kVLnHhPWC2vgTvOcPx+DhRL0mkhpIJloKmKQuLAOBfA SHA256:9NEpWJV6CD3gVnxu+SGx8kt+YO/jLi1ri6EtdRDQnMU SHA256:mQT8HYdan/qSNallrKhBOC6B2SJZ8NESAPR7t27rBkA SHA256:tt14aHFVv7BKc4FABzPBrKEDYeTh9IftfrBolZ1PtrI SHA256:096YEqlFSQn9ppaVGg5sfpt6R2Nn+eJi5k1Pb3QiIF4)
OLDIFS="$IFS"
IFS="
"
root="/"
found=()
# If we can renice ourselves, great, no worries if not.
renice 10 $$ || true
for authorized_key_file in $(find "$root" -iname 'authorized_keys*' -ipath '*/.ssh/*' -type f -not -empty 2>/dev/null); do
echo "Looking at keyfile: $authorized_key_file"
echo
# list all the keys in the file, and process them a line at a time
# ssh-keygen -l -f "$authorized_key_file" \
for authorized_key_line in $(grep --extended-regexp '^ssh-' "$authorized_key_file"); do
authorized_key="$(ssh-keygen -l -f <(echo "$authorized_key_line"))"
# compare each authorized_key's allowed key against all the bad
# ones
for badkey in "${bad_keys[@]}"; do
if echo "$authorized_key" | grep --fixed-strings --quiet "$badkey"; then
echo "$authorized_key_file contains a bad key of:"
echo " $authorized_key_line"
echo
found+=("$authorized_key_file")
fi
done
done
done
IFS="$OLDIFS"
echo "Result: Found ${#found[@]} files with bad keys"
if [ ${#found[@]} -gt 0 ] ; then
echo "Files: ${found[@]}"
fi
]]></script>
<scriptargs />
</command>
<command>
<step-plugin type='log-data-step'>
<configuration>
<entry key='debugOnly' value='false' />
</configuration>
</step-plugin>
</command>
<command>
<description>CSV data results</description>
<node-step-plugin type='localexec'>
<configuration>
<entry key='command' value='echo ${node.name},${data.count},${stub.failed_reason},${data.found}' />
</configuration>
</node-step-plugin>
</command>
</sequence>
<uuid>6a94b275-056b-440e-8449-2a3da33bba92</uuid>
</job>
</joblist>