forked from leebaird/discover
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ssl.sh
executable file
·233 lines (184 loc) · 8.5 KB
/
ssl.sh
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#!/bin/bash
clear
f_banner
echo -e "${BLUE}Check for SSL certificate issues.${NC}"
echo
echo "List of IP:port."
echo
f_location
echo
echo $medium
echo
echo "Running sslyze."
sslyze --targets_in=$location --resum --reneg --heartbleed --certinfo --sslv2 --sslv3 --hide_rejected_ciphers --openssl_ccs > tmp
# Remove the first 20 lines and cleanup
sed '1,20d' tmp | egrep -v '(=>|error:|ERROR|is trusted|NOT SUPPORTED|OK - Supported|OpenSSLError|Server rejected|timeout|unexpected error)' |
# Find FOO, if the next line is blank, delete both lines
awk '/Compression/ { Compression = 1; next } Compression == 1 && /^$/ { Compression = 0; next } { Compression = 0 } { print }' |
awk '/Renegotiation/ { Renegotiation = 1; next } Renegotiation == 1 && /^$/ { Renegotiation = 0; next } { Renegotiation = 0 } { print }' |
awk '/Resumption/ { Resumption = 1; next } Resumption == 1 && /^$/ { Resumption = 0; next } { Resumption = 0 } { print }' |
awk '/SSLV2/ { SSLV2 = 1; next } SSLV2 == 1 && /^$/ { SSLV2 = 0; next } { SSLV2 = 0 } { print }' |
awk '/SSLV3/ { SSLV3 = 1; next } SSLV3 == 1 && /^$/ { SSLV3 = 0; next } { SSLV3 = 0 } { print }' |
awk '/Stapling/ { Stapling = 1; next } Stapling == 1 && /^$/ { Stapling = 0; next } { Stapling = 0 } { print }' |
awk '/Unhandled/ { Unhandled = 1; next } Unhandled == 1 && /^$/ { Unhandled = 0; next } { Unhandled = 0 } { print }' |
# Find a dash (-), if the next line is blank, delete it
awk -v n=-2 'NR==n+1 && !NF{next} /-/ {n=NR}1' |
# Remove double spacing
cat -s > $home/data/sslyze.txt
echo
echo "Running sslscan."
echo
START=$(date +%r\ %Z)
echo > tmp
echo $medium >> tmp
echo >> tmp
number=$(wc -l $location | cut -d ' ' -f1)
N=0
while read -r line; do
echo $line > ssl_$line
N=$((N+1))
echo -n "[$N/$number] $line"
sslscan --ipv4 --show-certificate --ssl2 --ssl3 --tlsall --no-colour $line > tmp_$line
echo "... completed."
echo >> ssl_$line
if [ -e tmp_$line ]; then
error=$(grep 'ERROR:' tmp_$line)
if [[ ! $error ]]; then
issuer=$(grep 'Issuer: ' tmp_$line)
if [[ $issuer ]]; then
grep 'Issuer:' tmp_$line | sed 's/ Issuer: / Issuer: /g' >> ssl_$line
else
echo "Issuer info not available." >> ssl_$line
echo >> ssl_$line
fi
subject=$(grep 'Subject:' tmp_$line)
if [[ $subject ]]; then
grep 'Subject:' tmp_$line >> ssl_$line
echo >> ssl_$line
else
echo "Certificate subject info not available." >> ssl_$line
echo >> ssl_$line
fi
dns=$(grep 'DNS:' tmp_$line)
if [[ $dns ]]; then
grep 'DNS:' tmp_$line | sed 's/ DNS:/ DNS:/g' >> ssl_$line
echo >> ssl_$line
fi
A=$(grep -i 'MD5WithRSAEncryption' tmp_$line)
if [[ $A ]]; then
echo "[*] MD5-based Signature in TLS/SSL Server X.509 Certificate" >> ssl_$line
grep -i 'MD5WithRSAEncryption' tmp_$line >> ssl_$line
echo >> ssl_$line
fi
B=$(grep 'NULL' tmp_$line)
if [[ $B ]]; then
echo "[*] NULL Ciphers" >> ssl_$line
grep 'NULL' tmp_$line >> ssl_$line
echo >> ssl_$line
fi
C=$(grep 'SSLv2' tmp_$line)
if [[ $C ]]; then
echo "[*] TLS/SSL Server Supports SSLv2" >> ssl_$line
grep 'SSLv2' tmp_$line > ssltmp2_$line
sed '/^ SSL/d' ssltmp2_$line >> ssl_$line
echo >> ssl_$line
fi
D=$(grep ' 40 bits' tmp_$line)
D2=$(grep ' 56 bits' tmp_$line)
if [[ $D || $D2 ]]; then
echo "[*] TLS/SSL Server Supports Weak Cipher Algorithms" >> ssl_$line
grep ' 40 bits' tmp_$line >> ssl_$line
grep ' 56 bits' tmp_$line >> ssl_$line
echo >> ssl_$line
fi
expmonth=$(grep 'Not valid after:' tmp_$line | awk '{print $4}')
if [ "$expmonth" == "Jan" ]; then monthnum="01"; fi
if [ "$expmonth" == "Feb" ]; then monthnum="02"; fi
if [ "$expmonth" == "Mar" ]; then monthnum="03"; fi
if [ "$expmonth" == "Apr" ]; then monthnum="04"; fi
if [ "$expmonth" == "May" ]; then monthnum="05"; fi
if [ "$expmonth" == "Jun" ]; then monthnum="06"; fi
if [ "$expmonth" == "Jul" ]; then monthnum="07"; fi
if [ "$expmonth" == "Aug" ]; then monthnum="08"; fi
if [ "$expmonth" == "Sep" ]; then monthnum="09"; fi
if [ "$expmonth" == "Oct" ]; then monthnum="10"; fi
if [ "$expmonth" == "Nov" ]; then monthnum="11"; fi
if [ "$expmonth" == "Dec" ]; then monthnum="12"; fi
expyear=$(grep 'Not valid after:' tmp_$line | awk '{print $7}')
expday=$(grep 'Not valid after:' tmp_$line | awk '{print $5}')
expdate=$(echo $expyear-$monthnum-$expday)
datenow=$(date +%F)
date2stamp(){
date --utc --date "$1" +%s
}
datenowstamp=$(date2stamp $datenow)
expdatestamp=$(date2stamp $expdate)
certissuedate=$(grep 'Not valid before:' tmp_$line)
fmt_certissuedate=$(echo $certissuedate | sed 's/Not valid before:/Certificate Issue Date:/')
certexpiredate=$(grep 'Not valid after:' tmp_$line)
fmt_certexpiredate=$(echo $certexpiredate | sed 's/Not valid after:/Certificate Expiry Date:/')
echo " $fmt_certissuedate" >> ssl_$line
echo " $fmt_certexpiredate" >> ssl_$line
echo >> ssl_$line
if (($expdatestamp < $datenowstamp)); then
echo "[*] X.509 Server Certificate is Invalid/Expired" >> ssl_$line
echo " Cert Expire Date: $expdate" >> ssl_$line
echo >> ssl_$line
fi
E=$(grep 'Authority Information Access' tmp_$line)
if [[ ! $E ]]; then
echo "[*] Self-signed TLS/SSL Certificate" >> ssl_$line
echo >> ssl_$line
fi
echo $medium >> ssl_$line
echo >> ssl_$line
cat ssl_$line >> tmp
else
echo -e "${RED}Could not open a connection.${NC}"
echo "[*] Could not open a connection." >> ssl_$line
echo >> ssl_$line
echo $medium >> ssl_$line
echo >> ssl_$line
cat ssl_$line >> tmp
fi
else
echo -e "${RED}No response.${NC}"
echo "[*] No response." >> ssl_$line
echo >> ssl_$line
echo $medium >> ssl_$line
echo >> ssl_$line
cat ssl_$line >> tmp
fi
done < "$location"
END=$(date +%r\ %Z)
echo "sslscan Report" > tmp2
date +%A" - "%B" "%d", "%Y >> tmp2
echo >> tmp2
echo "Start time $START" >> tmp2
echo "Finish time $END" >> tmp2
echo "Scanner IP $ip" >> tmp2
mv tmp2 $home/data/sslscan.txt
grep -v 'Issuer info not available.' tmp | grep -v 'Certificate subject info not available.' >> $home/data/sslscan.txt
echo
echo "Running nmap."
echo
cat $location | cut -d ':' -f1 > tmp
nmap -Pn -n -T4 --open -p443 --script-timeout 20s -sV --min-hostgroup 100 --script=rsa-vuln-roca,ssl*,tls-alpn,tls-ticketbleed -iL tmp > tmp2
egrep -v '( - A|before|Ciphersuite|cipher preference|deprecated)' tmp2 |
# Find FOO, if the next line is blank, delete both lines
awk '/latency/ { latency = 1; next } latency == 1 && /^$/ { latency = 0; next } { latency = 0 } { print }' |
# Find FOO, if the next line is blank, delete the line containing FOO
awk -v n=-2 'NR==n+1 && NF{print hold} /sslv2-drown/ {n=NR;hold=$0;next}1' |
awk -v n=-2 'NR==n+1 && NF{print hold} /least strength/ {n=NR;hold=$0;next}1' |
awk -v n=-2 'NR==n+1 {if($0 ~ /NULL/) { next; } else { print hold } } /compressors/ {n=NR;hold=$0;next}1' |
sed 's/Nmap scan report for //g' > $home/data/nmap-ssl.txt
rm tmp* ssl_* 2>/dev/null
echo
echo $medium
echo
echo "***Scan complete.***"
echo
echo
echo -e "The new reports are located at ${YELLOW}$home/data/sslscan.txt, sslyze.txt, ${NC}and ${YELLOW}nmap-ssl.txt ${NC}"
echo
echo